Options
All
  • Public
  • Public/Protected
  • All
Menu

Class 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.

class

Asset

Hierarchy

  • Asset

Implements

Index

Constructors

constructor

  • new Asset(amt?: u64, sy?: u64): Asset
  • Parameters

    • Default value amt: u64 = 0
    • Default value sy: u64 = 0

    Returns Asset

Properties

Private _amount

_amount: u64

Private _symbol

_symbol: u64

Accessors

amount

  • get amount(): u64
  • set amount(a: u64): void

Methods

Private _add

Private _sub

add

  • add two Asset objects together, like "+"

    Parameters

    • rhs: Asset

      another Asset object with same symbol.

    Returns Asset

clone

deserialize

divide

  • divide(rhs: u64): Asset
  • divide the asset with a factor.

    Parameters

    • rhs: u64

      divide factor.

    Returns Asset

getAmount

  • getAmount(): u64
  • Get the amount of Asset.

    Returns u64

    an uint64 value.

getSymbol

  • getSymbol(): u64
  • 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.

    Returns u64

isAmountWithinRange

  • isAmountWithinRange(): boolean

isSymbolValid

  • isSymbolValid(): boolean
  • 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".

    Returns boolean

isValid

  • isValid(): boolean
  • To check if an Asset is valid or not.

    Returns boolean

multi

  • multiple the asset with a factor.

    Parameters

    • rhs: u64

      multiple factor.

    Returns Asset

primaryKey

  • primaryKey(): u64

prints

  • prints(tag: string): void

serialize

setAmount

  • setAmount(newAmount: u64): void
  • Set the amount of Asset.

    Parameters

    • newAmount: u64

      new amount value.

    Returns void

setSymbol

  • setSymbol(newSymbol: u64): void
  • Set new encoded symbol. Generate new symbol by calling function StringToSymbol

    Parameters

    • newSymbol: u64

      new symbol

    Returns void

sub

  • sub Asset's amount, like "-"

    Parameters

    • rhs: Asset

      another Asset object with same symbol to sub.

    Returns Asset

symbolName

  • symbolName(): u64
  • Get symbol name without precision info.

    Returns u64

symbolNameLength

  • symbolNameLength(): u32

symbolPrecision

  • symbolPrecision(): u64

Static Private _eq

Static Private _gt

Static Private _gte

Static Private _lt

Static Private _lte

Static balanceOf

  • balanceOf(account: account_name): Asset
  • query the balance of specific account.

    Parameters

    • account: account_name

      account name for querying balance from.

    Returns Asset

Static Private checkOperaotrCondition

  • checkOperaotrCondition(rhs: Asset, lhs: Asset, op: string): void

Static transfer

  • transfer(from: account_name, to: account_name, value: Asset, memo: string): void
  • 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

    • from: account_name

      transfer Asset from this account.

    • to: account_name

      transfer Asset to this account.

    • value: Asset

      assets will be transfered.

    • memo: string

      a memo tip for this transaction.

    Returns void

Generated using TypeDoc