ContractSdk
Options
All
  • Public
  • Public/Protected
  • All
Menu

TsSDK

This project contains typescript SDK source code.

Dependency

This project use AssemblyScript/assemblyscript as compile tool, before you compile your cotract to Ultrain supoort binary fomat, please install assemblyscritp at first.

Index

External modules

"lib/ISerializable"

"lib/ISerializable":

ISerializable

ISerializable:

deserialize

primaryKey

  • primaryKey(): u64

serialize

"src/action"

"src/action":

Action

Action:

class Action is applied to access an action's context information. This class is static.

class

Action

receiver

receiver:

to get the receiver's account name of current action. such as command 'clultrain push action kobe '["params"]' -p james's-key', 'kobe' is the receiver's account name.

sender

sender:

to get the sender of current action, specially, 'sender' means whose permission key is used by '-p', such as command 'clultrain push action kobe '["params"]' -p james's-key', 'james' is the sender's account name.

hasAuth

  • hasAuth(account: account_name): boolean
  • to check if an account name has been authored.

    Parameters

    • account: account_name

      the account name which will be checked.

    Returns boolean

    boolean value, return true means the account is authored, otherwised false.

isAccount

  • isAccount(account: account_name): boolean
  • to check if an account name is valid or not.

    Parameters

    • account: account_name

      account name to be checked.

    Returns boolean

    boolean

requireAuth

  • requireAuth(account: account_name): void
  • check the authority of a speicfic account name.

    Parameters

    • account: account_name

      account_name whose authority is required.

    Returns void

ActionImpl

ActionImpl:

class ActionImpl is an internal class, for method {@link dispatchInline}.

class

ActionImpl

constructor

account

account: account_name

authorization

authorization: PermissionLevel[]

data

data: u8[]

name

deserialize

primaryKey

  • primaryKey(): u64

serialize

TransferParams

TransferParams:

class TransferParams is applied to transfer Tokens from an account to another.

class

TransferParams

constructor

  • Parameters

    • Default value from: u64 = 0
    • Default value to: u64 = 0
    • Default value quantity: Asset = null
    • Default value memo: string = ""

    Returns TransferParams

from

from: u64

memo

memo: string

quantity

quantity: Asset

to

to: u64

deserialize

primaryKey

  • primaryKey(): u64

serialize

dispatchInline

requirePermissionLevel

  • to check if permission is authored or not.

    function

    requirePermissionLevel

    Parameters

    Returns void

"src/asset"

"src/asset":

Asset

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

constructor

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

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

    Returns Asset

_amount

_amount: u64

_symbol

_symbol: u64

amount

amount:

_add

_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

_eq

_gt

_gte

_lt

_lte

balanceOf

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

    Parameters

    • account: account_name

      account name for querying balance from.

    Returns Asset

checkOperaotrCondition

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

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

CHAR_A

CHAR_A: u8

ASCII code of character A.

CHAR_Z

CHAR_Z: u8

ASCII code of character Z.

MAX_AMOUNT

MAX_AMOUNT: u64

max amount of Asset, which is 2^62 - 1.

StringToSymbol

  • StringToSymbol(precision: u8, str: string): u64
  • 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.

    function

    StringToSymbol

    Parameters

    • precision: u8

      symbol precision

    • str: string

      symbol as string

    Returns u64

    uint64 value.

SymbolNameLength

  • SymbolNameLength(symbolName: u64): u32
  • retrieve symbol name length.

    function

    SymbolNameLength

    Parameters

    • symbolName: u64

      encoded symbol name.

    Returns u32

    uint32

"src/balance"

"src/balance":

Account

Account:

class Account for Token system.

class

Account

constructor

balance

balance: Asset

deserialize

primaryKey

  • primaryKey(): u64

serialize

CurrencyStats

CurrencyStats:

class CurrencyStats for Token system.

class

CurrencyStats

constructor

issuer

issuer: account_name

max_supply

max_supply: Asset

supply

supply: Asset

deserialize

primaryKey

  • primaryKey(): u64

serialize

SYS

SYS: u64

Ultrain block system Token, it's precision is 4, and symbol is "UGS".

SYS_NAME

SYS_NAME: u64

Ultrain block system Token name "UGS".

queryBalance

  • queryBalance(owner: account_name): Asset
  • to query the balance of an account from Ultrain Token system.

    function

    queryBalance

    Parameters

    • owner: account_name

      account name to be queried.

    Returns Asset

    Asset

send

  • send(from: account_name, to: account_name, quantity: Asset, memo: string): void
  • to send Token of UGS from an account to another.

    function

    send

    Parameters

    • from: account_name

      from account

    • to: account_name

      to account

    • quantity: Asset

      Asset to send.

    • memo: string

      a string message

    Returns void

"src/datastream"

"src/datastream":

