Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ChainRpc

Hierarchy

  • ChainRpc

Index

Methods

containsTransaction

  • containsTransaction(hash: H256Value): Promise<boolean>
  • Queries whether the chain has the transaction of given tx.

    Parameters

    • hash: H256Value

      The tx hash of which to get the corresponding tx of.

    Returns Promise<boolean>

    boolean when transaction of given hash not exists.

executeTransaction

  • executeTransaction(tx: Transaction, sender: PlatformAddressValue): Promise<string | null>
  • Executes the transactions.

    Parameters

    • tx: Transaction

      A transaction to execute.

    • sender: PlatformAddressValue

      A platform address of sender.

    Returns Promise<string | null>

    True, if the transaction is executed successfully. False, if the transaction is not executed.

executeVM

  • executeVM(transaction: SignedTransaction, parameters: string[][], indices: number[]): Promise<string[]>
  • Execute the inputs of the AssetTransfer transaction in the CodeChain VM.

    Parameters

    • transaction: SignedTransaction

      The transaction that its inputs will be executed.

    • parameters: string[][]

      Parameters of the outputs as an array.

    • indices: number[]

      Indices of inputs to run in VM.

    Returns Promise<string[]>

    The results of VM execution.

getAsset

  • getAsset(tracker: H256Value, index: number, shardId: number, blockNumber?: undefined | number): Promise<Asset | null>
  • Gets asset of given transaction hash and index.

    Parameters

    • tracker: H256Value

      The tracker of previous input transaction.

    • index: number

      The index of output in the transaction.

    • shardId: number

      The shard id of output in the transaction.

    • Optional blockNumber: undefined | number

      The specific block number to get the asset from

    Returns Promise<Asset | null>

    Asset, if asset exists, Else, returns null.

getAssetSchemeByTracker

  • getAssetSchemeByTracker(tracker: H256Value, shardId: number, blockNumber?: number | null): Promise<AssetScheme | null>
  • Gets asset scheme of given tracker of the mint transaction.

    Parameters

    • tracker: H256Value

      The tracker of the mint transaction.

    • shardId: number

      The shard id of Asset Scheme.

    • Optional blockNumber: number | null

      The specific block number to get the asset scheme from

    Returns Promise<AssetScheme | null>

    AssetScheme, if asset scheme exists. Else, returns null.

getAssetSchemeByType

  • getAssetSchemeByType(assetType: H160Value, shardId: number, blockNumber?: number | null): Promise<AssetScheme | null>
  • Gets asset scheme of asset type

    Parameters

    • assetType: H160Value

      The type of Asset.

    • shardId: number

      The shard id of Asset Scheme.

    • Optional blockNumber: number | null

      The specific block number to get the asset scheme from

    Returns Promise<AssetScheme | null>

    AssetScheme, if asset scheme exists. Else, returns null.

getBalance

  • getBalance(address: PlatformAddressValue, blockNumber?: undefined | number): Promise<U64>
  • Gets balance of an account of given address, recorded in the block of given blockNumber. If blockNumber is not given, then returns balance recorded in the most recent block.

    Parameters

    • address: PlatformAddressValue

      An account address

    • Optional blockNumber: undefined | number

      The specific block number to get account's balance at given address.

    Returns Promise<U64>

    Balance of account at the specified block, or null if no such block exists.

getBestBlockId

  • getBestBlockId(): Promise<object>
  • Gets the id of the latest block.

    Returns Promise<object>

    A number and the hash of the latest block.

getBestBlockNumber

  • getBestBlockNumber(): Promise<number>
  • Gets number of the latest block.

    Returns Promise<number>

    Number of the latest block.

getBlock

  • getBlock(hashOrNumber: H256Value | number): Promise<Block | null>
  • Gets block of given block hash.

    Parameters

    • hashOrNumber: H256Value | number

      The block hash or number of which to get the block of

    Returns Promise<Block | null>

    Block, if block exists. Else, returns null.

