UNPKG

@mavrykdynamics/taquito-rpc

Version:

Provides low level methods, and types to invoke RPC calls from a Nomadic Mavryk RPC node

442 lines (441 loc) 28.2 kB
import BigNumber from 'bignumber.js'; import { RpcClientInterface, RPCOptions } from '../rpc-client-interface'; import { BakingRightsQueryArguments, BakingRightsResponse, BalanceResponse, UnstakeRequestsResponse, BallotListResponse, BallotsResponse, BigMapGetResponse, BigMapKey, BigMapResponse, BlockHeaderResponse, BlockMetadata, BlockResponse, ConstantsResponse, ContractResponse, CurrentProposalResponse, CurrentQuorumResponse, DelegateResponse, DelegatesResponse, VotingInfoResponse, AttestationRightsQueryArguments, AttestationRightsResponse, EntrypointsResponse, ForgeOperationsParams, ManagerKeyResponse, OperationHash, PackDataParams, PreapplyParams, PreapplyResponse, ProposalsResponse, ProtocolsResponse, RPCRunCodeParam, RPCRunOperationParam, RPCRunScriptViewParam, RPCRunViewParam, RunCodeResult, RunScriptViewResult, RunViewResult, SaplingDiffResponse, ScriptResponse, StorageResponse, UnparsingMode, VotesListingsResponse, VotingPeriodBlockResult, TicketTokenParams, AllTicketBalances, PendingOperationsQueryArguments, PendingOperationsV1, PendingOperationsV2, RPCSimulateOperationParam, AILaunchCycleResponse, AllDelegatesQueryArguments } from '../types'; interface CachedDataInterface { [key: string]: { handle: () => void; response: Promise<any>; }; } /*** * @description RpcClientCache acts as a decorator over the RpcClient instance by caching responses for the period defined by the ttl. */ export declare class RpcClientCache implements RpcClientInterface { private rpcClient; private ttl; private _cache; /** * * @param rpcClient rpcClient responsible of the interaction with Mavryk network through an rpc node * @param ttl number representing the time to live (default 1000 milliseconds) * * @example new RpcClientCache(new RpcClient('https://mainnet.ecadinfra.com/')) */ constructor(rpcClient: RpcClientInterface, ttl?: number); getAllCachedData(): CachedDataInterface; /** * @description Remove all the data in the cache. * */ deleteAllCachedData(): void; private formatCacheKey; private has; private get; private put; private remove; private validateAddress; private validateContract; /** * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Get the block's hash, its unique identifier. * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-hash */ getBlockHash({ block }?: RPCOptions): Promise<string>; /** * @param options contains generic configuration for rpc calls to specified block (default to head) * @description List the ancestors of the given block which, if referred to as the branch in an operation header, are recent enough for that operation to be included in the current block. * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-live-blocks */ getLiveBlocks({ block }?: RPCOptions): Promise<string[]>; /** * @param address address from which we want to retrieve the balance * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Access the spendable balance of a contract, excluding frozen bonds * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-contracts-contract-id-balance */ getBalance(address: string, { block }?: RPCOptions): Promise<BalanceResponse>; /** * @param address address from which we want to retrieve the full balance * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Access the full balance of a contract, including frozen bonds and stake. * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-contracts-contract-id-full-balance */ getFullBalance(address: string, { block }?: RPCOptions): Promise<BalanceResponse>; /** * @param address address from which we want to retrieve the staked balance * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Access the staked balance of a contract. Returns None if the contract is originated, or neither delegated nor a delegate. * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-contracts-contract-id-staked-balance */ getStakedBalance(address: string, { block }?: RPCOptions): Promise<BalanceResponse>; /** * @param address address from which we want to retrieve the unstaked finalizable balance * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Access the balance of a contract that was requested for an unstake operation, and is no longer frozen, which means it will appear in the spendable balance of the contract after any stake/unstake/finalize_unstake operation. Returns None if the contract is originated. * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-contracts-contract-id-unstaked-finalizable-balance */ getUnstakedFinalizableBalance(address: string, { block }?: RPCOptions): Promise<BalanceResponse>; /** * @param address address from which we want to retrieve the unstaked frozen balance * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Access the balance of a contract that was requested for an unstake operation, but is still frozen for the duration of the slashing period. Returns None if the contract is originated. * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-contracts-contract-id-unstaked-frozen-balance */ getUnstakedFrozenBalance(address: string, { block }?: RPCOptions): Promise<BalanceResponse>; /** * @param address address from which we want to retrieve the unstake requests * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Access the unstake requests of the contract. The requests that appear in the finalizable field can be finalized, which means that the contract can transfer these (no longer frozen) funds to their spendable balance with a [finalize_unstake] operation call. Returns null if there is no unstake request pending. * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-contracts-contract-id-unstake-requests */ getUnstakeRequests(address: string, { block }?: RPCOptions): Promise<UnstakeRequestsResponse>; /** * @param address contract address from which we want to retrieve the storage * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Access the data of the contract. * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-contracts-contract-id-storage */ getStorage(address: string, { block }?: { block: string; }): Promise<StorageResponse>; /** * @param address contract address from which we want to retrieve the script * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Access the code and data of the contract. * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-contracts-contract-id-script */ getScript(address: string, { block }?: { block: string; }): Promise<ScriptResponse>; /** * @param address contract address from which we want to retrieve the script * @param unparsingMode default is { unparsing_mode: "Readable" } * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Access the script of the contract and normalize it using the requested unparsing mode. */ getNormalizedScript(address: string, unparsingMode?: UnparsingMode, { block }?: { block: string; }): Promise<ScriptResponse>; /** * @param address contract address from which we want to retrieve * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Access the complete status of a contract. * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-contracts-contract-id */ getContract(address: string, { block }?: { block: string; }): Promise<ContractResponse>; /** * @param address contract address from which we want to retrieve the manager * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Access the manager of an implicit contract * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-contracts-contract-id-manager-key */ getManagerKey(address: string, { block }?: { block: string; }): Promise<ManagerKeyResponse>; /** * @param address contract address from which we want to retrieve the delegate (baker) * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Access the delegate of a contract, if any * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-contracts-contract-id-delegate */ getDelegate(address: string, { block }?: { block: string; }): Promise<DelegateResponse>; /** * @deprecated Deprecated in favor of getBigMapKeyByID * @param address contract address from which we want to retrieve the big map key * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Access the value associated with a key in the big map storage of the contract. * @see https://protocol.mavryk.org/active/rpc.html#post-block-id-context-contracts-contract-id-big-map-get */ getBigMapKey(address: string, key: BigMapKey, { block }?: { block: string; }): Promise<BigMapGetResponse>; /** * @param id Big Map ID * @param expr Expression hash to query (A b58check encoded Blake2b hash of the expression (The expression can be packed using the pack_data method)) * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Access the value associated with a key in a big map. * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-big-maps-big-map-id-script-expr */ getBigMapExpr(id: string, expr: string, { block }?: { block: string; }): Promise<BigMapResponse>; /** * @param args contains optional query arguments (active, inactive, with_minimal_stake, without_minimal_stake) * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Lists all registered delegates by default with query arguments to filter unneeded values. * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-delegates-pkh */ getAllDelegates(args?: AllDelegatesQueryArguments, { block }?: { block: string; }): Promise<string[]>; /** * @param address delegate address which we want to retrieve * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Everything about a delegate * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-delegates-pkh */ getDelegates(address: string, { block }?: { block: string; }): Promise<DelegatesResponse>; /** * @param address delegate address which we want to retrieve * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Returns the delegate info (e.g. voting power) found in the listings of the current voting period * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-delegates-pkh-voting-info */ getVotingInfo(address: string, { block }?: { block: string; }): Promise<VotingInfoResponse>; /** * @param options contains generic configuration for rpc calls to specified block (default to head) * @description All constants * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-constants */ getConstants({ block }?: RPCOptions): Promise<ConstantsResponse>; /** * @param options contains generic configuration for rpc calls to specified block (default to head) and version. * @description All the information about a block * @see https://protocol.mavryk.org/active/rpc.html#get-block-id * @example getBlock() will default to `/main/chains/block/head?version=0` which shows { kind: endorsement } * @example getBlock({ block: 'head~2', version: 1 }) will return an offset of 2 from head blocks and shows { kind: attestation } * @example getBlock({ block: 'BL8fTiWcSxWCjiMVnDkbh6EuhqVPZzgWheJ2dqwrxYRm9AephXh~2' }) will return an offset of 2 blocks from given block hash.. */ getBlock({ block }?: RPCOptions): Promise<BlockResponse>; /** * @param options contains generic configuration for rpc calls to specified block (default to head) * @description The whole block header * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-header */ getBlockHeader({ block }?: RPCOptions): Promise<BlockHeaderResponse>; /** * @param options contains generic configuration for rpc calls to specified block (default to head) and version * @description All the metadata associated to the block * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-metadata */ getBlockMetadata({ block }?: RPCOptions): Promise<BlockMetadata>; /** * @param args contains optional query arguments (level, cycle, delegate, consensus_key, and max_round) * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Retrieves the list of delegates allowed to bake a block. * @see https://gitlab.com/mavryk-network/mavryk-protocol/-/blob/master/docs/api/boreas-openapi-rc.json */ getBakingRights(args?: BakingRightsQueryArguments, { block }?: RPCOptions): Promise<BakingRightsResponse>; /** * @param args contains optional query arguments (level, cycle, delegate, and consensus_key) * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Retrieves the delegates allowed to attest a block * @see https://gitlab.com/mavryk-network/mavryk-protocol/-/blob/master/docs/api/boreas-openapi-rc.json */ getAttestationRights(args?: AttestationRightsQueryArguments, { block }?: RPCOptions): Promise<AttestationRightsResponse>; /** * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Ballots casted so far during a voting period * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-votes-ballot-list */ getBallotList({ block }?: RPCOptions): Promise<BallotListResponse>; /** * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Sum of ballots casted so far during a voting period * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-votes-ballots */ getBallots({ block }?: RPCOptions): Promise<BallotsResponse>; /** * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Current proposal under evaluation. * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-votes-current-proposal */ getCurrentProposal({ block, }?: RPCOptions): Promise<CurrentProposalResponse>; /** * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Current expected quorum. * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-votes-current-quorum */ getCurrentQuorum({ block, }?: RPCOptions): Promise<CurrentQuorumResponse>; /** * @param options contains generic configuration for rpc calls to specified block (default to head) * @description List of delegates with their voting power * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-votes-listings */ getVotesListings({ block, }?: RPCOptions): Promise<VotesListingsResponse>; /** * @param options contains generic configuration for rpc calls to specified block (default to head) * @description List of proposals with number of supporters * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-votes-proposals */ getProposals({ block }?: RPCOptions): Promise<ProposalsResponse>; /** * @param data operation contents to forge * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Forge an operation returning the unsigned bytes * @see https://gitlab.com/mavryk-network/mavryk-protocol/-/blob/master/docs/api/boreas-openapi-rc.json */ forgeOperations(data: ForgeOperationsParams, { block }?: RPCOptions): Promise<string>; /** * @param signedOpBytes signed bytes to inject * @description Inject an operation in node and broadcast it and return the ID of the operation * @see https://protocol.mavryk.org/shell/rpc.html#post-injection-operation */ injectOperation(signedOpBytes: string): Promise<OperationHash>; /** * @param ops Operations to apply * @param options contains generic configuration for rpc calls to specified block and version * @description Simulate the application of the operations with the context of the given block and return the result of each operation application * @see https://protocol.mavryk.org/active/rpc.html#post-block-id-helpers-preapply-operations */ preapplyOperations(ops: PreapplyParams, { block }?: RPCOptions): Promise<PreapplyResponse[]>; /** * @param contract address of the contract we want to get the entrypoints of * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Return the list of entrypoints of the contract * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-contracts-contract-id-entrypoints * @version 005_PsBABY5H */ getEntrypoints(contract: string, { block }?: RPCOptions): Promise<EntrypointsResponse>; /** * @deprecated Deprecated in favor of simulateOperation * @param op Operation to run * @param options contains generic configuration for rpc calls to specified block and version * @description Run an operation with the context of the given block and without signature checks and return the operation application result, including the consumed gas. * @see https://gitlab.com/mavryk-network/mavryk-protocol/-/blob/master/docs/api/boreas-openapi-rc.json */ runOperation(op: RPCRunOperationParam, { block }?: RPCOptions): Promise<PreapplyResponse>; /** * @param op Operation to simulate * @param options contains generic configuration for rpc calls to specified block and version * @description Simulate running an operation at some future moment (based on the number of blocks given in the `latency` argument), and return the operation application result. * @see https://gitlab.com/mavryk-network/mavryk-protocol/-/blob/master/docs/api/boreas-openapi-rc.json */ simulateOperation(op: RPCSimulateOperationParam, { block }?: RPCOptions): Promise<PreapplyResponse>; /** * @param code Code to run * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Run a Michelson script in the current context * @see https://gitlab.com/mavryk-network/mavryk-protocol/-/blob/master/docs/api/boreas-openapi-rc.json */ runCode(code: RPCRunCodeParam, { block }?: RPCOptions): Promise<RunCodeResult>; /** * @param viewScriptParams Parameters of the script view to run * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Simulate a call to a michelson view * @see https://gitlab.com/mavryk-network/mavryk-protocol/-/blob/master/docs/api/boreas-openapi-rc.json */ runScriptView({ unparsing_mode, ...rest }: RPCRunScriptViewParam, { block }?: RPCOptions): Promise<RunScriptViewResult>; /** * @param viewParams Parameters of the view to run * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Simulate a call to a view following the TZIP-4 standard. * @see https://gitlab.com/mavryk-network/mavryk-protocol/-/blob/master/docs/api/boreas-openapi-rc.json */ runView({ unparsing_mode, ...rest }: RPCRunViewParam, { block }?: RPCOptions): Promise<RunViewResult>; getChainId(): Promise<any>; /** * @param data Data to pack * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Computes the serialized version of a data expression using the same algorithm as script instruction PACK * Note: You should always verify the packed bytes before signing or requesting that they be signed when using the RPC to pack. * This precaution helps protect you and your applications users from RPC nodes that have been compromised. * A node that is operated by a bad actor, or compromised by a bad actor could return a fully formed operation that does not correspond to the input provided to the RPC endpoint. * A safer solution to pack and sign data would be to use the `packDataBytes` function available in the `@mavrykdynamics/taquito-michel-codec` package. * @example packData({ data: { string: "test" }, type: { prim: "string" } }) * @see https://gitlab.com/mavryk-network/mavryk-protocol/-/blob/master/docs/api/boreas-openapi-rc.json */ packData(data: PackDataParams, { block }?: RPCOptions): Promise<{ packed: string; gas: BigNumber | 'unaccounted' | undefined; }>; /** * * @description Return rpc root url */ getRpcUrl(): string; /** * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Returns the voting period (index, kind, starting position) and related information (position, remaining) of the interrogated block * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-votes-current-period */ getCurrentPeriod({ block, }?: RPCOptions): Promise<VotingPeriodBlockResult>; /** * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Returns the voting period (index, kind, starting position) and related information (position, remaining) of the next block.Useful to craft operations that will be valid in the next block * @example getSuccessorPeriod() will default to successor voting period for /main/chains/block/head. * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-votes-successor-period */ getSuccessorPeriod({ block, }?: RPCOptions): Promise<VotingPeriodBlockResult>; /** * @param id Sapling state ID * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Returns the root and a diff of a state starting from an optional offset which is zero by default * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-sapling-sapling-state-id-get-diff */ getSaplingDiffById(id: string, { block }?: { block: string; }): Promise<SaplingDiffResponse>; /** * @param contract address of the contract we want to get the sapling diff * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Returns the root and a diff of a state starting from an optional offset which is zero by default * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-contracts-contract-id-single-sapling-get-diff */ getSaplingDiffByContract(contract: string, { block }?: { block: string; }): Promise<SaplingDiffResponse>; /** * @param options contains generic configuration for rpc calls to specified block (default to head) * @description get current and next protocol * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-protocols */ getProtocols({ block }?: { block: string; }): Promise<ProtocolsResponse>; /** * @param contract address of the contract we want to retrieve storage information of * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Access the used storage space of the contract * @see https://gitlab.com/mavryk-network/mavryk-protocol/-/blob/master/docs/api/boreas-openapi-rc.json */ getStorageUsedSpace(contract: string, { block }?: { block: string; }): Promise<string>; /** * @param contract address of the contract we want to retrieve storage information of * @param options contains generic configuration for rpc calls to specified block (default to head) = * @description Access the paid storage space of the contract * @see https://gitlab.com/mavryk-network/mavryk-protocol/-/blob/master/docs/api/boreas-openapi-rc.json */ getStoragePaidSpace(contract: string, { block }?: { block: string; }): Promise<string>; /** * @param contract implicit or originated address we want to retrieve ticket balance of * @param ticket object to specify a ticket by ticketer, content type and content * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Access the contract's balance of ticket with specified ticketer, content type, and content. * @example ticket { ticketer: 'address', content_type: { prim: "string" }, content: { string: 'ticket1' } } * @see https://gitlab.com/mavryk-network/mavryk-protocol/-/blob/master/docs/api/boreas-openapi-rc.json */ getTicketBalance(contract: string, ticket: TicketTokenParams, { block }?: RPCOptions): Promise<string>; /** * @param contract originated address we want to retrieve ticket balances of * @param options contains generic configuration for rpc calls to specified block (default to head) * @description Access the complete list of tickets owned by the given contract by scanning the contract's storage. * @see https://gitlab.com/mavryk-network/mavryk-protocol/-/blob/master/docs/api/boreas-openapi-rc.json */ getAllTicketBalances(contract: string, { block }?: RPCOptions): Promise<AllTicketBalances>; /** * @description Returns the cycle at which the launch of the Adaptive Issuance feature is set to happen. A result of null means that the feature is not yet set to launch. * @param options contains generic configuration for rpc calls to specified block (default to head) * @see https://protocol.mavryk.org/active/rpc.html#get-block-id-context-adaptive-issuance-launch-cycle */ getAdaptiveIssuanceLaunchCycle({ block, }?: RPCOptions): Promise<AILaunchCycleResponse>; /** * @description List the prevalidated operations in mempool (accessibility of mempool depends on each rpc endpoint) * @param args has 5 optional properties. We support version 1 & 2 * @default args { version: '2', validated: true, refused: true, outdated, true, branchRefused: true, branchDelayed: true, validationPass: undefined } */ getPendingOperations(args?: PendingOperationsQueryArguments): Promise<PendingOperationsV1 | PendingOperationsV2>; } export {};