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; /** * get info of the chain connected * @return {Promise<*>} */ getInfo(): Promise; /** * get specific block of the chain * @param blockNumOrId * @return {Promise<*>} */ getBlock(blockNumOrId: string | number): Promise; /** * get contract * @param code * @return {Promise} */ getContract(code: string): Promise; /** * get the abi of contract * @param code * @return {Promise<*>} */ getAbi(code: string): Promise; /** * get the definition of a table in specific contract abi * @param code * @param tableName * @return {Promise<*|undefined>} */ getTableAbi(code: string, tableName: string): Promise; /** * abiJsonToBin * @param code * @param action * @param args * @return {Promise} */ abiJsonToBin(code: string, action: string, args: any[]): Promise; /** * get account info of any user * @param {string|number} account_name - string name or id * @return {Promise<{AccountInfo}>} */ getAccountInfo(account_name: string): Promise; /** * 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; /** * get public keys of an account * @param account_name * @param authority - default is 'active' * @return {Promise<*>} * @constructor */ getPubKeys(account_name: string, authority?: string): Promise; /** * 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.} 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; /** * get a account's action count * @param {string|number} account_name - string name or id * @return {Promise} */ getActionCount(account_name: string): Promise; /** * get a account's max seq * @param {string|number} account_name - string name or id * @return {Promise} - return -1 if there is no action */ getActionMaxSeq(account_name: string): Promise; /** * get recent actions * @param account_name * @return {Promise} */ getRecentActions(account_name: string): Promise; /** * 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} - [startPos, ..., startPos + offset] */ getActions(account_name: string, startPos?: number, offset?: number, fetchTimeout?: number): Promise; /** * 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} */ getAllActionsBatch(account_name: string, cbReceive: (acts: any[]) => any, startPos?: number, count?: number, concurrent?: number): Promise; /** * 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} asset format '1.0000 EOS' */ getBalance(account_name: string, code?: string, symbolName?: string): Promise; /** * 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} - list of asset, asset format is like '1.0000 EOS' */ getBalances(account_name: string, code?: string): Promise; /** * 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} transactionData */ transfer(account: IIdentity, target: string, quantity: string, memo: string, cbError: (err: any) => any, tokenAccount?: string): Promise; /** * check a transaction info, retry once per sec until success * @param {string} txID * @param {number} maxRound * @param {number} timeSpanMS * @return {Promise} transaction */ waitTx(txID: string, maxRound?: number, timeSpanMS?: number): Promise; /** * send action to a contract * @param {string} code - account of contract * @param {string} func - function name * @param {*} jsonData - data * @param {Array} authorization - should be an object who has keys {actor, permission} * @return {Promise<*>} - transaction */ call(code: string, func: string, jsonData: any, ...authorization: IAuthorization[]): Promise; /** * 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} hint - hint table to speed up search * @example getTable("contract", "table", "scope", 0, -1, "4611686018427387903", "6917529027641081856", "9223372036854775808", "13835058055282163712") * @return {Promise} */ getTableAll(code: string, tableName: string, scope: string, lowerNum: string | number, upperNum: string | number, ...hint: Array): Promise; /** * 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} */ checkTable(code: string, tableName: string, scope: string, limit?: number, lower_bound?: number | string, upper_bound?: number | string, index_position?: number): Promise; /** * 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} */ checkTableMore(code: string, tableName: string, scope: string, primaryKey: string, limit?: number, lower_bound?: number | string, upper_bound?: number | string, index_position?: number): Promise; /** * 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} */ checkTableRange(code: string, tableName: string, scope: string, from: number | string, length?: number, index_position?: number): Promise; /** * 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; /** * 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; static getTableByScope(host: string, code: string, table: string, lower_bound: string | number, upper_bound: string | number, limit?: number): Promise; static help(): string; }