getBlockHash

  • getBlockHash(blockNumber: number): Promise<H256 | null>
  • Gets block hash of given blockNumber.

    Parameters

    • blockNumber: number

      The block number of which to get the block hash of.

    Returns Promise<H256 | null>

    BlockHash, if block exists. Else, returns null.

getBlockTransactionCountByHash

  • getBlockTransactionCountByHash(hash: H256Value): Promise<number | null>
  • Gets the number of transactions within a block that corresponds with the given hash.

    Parameters

    • hash: H256Value

      The block hash.

    Returns Promise<number | null>

    A number of transactions within a block.

getErrorHint

  • getErrorHint(transactionHash: H256Value): Promise<string | null>
  • Gets a hint to find out why the transaction failed.

    Parameters

    • transactionHash: H256Value

      A transaction hash from which the error hint would get.

    Returns Promise<string | null>

    Null if the transaction is not involved in the chain or succeeded. If the transaction failed, this should return the reason for the transaction failing.

getGenesisAccounts

  • getGenesisAccounts(): Promise<PlatformAddress[]>
  • Gets the platform account in the genesis block

    Returns Promise<PlatformAddress[]>

    The platform addresses in the genesis block.

getMiningReward

  • getMiningReward(blockNumber: number): Promise<U64 | null>
  • Gets the mining reward of the given block number.

    Parameters

    • blockNumber: number

      A block nubmer.

    Returns Promise<U64 | null>

    The amount of mining reward, or null if the given block number is not mined yet.

getNetworkId

getNumberOfShards

  • getNumberOfShards(blockNumber?: undefined | number): Promise<number>
  • Gets the number of shards, at the state of the given blockNumber

    Parameters

    • Optional blockNumber: undefined | number

      A block number.

    Returns Promise<number>

    A number of shards

getPendingTransactions

  • getPendingTransactions(from?: number | null, to?: number | null): Promise<object>
  • Gets pending transactions that have the insertion timestamp within the given range.

    Parameters

    • Optional from: number | null

      The lower bound of the insertion timestamp.

    • Optional to: number | null

      The upper bound of the insertion timestamp.

    Returns Promise<object>

    List of SignedTransaction, with each tx has null for blockNumber/blockHash/transactionIndex.

getPendingTransactionsCount

  • getPendingTransactionsCount(from?: number | null, to?: number | null): Promise<number>
  • Gets the count of the pending transactions within the given range from the transaction queues.

    Parameters

    • Optional from: number | null

      The lower bound of collected pending transactions. If null, there is no lower bound.

    • Optional to: number | null

      The upper bound of collected pending transactions. If null, there is no upper bound.

    Returns Promise<number>

    The count of the pending transactions.

getRegularKey

  • getRegularKey(address: PlatformAddressValue, blockNumber?: undefined | number): Promise<H512 | null>
  • Gets the regular key of an account of given address, recorded in the block of given blockNumber. If blockNumber is not given, then returns the regular key in the most recent block.

    Parameters

    • address: PlatformAddressValue

      An account address

    • Optional blockNumber: undefined | number

      The specific block number to get account's regular key at given address.

    Returns Promise<H512 | null>

    The regular key of account at specified block.

getRegularKeyOwner

  • getRegularKeyOwner(regularKey: H512Value, blockNumber?: undefined | number): Promise<PlatformAddress | null>
  • Gets the owner of a regular key, recorded in the block of given blockNumber.

    Parameters

    • regularKey: H512Value

      A regular key.

    • Optional blockNumber: undefined | number

      A block number.

    Returns Promise<PlatformAddress | null>

    The platform address that can use the regular key at the specified block.

getSeq

  • getSeq(address: PlatformAddressValue, blockNumber?: undefined | number): Promise<number>
  • Gets seq of an account of given address, recorded in the block of given blockNumber. If blockNumber is not given, then returns seq recorded in the most recent block.

    Parameters

    • address: PlatformAddressValue

      An account address

    • Optional blockNumber: undefined | number

      The specific block number to get account's seq at given address.

    Returns Promise<number>

    Seq of account at the specified block, or null if no such block exists.