DSHelper

DSHelper:

internal class, not for external users.

getDataStreamWithLength

serializeComplex

serializeComplexVector

DataStream

DataStream:

internal class, not for external users.

class

DataStream

constructor

  • new DataStream(buffer: u32, len: u32): DataStream

buffer

buffer: u32

len

len: u32

pos

pos: u32

isMesureMode

  • isMesureMode(): boolean

pointer

  • pointer(): usize

read

  • read<T>(): T

readComplexVector

  • readComplexVector<T>(): T[]

readDouble

  • readDouble(): f64

readString

  • readString(): string

readStringVector

  • readStringVector(): string[]

readVarint32

  • readVarint32(): u32

readVector

  • readVector<T>(): T[]

size

  • size(): u32

toArray

  • toArray<T>(): T[]

write

  • write<T>(value: T): void

writeComplexVector

  • writeComplexVector<T>(arr: T[]): void
  • write array of complex class which implements ISerialzable interface.

    Type parameters

    Parameters

    • arr: T[]

    Returns void

writeDouble

  • writeDouble(d: f64): void

writeString

  • writeString(str: string): void

writeStringVector

  • writeStringVector(arr: string[]): void

writeVarint32

  • writeVarint32(value: u32): void

writeVector

  • writeVector<T>(arr: T[]): void

fromArray

  • make a DataStream from an existing array.

    Type parameters

    • T

    Parameters

    • from: T[]

      an array of basic class, like u8/i8, u16/i16, u32/i32, u64/i64

    Returns DataStream

measure

  • measure<T>(obj: T): u32
  • to measure the length of serialized buffer.

    Type parameters

    Parameters

    • obj: T

      an instance of class which implements ISerializable.

    Returns u32

measureComplexVector

  • measureComplexVector<T>(arr: T[]): u32

HEADER_SIZE

HEADER_SIZE: number

internal memory HEADER SIZE. NEVER used by users.

"src/dbmanager"

"src/dbmanager":

DBManager

DBManager:

class DBManager is used to manager reading or writing to system db. the type T must be implements interface ISerializable, reference Account or CurrencyStats

class

DBManager

constructor

  • new DBManager(tblname: u64, owner: u64, scope: u64): DBManager
  • create a table to persistent data.

    Parameters

    • tblname: u64

      the table name

    • owner: u64

      the owner of the table, who can read and write the table, anyone else is read-only. meanwhile, the owner should pay for storing data if need.

    • scope: u64

      the scope of rows, if you write a row with scope A, then you must read the row with scope A too, otherwise you get nothing.

    Returns DBManager

_items_vector

_items_vector: DataItem<T>[]

_owner

_owner: u64

_scope

_scope: u64

_tblname

_tblname: u64

emplace

  • emplace(payer: u64, obj: T): void
  • insert a new record to database.

    Parameters

    • payer: u64

      an account_name, who pays for the storing action.

    • obj: T

      the data to be sotred.

    Returns void

erase

  • erase(obj: T): void
  • remove a record from database.

    Parameters

    • obj: T

      data to be removed.

    Returns void

get

  • get(primary: u64, out: T): boolean
  • read a record form database.

    Parameters

    • primary: u64

      the primary key of data

    • out: T

      the data struct if success.

    Returns boolean

    true if the primary key exists, otherwise false.

getCode

  • getCode(): u64

getScope

  • getScope(): u64

loadObjectByPrimaryIterator

  • loadObjectByPrimaryIterator(itr: i32, out: T): void

modify

  • modify(payer: u64, newobj: T): void
  • update a row.

    Parameters

    • payer: u64

      account name who pays for the updating action.

    • newobj: T

      the updated data to be stored.

    Returns void

DataItem

DataItem:

describe a row of table.

class

DataItem

constructor

_dbmgr

_dbmgr: DBManager<T>

_iters

_iters: i32[]

_primary_itr

_primary_itr: i32

_value

_value: T

"src/log"

"src/log":

env

env:

ts_log_done

  • ts_log_done(): void

ts_log_print_i

  • ts_log_print_i(i: i64, fmt: u32): void
  • Parameters

    • i: i64
    • fmt: u32

    Returns void

ts_log_print_s

  • ts_log_print_s(ch: i32): void

Logger

Logger:

class Logger providers api to print logs to console immediately after you call function 'flush'.

flush

  • flush(): void
  • flush the logs to console, the message will output to the console only after calling this method, or the message concat together.

    Returns void

i

  • i(intger: i64, fmt?: u32): Logger
  • print an integer to console.

    Parameters

    • intger: i64

      integer to print.

    • Default value fmt: u32 = 10

      to print as dec or hex. for example, 'Log.i(10, 10).flush() ' will print '10', but 'Log.i(10, 16).flush()' will print 'A'.

    Returns Logger

