Asset

Asset

new Asset()

Methods

(static) balanceOf(account)

query the balance of specific account.

Parameters:
Name Type Description
account

account name for querying balance from.

(static) StringToSymbol(precision, str)

Encode a string to uint64 value, for example, let symbol = StringToSymbol(4, "ABC"); // symbol = 0x43424104 the precision number 4 means there are 4 digitals after ".", Asset "100.0000 ABC" will match this symbol.

Example
import { StringToSymbol } from "ultrain-ts-lib/src/asset";
Parameters:
Name Type Description
precision

symbol precision

str

symbol as string

Returns:

uint64 value.

(static) SymbolNameLength(symbolName)

retrieve symbol name length.

Parameters:
Name Type Description
symbolName

encoded symbol name.

Returns:

uint32

(static) transfer(from, to, value, memo)

Transfer some Assets from an account to another. It is an async method, if the operation failed, then an exception will be thrown and the transaction failed.

Parameters:
Name Type Description
from

transfer Asset from this account.

to

transfer Asset to this account.

value

assets will be transfered.

memo

a memo tip for this transaction.

add(rhs)

add two Asset objects together, like "+"

Parameters:
Name Type Description
rhs

another Asset object with same symbol.

clone()

Clone an Asset object.

divide(rhs)

divide the asset with a factor.

Parameters:
Name Type Description
rhs

divide factor.

formatAmount(amount, precision)

Format the amount, example formatAmount(10000, 4) == "1.0000"

Parameters:
Name Type Description
amount

the amount

precision

the precision

getAmount()

Get the amount of Asset.

Returns:

an uint64 value.

getSymbol()

Get the encoded symbol. for example, if the symbol string is "ABC", then the symbol is 0x434241xx. Notice the last "xx" stands for the precisions

isAmountWithinRange(amount)

to check if the amount of Asset is valid or not.

Parameters:
Name Type Description
amount

new amount of Asset, which muse be positive and less than 2^62 - 1

isSymbolValid()

To check if a symbol is valid or not. A valid symbol must fullfill two conditions:

  1. length of symbol string must be less or equal than 7. for example, "ABCDEFG" is valid, but "ABCEDFGH" is invalid.
  2. the symbol can only contains upper case characters in "A-Z".

isValid()

To check if an Asset is valid or not.

multi(rhs)

multiple the asset with a factor.

Parameters:
Name Type Description
rhs

multiple factor.

setAmount(newAmount)

Set the amount of Asset.

Parameters:
Name Type Description
newAmount

new amount value.

setSymbol(newSymbol)

Set new encoded symbol. Generate new symbol by calling function StringToSymbol

Parameters:
Name Type Description
newSymbol

new symbol

sub(rhs)

sub Asset's amount, like "-"

Parameters:
Name Type Description
rhs

another Asset object with same symbol to sub.

symbolName()

Get symbol name without precision info.

symbolNameLength()

Get the length of symbol name.

Returns:

uint32

symbolPrecision()

Get the precision of Asset.

toString() → {string}

Returns:
Type
string

Asset

new Asset()

The class Asset manages the digital assets which stored on the chain. A valid asset has two parts: amount and symbol. Different assets have different symbols. for example, "1000 UGS" and "1000 SYS" are both valid assets, but they are different. You can do +,-,*, / and logic compare such as ==,!=, <=, >= on assets with same symbol.

Example
import { Asset } from "ultrain-ts-lib/src/asset";

Methods

(static) balanceOf(account)

query the balance of specific account.

Parameters:
Name Type Description
account

account name for querying balance from.

(static) StringToSymbol(precision, str)

Encode a string to uint64 value, for example, let symbol = StringToSymbol(4, "ABC"); // symbol = 0x43424104 the precision number 4 means there are 4 digitals after ".", Asset "100.0000 ABC" will match this symbol.

Example
import { StringToSymbol } from "ultrain-ts-lib/src/asset";
Parameters:
Name Type Description
precision

symbol precision

str

symbol as string

Returns:

uint64 value.

(static) SymbolNameLength(symbolName)

retrieve symbol name length.

Parameters:
Name Type Description
symbolName

encoded symbol name.

Returns:

uint32

(static) transfer(from, to, value, memo)

Transfer some Assets from an account to another. It is an async method, if the operation failed, then an exception will be thrown and the transaction failed.

Parameters:
Name Type Description
from

transfer Asset from this account.

to

transfer Asset to this account.

value

assets will be transfered.

memo

a memo tip for this transaction.

add(rhs)

add two Asset objects together, like "+"

Parameters:
Name Type Description
rhs

another Asset object with same symbol.

clone()

Clone an Asset object.

divide(rhs)

divide the asset with a factor.

Parameters:
Name Type Description
rhs

divide factor.

formatAmount(amount, precision)

Format the amount, example formatAmount(10000, 4) == "1.0000"

Parameters:
Name Type Description
amount

the amount

precision

the precision

getAmount()

Get the amount of Asset.

Returns:

an uint64 value.

getSymbol()

Get the encoded symbol. for example, if the symbol string is "ABC", then the symbol is 0x434241xx. Notice the last "xx" stands for the precisions

isAmountWithinRange(amount)

to check if the amount of Asset is valid or not.

Parameters:
Name Type Description
amount

new amount of Asset, which muse be positive and less than 2^62 - 1

isSymbolValid()

To check if a symbol is valid or not. A valid symbol must fullfill two conditions:

  1. length of symbol string must be less or equal than 7. for example, "ABCDEFG" is valid, but "ABCEDFGH" is invalid.
  2. the symbol can only contains upper case characters in "A-Z".

isValid()

To check if an Asset is valid or not.

multi(rhs)

multiple the asset with a factor.

Parameters:
Name Type Description
rhs

multiple factor.

setAmount(newAmount)

Set the amount of Asset.

Parameters:
Name Type Description
newAmount

new amount value.

setSymbol(newSymbol)

Set new encoded symbol. Generate new symbol by calling function StringToSymbol

Parameters:
Name Type Description
newSymbol

new symbol

sub(rhs)

sub Asset's amount, like "-"

Parameters:
Name Type Description
rhs

another Asset object with same symbol to sub.

symbolName()

Get symbol name without precision info.

symbolNameLength()

Get the length of symbol name.

Returns:

uint32

symbolPrecision()

Get the precision of Asset.

toString() → {string}

Returns:
Type
string