getShardIdByHash

  • getShardIdByHash(hash: H256Value, blockNumber?: undefined | number): Promise<number | null>
  • Gets the shard id of the given hash of a CreateShard transaction.

    Parameters

    • hash: H256Value

      A transaction hash of a CreateShard transaction.

    • Optional blockNumber: undefined | number

      A block number.

    Returns Promise<number | null>

    A shard id.

getShardOwners

  • getShardOwners(shardId: number, blockNumber?: undefined | number): Promise<PlatformAddress[] | null>
  • Gets the owners of the shard.

    Parameters

    • shardId: number

      A shard id.

    • Optional blockNumber: undefined | number

    Returns Promise<PlatformAddress[] | null>

    The platform addresses of the owners.

getShardRoot

  • getShardRoot(shardId: number, blockNumber?: undefined | number): Promise<H256 | null>
  • Gets the root of the shard, at the state of the given blockNumber.

    Parameters

    • shardId: number

      A shard Id.

    • Optional blockNumber: undefined | number

      A block number.

    Returns Promise<H256 | null>

    The hash of root of the shard.

getShardUsers

  • getShardUsers(shardId: number, blockNumber?: undefined | number): Promise<PlatformAddress[] | null>
  • Gets the users of the shard.

    Parameters

    • shardId: number

      A shard id.

    • Optional blockNumber: undefined | number

    Returns Promise<PlatformAddress[] | null>

    The platform addresses of the users.

getText

  • getText(txHash: H256Value, blockNumber?: number | null): Promise<Text | null>
  • Gets the text of the given hash of tx with Store type.

    Parameters

    • txHash: H256Value

      The tx hash of the Store tx.

    • Optional blockNumber: number | null

      The specific block number to get the text from

    Returns Promise<Text | null>

    Text, if text exists. Else, returns null.

getTransaction

  • Gets SignedTransaction of given hash. Else returns null.

    Parameters

    • hash: H256Value

      SignedTransaction's hash

    Returns Promise<SignedTransaction | null>

    SignedTransaction, or null when SignedTransaction was not found.

getTransactionByTracker

  • Gets a transaction of given hash.

    Parameters

    • tracker: H256Value

      The tracker of which to get the corresponding transaction of.

    Returns Promise<SignedTransaction | null>

    A transaction, or null when transaction of given hash not exists.

getTransactionResultsByTracker

  • getTransactionResultsByTracker(tracker: H256Value, options?: object): Promise<boolean[]>
  • Gets results of a transaction of given tracker.

    Parameters

    • tracker: H256Value

      The transaction hash of which to get the corresponding transaction of.

    • Default value options: object = {}
      • Optional timeout?: undefined | number

        Indicating milliseconds to wait the transaction to be confirmed.

    Returns Promise<boolean[]>

    List of boolean, or null when transaction of given hash not exists.

isAssetSpent

  • isAssetSpent(txhash: H256Value, index: number, shardId: number, blockNumber?: undefined | number): Promise<boolean | null>
  • Checks whether an asset is spent or not.

    Parameters

    • txhash: H256Value

      The tx hash of AssetMintTransaction or AssetTransferTransaction.

    • index: number

      The index of output in the transaction.

    • shardId: number

      The shard id of an Asset.

    • Optional blockNumber: undefined | number

      The specific block number to get the asset from.

    Returns Promise<boolean | null>

    True, if the asset is spent. False, if the asset is not spent. Null, if no such asset exists.

sendSignedTransaction

  • Sends SignedTransaction to CodeChain's network.

    Parameters

    Returns Promise<H256>

    SignedTransaction's hash.

sendTransaction

  • sendTransaction(tx: Transaction, options?: undefined | object): Promise<H256>
  • Signs a tx with the given account and sends it to CodeChain's network.

    throws

    When the given account cannot afford to pay the fee

    throws

    When the given fee is too low

    throws

    When the given seq does not match

    throws

    When the given account is unknown

    throws

    When the given passphrase does not match

    Parameters

    • tx: Transaction

      The tx to send

    • Optional options: undefined | object

    Returns Promise<H256>

    SignedTransaction's hash

Generated using TypeDoc