s

  • print a string message to console.

    Parameters

    • msg: string

      message to print.

    Returns Logger

Log

Log: Logger

A global variable of Logger. There is only one Log object at the same time.

"src/map"

"src/map":

Map

Map:
author

fanliangqin@ultrain.io

datetime

16:53:10, 07/11/2018 All rights reserved by ultrain.io @2018

_keys

_keys: K[]

_values

_values: V[]

_valueAt

  • _valueAt(key: K): V

clear

  • clear(): void

contains

  • contains(key: K): boolean

find

  • find(key: K): i32

get

  • get(key: K): V

keys

  • keys(): K[]

remove

  • remove(key: K): boolean

set

  • set(key: K, val: V): void

size

  • size(): i32

values

  • values(): V[]

"src/name_ex"

"src/name_ex":

NameEx

NameEx:

class NameEx uses to store 21 characters name, method NEX converts a string which contains "._0123456789abcdefghijklmnopqrstuvwxyzABCEDEFGHIJKLMNOPQRSTUVWXYZ" to NameEx. for example, action_name is an intance of NameEx.

class

NameEx

constructor

  • new NameEx(h: u64, l: u64): NameEx

valueH

valueH: u64

valueL

valueL: u64

deserialize

primaryKey

  • primaryKey(): u64

serialize

toString

  • toString(): string

_eq

_neq

action_name

action_name: NameEx

NEX

  • convert a string to NameEx. There are some limits for param str:

    1. length of str must be less than 21.
    2. only contains "._0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".
    3. can not end with "."
    function

    NEX

    Parameters

    • str: string

      a string to convert to NameEx

    Returns NameEx

    an instance of NameEx

RNEX

  • RNEX(h: u64, l: u64): string
  • convert NameEx.valueH, NameEx.valueL to a string.

    function

    RNEX

    Parameters

    • h: u64

      high 64 bits of NameEx.

    • l: u64

      low 64 bits of NameEx.

    Returns string

char_to_symbol_ex

  • char_to_symbol_ex(c: u8): u64

"src/permission-level"

"src/permission-level":

PermissionLevel

PermissionLevel:

Permission Level stands for '-p' paramters. for example, PermissionLevel(N("tom"), N("active")) equals '-p tom@active'

class

PermissionLevel

constructor

actor

actor: u64

permission

permission: u64

deserialize

equal

primaryKey

  • primaryKey(): u64

serialize

"src/return"

"src/return":

env

env:

set_result_int

  • set_result_int(val: u64): void

set_result_str

  • set_result_str(cstr: usize): void

Return

  • Return<T>(val: T): void
  • set value as return value. This value will be printed to console or return within response if you call API by POST method via https. Till now, type T can only be string or integer. NOTE: the return value doesn't mean the transaction is commited by blockchain, but means if the transaction is executed, the result will be it.

    Type parameters

    • T

    Parameters

    • val: T

      value will set as return value.

    Returns void

ReturnArray

  • ReturnArray<T>(val: T[]): void
  • return an array to caller. It behaves like Return.

    Type parameters

    • T

    Parameters

    • val: T[]

      an array of returns value.

    Returns void

"src/utils"

"src/utils":

ASCIICHAR

ASCIICHAR: string[]

printable characters.

N

  • N(str: string): u64
  • convert a string to uint64 encoded by Base32. so the string must follow below principles:

    1. no more than 13 characters.
    2. only contains ".12345abcdefghijklmnopqrstuvwxyz"
    3. not end with "."

    Parameters

    • str: string

      string to convert

    Returns u64

NameSuffix

  • NameSuffix(n: u64): u64

RN

  • RN(name: u64): string
  • a revert operation of method N

    Parameters

    • name: u64

      uint64 value

    Returns string

char_to_symbol

  • char_to_symbol(c: u8): u64

intToString

  • intToString(_int: u64): string
  • convert an uint64 to string.

    Parameters

    • _int: u64

      uint64 to convert

    Returns string

    string

printstr

  • printstr(str: string): void
  • print a string to console after wasm vm quit.

    Parameters

    • str: string

      string to print.

    Returns void

string2cstr

  • string2cstr(str: string): u32
  • convert string to usize. here, usize likes "const char*" in c/c++.

    Parameters

    • str: string

      a utf-16 string of typescript.

    Returns u32

    usize

toUTF8Array

  • toUTF8Array(str: string): u8[]
  • convert an utf-16 to utf-8 string array.

    Parameters

    • str: string

      a typescript string

    Returns u8[]

    an array of uint8

ultrain_assert

  • ultrain_assert(condition: boolean, msg: string): void
  • assert an condition. if condition is false, vm throws an exception and quit executing.

    Parameters

    • condition: boolean

      condition to check.

    • msg: string

      help message

    Returns void

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc