UNPKG

eosplayer

Version:

eosplayer is the glue layer of eosjs, which is packaged based on eosjs and provides better usability for the application layer. It can be used on browsers already installed scatter or in Dapp wallets.

248 lines (247 loc) 10.4 kB
import { ISignPlugin } from '../plugins'; import { IAccountInfo, IAuthorization, IEosClient, IIdentity } from '../types/eos'; import { CQueue } from '../utils/cQueue'; /** * chain helper, supported chain operations * @author kinghand@foxmail.com */ export default class ChainHelper { readonly _eos: IEosClient; constructor(_eos: IEosClient); readonly storyBoard: CQueue<any>; /** * get info of the chain connected * @return {Promise<*>} */ getInfo(): Promise<any>; /** * get specific block of the chain * @param blockNumOrId * @return {Promise<*>} */ getBlock(blockNumOrId: string | number): Promise<any>; /** * get contract * @param code * @return {Promise<void>} */ getContract(code: string): Promise<any>; /** * get the abi of contract * @param code * @return {Promise<*>} */ getAbi(code: string): Promise<any>; /** * get the definition of a table in specific contract abi * @param code * @param tableName * @return {Promise<*|undefined>} */ getTableAbi(code: string, tableName: string): Promise<any>; /** * abiJsonToBin * @param code * @param action * @param args * @return {Promise<string>} */ abiJsonToBin(code: string, action: string, args: any[]): Promise<any>; /** * get account info of any user * @param {string|number} account_name - string name or id * @return {Promise<{AccountInfo}>} */ getAccountInfo(account_name: string): Promise<IAccountInfo>; /** * get first public key of an account * @param account_name - account_name * @param authority - default is 'active' * @return {Promise<*>} * @constructor */ getPubKey(account_name: string, authority?: string): Promise<any>; /** * get public keys of an account * @param account_name * @param authority - default is 'active' * @return {Promise<*>} * @constructor */ getPubKeys(account_name: string, authority?: string): Promise<any>; /** * recover public key from signature * @param signature - signed data * @param message * @return {string} */ recoverSign(signature: string, message: string): string; /** * validate if signed data is signed by a account * @param signature - signed data * @param message * @param account_name * @param authority - default is 'active' * @param {Array.<ISignPlugin>} signPlugins - plugins for validate sign * @example * validateSign(SIG, MSG, ACC, 'active', { ['pretonarts11@eosio.code'] : async (account, recoverKey) => validate rpc ... } * @return {string|undefined} - recover public key, and it's failed when 'undefined' return. */ validateSign(signature: string, message: string, account_name: string, authority?: string, ...signPlugins: ISignPlugin[]): Promise<string | undefined>; /** * get a account's action count * @param {string|number} account_name - string name or id * @return {Promise<number>} */ getActionCount(account_name: string): Promise<any>; /** * get a account's max seq * @param {string|number} account_name - string name or id * @return {Promise<number>} - return -1 if there is no action */ getActionMaxSeq(account_name: string): Promise<any>; /** * get recent actions * @param account_name * @return {Promise<Array>} */ getRecentActions(account_name: string): Promise<any>; /** * get actions of an account * @desc to avoid searching in huge amount actions, the application layer should check the getActionCount before calling thi method * @param {string|number} account_name - string name or id * @param {number} startPos - start from 0 * @param {number} offset - when offset is 0, one object returned, offset ==(should be) count - 1 * @param {number} fetchTimeout - fetch time out (ms) * @return {Promise<Array>} - [startPos, ..., startPos + offset] */ getActions(account_name: string, startPos?: number, offset?: number, fetchTimeout?: number): Promise<any[]>; /** * Get all the actions in bulk * @param account_name * @param cbReceive - using this callback to receive list of actions * @param startPos * @param count * @param concurrent * @return {Promise<void>} */ getAllActionsBatch(account_name: string, cbReceive: (acts: any[]) => any, startPos?: number, count?: number, concurrent?: number): Promise<boolean>; /** * get balance of specific account * @param account_name - user's account name * @param code - Account of the currency contract. The default code is "eosio.token", which is the currency code of eos * @param symbolName - the token's symbol name * @return {Promise<string|undefined>} asset format '1.0000 EOS' */ getBalance(account_name: string, code?: string, symbolName?: string): Promise<any>; /** * get balance of specific account * @param account_name - user's account name * @param code - Account of the currency contract. The default code is "eosio.token", which is the currency code of eos * @return {Promise<Array>} - list of asset, asset format is like '1.0000 EOS' */ getBalances(account_name: string, code?: string): Promise<any>; /** * transfer * @param {Object} account - {name, authority} * @param {string} target - eos account, can be user or contract * @param {string} quantity - eos asset format, e.p. "1.0000 EOS" * @param {string} memo - memo * @param {string} tokenAccount - name of token account - default is 'eosio.token' * @param {Function} cbError - memo * @return {Promise<Object>} transactionData */ transfer(account: IIdentity, target: string, quantity: string, memo: string, cbError: (err: any) => any, tokenAccount?: string): Promise<any>; /** * check a transaction info, retry once per sec until success * @param {string} txID * @param {number} maxRound * @param {number} timeSpanMS * @return {Promise<Object>} transaction */ waitTx(txID: string, maxRound?: number, timeSpanMS?: number): Promise<any>; /** * send action to a contract * @param {string} code - account of contract * @param {string} func - function name * @param {*} jsonData - data * @param {Array<IAuthorization>} authorization - should be an object who has keys {actor, permission} * @return {Promise<*>} - transaction */ call(code: string, func: string, jsonData: any, ...authorization: IAuthorization[]): Promise<any>; /** * get all items in a table * @desc this method can be very fast (infinitely close to once rpc time) when provide hint table * @param {string} code - the contract * @param {string} tableName - name of the table * @param {string} scope * @param {number} lowerNum - lower position, can be number or stringNumber, cannot be account_name * @param {number} upperNum - lower position, can be number or stringNumber, cannot be account_name * @param {Array<number>} hint - hint table to speed up search * @example getTable("contract", "table", "scope", 0, -1, "4611686018427387903", "6917529027641081856", "9223372036854775808", "13835058055282163712") * @return {Promise<Array>} */ getTableAll(code: string, tableName: string, scope: string, lowerNum: string | number, upperNum: string | number, ...hint: Array<string | number>): Promise<any[]>; /** * check a table * @desc the tag 'more' are not handled. * @param {string} code - the contract * @param {string} tableName - name of the table * @param {string} scope * @param {number} limit * @param {number | string} lower_bound * @param {number | string} upper_bound * @param {number} index_position * @return {Promise<Array>} */ checkTable(code: string, tableName: string, scope: string, limit?: number, lower_bound?: number | string, upper_bound?: number | string, index_position?: number): Promise<any[]>; /** * check a table * @desc the tag 'more' are handled. it means that the result would not be truncated. * @param {string} code - the contract * @param {string} tableName - name of the table * @param {string} scope * @param {string} primaryKey - the key for indexing * @param {number} limit * @param {number | string} lower_bound * @param {number | string} upper_bound * @param {number} index_position * @return {Promise<Array>} */ checkTableMore(code: string, tableName: string, scope: string, primaryKey: string, limit?: number, lower_bound?: number | string, upper_bound?: number | string, index_position?: number): Promise<any[]>; /** * check range in table * @desc the tag 'more' are handled. it means that the result would not be truncated. * @param {string} code - the contract * @param {string} tableName - name of the table * @param {string} scope * @param {number | string} from - start position or username * @param {number} length * @param {number} index_position * @return {Promise<Array>} */ checkTableRange(code: string, tableName: string, scope: string, from: number | string, length?: number, index_position?: number): Promise<any[]>; /** * check a item in a table * @param {string} code - the contract * @param {string} tableName * @param {string} scope * @param {number} key * @return {Promise<*>} */ checkTableItem(code: string, tableName: string, scope: string, key: string | number): Promise<any>; /** * update auth * @param account_name * @param permission * @param parent * @param threshold * @param keys * @param accounts * @param waits * @returns {Promise<*>} */ updateAuth(account_name: string, permission: string, parent: string, threshold: number, keys: any, accounts: any, waits?: number): Promise<any>; static getTableByScope(host: string, code: string, table: string, lower_bound: string | number, upper_bound: string | number, limit?: number): Promise<any[]>; static help(): string; }