import { BigNumber } from '@ethersproject/bignumber'; import { Client } from '@open-rpc/client-js'; import { DeployUtil, CLPublicKey, StoredValue, Transfers } from '..'; import { SafeEventEmitterProvider } from './ProviderTransport'; import { ValidatorWeight, RpcResult, RpcRequestProps, GetDeployResult, JsonBlockHash, GetBlockResult, GetPeersResult, GetStatusResult, DeployResult, SpeculativeExecutionResult, BlockIdentifier, GetChainSpecResult, StateIdentifier } from './types'; export { JSONRPCError } from '@open-rpc/client-js'; export declare enum PurseIdentifier { MainPurseUnderPublicKey = "main_purse_under_public_key", MainPurseUnderAccountHash = "main_purse_under_account_hash", PurseUref = "purse_uref" } /** Object to represent era specific information */ export declare class EraSummary { /** The hash of the block when the era was encountered */ blockHash: string; /** The id of the era */ eraId: number; /** A `StoredValue` */ StoredValue: StoredValue; /** The state root hash when the era was encountered */ stateRootHash: string; } /** Interface describing the validators at a certain era */ export interface EraValidators { era_id: number; validator_weights: ValidatorWeight[]; } /** Interface describing a validator auction bid */ export interface Bid { bonding_purse: string; staked_amount: string; delegation_rate: number; reward: string; delegators: Delegators[]; inactive: boolean; } /** Interface describing a delegator */ export interface Delegators { bonding_purse: string; delegatee: string; staked_amount: string; public_key: string; } /** Interface describing a delegator's information */ export interface DelegatorInfo { bonding_purse: string; delegatee: string; reward: string; staked_amount: string; } /** Interface describing a validator's auction bid */ export interface ValidatorBid { public_key: string; bid: Bid; } /** Interface describing the state of a validator auction */ export interface AuctionState { state_root_hash: string; block_height: number; era_validators: EraValidators[]; bids: ValidatorBid[]; } /** Result interface describing validator information */ export interface ValidatorsInfoResult extends RpcResult { api_version: string; auction_state: AuctionState; } /** JSON RPC service for interacting with Casper nodes */ export declare class CasperServiceByJsonRPC { /** JSON RPC client */ protected client: Client; /** * Constructor for building a `CasperServiceByJsonRPC` * @param provider A provider uri */ constructor(provider: string | SafeEventEmitterProvider); /** * Get information about a deploy using its hexadecimal hash * @param deployHash Hex-encoded hash digest. * @param finalizedApprovals Whether to return the deploy with the finalized approvals substituted. If `false` or omitted, returns the deploy with the approvals that were originally received by the node. * @param props optional request props * @returns A `Promise` that resolves to a `GetDeployResult` */ getDeployInfo(deployHash: string, finalizedApprovals?: boolean, props?: RpcRequestProps): Promise; /** * Get block information * @param blockHash A hexadecimal string representing the hash of a block * @param props optional request props * @returns A `Promise` resolving to a `GetBlockResult` */ getBlockInfo(blockHash: JsonBlockHash, props?: RpcRequestProps): Promise; /** * Get block info at a provided block height * @param height The block height at which to gather the block info * @param props optional request props * @returns A `Promise` resolving to a `GetBlockResult` */ getBlockInfoByHeight(height: number, props?: RpcRequestProps): Promise; /** * Get the block info of the latest block added * @param props optional request props * @returns A `Promise` that resolves to a `GetBlockResult` */ getLatestBlockInfo(props?: RpcRequestProps): Promise; /** * Get the attached node's current peers * @param props optional request props * @returns A `Promise` that resolves to a `GetPeersResult` */ getPeers(props?: RpcRequestProps): Promise; /** * Get the status of a node * @param props optional request props * @returns A `Promise` that resolves to a `GetStatusResult` */ getStatus(props?: RpcRequestProps): Promise; /** * Get information on the current validators * @param blockHash (optional) blockHash that you want to check * @param props optional request props * @returns A `Promise` that resolves to a `ValidatorsInfoResult` */ getValidatorsInfo(blockHash?: string, props?: RpcRequestProps): Promise; /** * Get information on the network validators of at a certain block height * @param blockHeight The block height at which to query the validators' info * @param props optional request props * @returns A `Promise` that resolves to a `ValidatorsInfoResult` */ getValidatorsInfoByBlockHeight(blockHeight: number, props?: RpcRequestProps): Promise; /** * Get the reference to an account balance uref by an account's account hash, so it may be cached * @param stateRootHash The state root hash at which the main purse URef will be queried * @param accountHash The account hash of the account * @param props optional request props * @returns The account's main purse URef */ getAccountBalanceUrefByPublicKeyHash(stateRootHash: string, accountHash: string, props?: RpcRequestProps): Promise; /** * Get the reference to an account balance uref by an account's public key, so it may be cached * @param stateRootHash The state root hash at which the main purse URef will be queried * @param publicKey The public key of the account * @param props optional request props * @returns The account's main purse URef * @see [getAccountBalanceUrefByPublicKeyHash](#L380) */ getAccountBalanceUrefByPublicKey(stateRootHash: string, publicKey: CLPublicKey, props?: RpcRequestProps): Promise; /** * Get the balance of an account using its main purse URef * @param stateRootHash The state root hash at which the account balance will be queried * @param balanceUref The URef of an account's main purse URef * @param props optional request props * @deprecated since casper-node 1.5, use `queryBalance` method instead * @returns An account's balance */ getAccountBalance(stateRootHash: string, balanceUref: string, props?: RpcRequestProps): Promise; /** * Returns balance using a purse identifier and a state identifier * @added casper-node 1.5 * @example * ```ts * const client = new CasperServiceByJsonRPC("http://localhost:11101/rpc"); * const balance = await client.queryBalance(PurseIdentifier.MainPurseUnderAccountHash, "account-hash-0909090909090909090909090909090909090909090909090909090909090909"); * ``` * @param purseIdentifierType purse type enum * @param purseIdentifier purse identifier * @param stateRootHash state root hash at which the block state will be queried * @param props optional request props * @returns Purse balance */ queryBalance(purseIdentifierType: PurseIdentifier, purseIdentifier: string, stateIdentifier?: StateIdentifier, props?: RpcRequestProps): Promise; /** * Get the state root hash at a specific block hash * @param blockHashBase16 The hexadecimal string representation of a block hash * @param props optional request props * @returns A `Promise` resolving to a state root hash hexadecimal string */ getStateRootHash(blockHashBase16?: JsonBlockHash, props?: RpcRequestProps): Promise; /** * Get the state root hash at a specific block height * @param blockHeight The height of a block hash * @param props optional request props * @returns A `Promise` resolving to a state root hash hexadecimal string */ getStateRootHashByHeight(blockHeight: number, props?: RpcRequestProps): Promise; /** * Get the global block state at a certain state root hash, path, and key * @param stateRootHash The state root hash at which the block state will be queried * @param key The key at which to query the state * @param path An array of a path / paths at which to query the state * @param props optional request props * @returns The block state at the state root hash, path, and key provided, as a `StoredValue` */ getBlockState(stateRootHash: string, key: string, path: string[], props?: RpcRequestProps): Promise; /** * Check deploy size and throws error if deploy size exceeds 1 Mbytes. * @param deploy deploy to check size. */ checkDeploySize(deploy: DeployUtil.Deploy): void; /** * Deploys a provided signed deploy * @param signedDeploy A signed `Deploy` object to be sent to a node * @param props optional request props * @remarks A deploy must not exceed 1 megabyte */ deploy(signedDeploy: DeployUtil.Deploy, props?: RpcRequestProps & { /** * Throws error for unsigned deploy if true * @default false */ checkApproval?: boolean; }): Promise; /** * Wait for deploy to be confirmed on-chain * @param deploy deploy instance or deploy hash * @param timeout optional parameter for timeout * @returns GetDepoyResult */ waitForDeploy(deploy: DeployUtil.Deploy | string, timeout?: number): Promise; /** * Estimate execution cost of the deploy without committing the execution result to the global state. * By default, `speculative_exec` JSON RPC method is **DISABLED** on a node. * Sending a request to a node with the endpoint disabled will result in an error message. * If enabled, `speculative_exec` operates on a separate port from the primary JSON-RPC, using 7778. * @added casper-node 1.5 * @param signedDeploy signed deploy object * @param blockIdentifier block identifier * @param props optional request props * @returns deploy execution result */ speculativeDeploy(signedDeploy: DeployUtil.Deploy, blockIdentifier?: BlockIdentifier, props?: RpcRequestProps): Promise; /** * Retrieves all transfers for a block from the network * @param blockHash Hexadecimal block hash. If not provided, the last block added to the chain, known as the given node, will be used * @param props optional request props * @returns A `Promise` resolving to a `Transfers` containing block transfers */ getBlockTransfers(blockHash?: string, props?: RpcRequestProps): Promise; /** * Retrieve era information at the block hash of a [switch block](https://docs.casperlabs.io/economics/consensus/#entry) * @param blockHash Hexadecimal block hash. If not provided, the last block added to the chain, known as the given node, will be used * @param props optional request props * @returns A `Promise` resolving to an `EraSummary` containing the era information */ getEraInfoBySwitchBlock(blockHash?: string, props?: RpcRequestProps): Promise; /** * Retrieve era information by [switch block](https://docs.casperlabs.io/economics/consensus/#entry) height * @param height The height of the switch block * @param props optional request props * @returns A `Promise` resolving to an `EraSummary` containing the era information */ getEraInfoBySwitchBlockHeight(height: number, props?: RpcRequestProps): Promise; /** * Retrieve era summary information by block hash (if provided) or most recently added block * @param blockHash Hexadecimal block hash. If not provided, the last block added to the chain, known as the given node, will be used * @returns A `Promise` resolving to an `EraSummary` containing the era information */ getEraSummary(blockHash?: string): Promise; /** * Retrieve era summary information by block height (if provided) or most recently added block * @param blockHeight The height of the switch block * @returns A `Promise` resolving to an `EraSummary` containing the era information */ getEraSummaryByBlockHeight(blockHeight?: number): Promise; /** * Get a dictionary item by its URef * @param stateRootHash The state root hash at which the item will be queried * @param dictionaryItemKey The key at which the item is stored * @param seedUref The seed URef of the dictionary * @param opts.rawData Returns rawData if true, otherwise return parsed data * @param props optional request props * @returns A `Promise` resolving to a `StoredValue` containing the item */ getDictionaryItemByURef(stateRootHash: string, dictionaryItemKey: string, seedUref: string, props?: RpcRequestProps & { rawData?: boolean; }): Promise; /** * Get a dictionary item by its name from within a contract * @param stateRootHash The state root hash at which the item will be queried * @param contractHash The contract hash of the contract that stores the queried dictionary * @param dictionaryName The name of the dictionary * @param dictionaryItemKey The key at which the item is stored * @param opts.rawData Returns rawData if true, otherwise return parsed data * @param props optional request props * @returns A `Promise` resolving to a `StoredValue` containing the item */ getDictionaryItemByName(stateRootHash: string, contractHash: string, dictionaryName: string, dictionaryItemKey: string, props?: RpcRequestProps & { rawData?: boolean; }): Promise; /** * Returns raw bytes for chainspec files. * @added casper-node 1.5 * @param props optional request props * @returns chainspec files content in bytes */ getChainSpec(props?: RpcRequestProps): Promise; }