@mavrykdynamics/taquito-rpc
Version:
Provides low level methods, and types to invoke RPC calls from a Nomadic Mavryk RPC node
1,033 lines (1,032 loc) • 55 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RpcClientCache = void 0;
const rpc_client_interface_1 = require("./../rpc-client-interface");
const rpc_client_interface_2 = require("../rpc-client-interface");
const taquito_core_1 = require("@mavrykdynamics/taquito-core");
const taquito_utils_1 = require("@mavrykdynamics/taquito-utils");
const defaultTtl = 1000;
/***
* @description RpcClientCache acts as a decorator over the RpcClient instance by caching responses for the period defined by the ttl.
*/
class RpcClientCache {
/**
*
* @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, ttl = defaultTtl) {
this.rpcClient = rpcClient;
this.ttl = ttl;
this._cache = {};
}
getAllCachedData() {
return this._cache;
}
/**
* @description Remove all the data in the cache.
*
*/
deleteAllCachedData() {
for (const key in this._cache) {
delete this._cache[key];
}
}
formatCacheKey(rpcUrl, rpcMethodName, rpcMethodParams, rpcMethodData) {
let paramsToString = '';
rpcMethodParams.forEach((param) => {
paramsToString =
typeof param === 'object'
? paramsToString + JSON.stringify(param) + '/'
: paramsToString + param + '/';
});
return rpcMethodData
? `${rpcUrl}/${rpcMethodName}/${paramsToString}${JSON.stringify(rpcMethodData)}/`
: `${rpcUrl}/${rpcMethodName}/${paramsToString}`;
}
has(key) {
return key in this._cache;
}
get(key) {
return this._cache[key].response;
}
put(key, response) {
const handle = setTimeout(() => {
return this.remove(key);
}, this.ttl);
Object.assign(this._cache, { [key]: { handle, response } });
}
remove(key) {
if (key in this._cache) {
delete this._cache[key];
}
}
validateAddress(address) {
const addressValidation = (0, taquito_utils_1.validateAddress)(address);
if (addressValidation !== taquito_utils_1.ValidationResult.VALID) {
throw new taquito_core_1.InvalidAddressError(address, (0, taquito_utils_1.invalidDetail)(addressValidation));
}
}
validateContract(address) {
const addressValidation = (0, taquito_utils_1.validateContractAddress)(address);
if (addressValidation !== taquito_utils_1.ValidationResult.VALID) {
throw new taquito_core_1.InvalidContractAddressError(address, (0, taquito_utils_1.invalidDetail)(addressValidation));
}
}
/**
* @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 } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_BLOCK_HASH, [
block,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getBlockHash({ block });
this.put(key, response);
return response;
}
});
}
/**
* @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 } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_LIVE_BLOCKS, [
block,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getLiveBlocks({ block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
this.validateAddress(address);
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_BALANCE, [
block,
address,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getBalance(address, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
this.validateAddress(address);
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_FULL_BALANCE, [
block,
address,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getFullBalance(address, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
this.validateAddress(address);
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_STAKED_BALANCE, [
block,
address,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getStakedBalance(address, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
this.validateAddress(address);
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_UNSTAKED_FINALIZABLE_BALANCE, [block, address]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getUnstakedFinalizableBalance(address, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
this.validateAddress(address);
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_UNSTAKED_FROZEN_BALANCE, [block, address]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getUnstakedFrozenBalance(address, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
this.validateAddress(address);
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_UNSTAKE_REQUESTS, [block, address]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getUnstakeRequests(address, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
this.validateContract(address);
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_STORAGE, [
block,
address,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getStorage(address, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
this.validateContract(address);
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_SCRIPT, [
block,
address,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getScript(address, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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, unparsingMode = { unparsing_mode: 'Readable' }, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
this.validateContract(address);
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_NORMALIZED_SCRIPT, [block, address], unparsingMode);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getNormalizedScript(address, unparsingMode, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
this.validateAddress(address);
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_CONTRACT, [
block,
address,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getContract(address, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
this.validateAddress(address);
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_MANAGER_KEY, [
block,
address,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getManagerKey(address, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
this.validateAddress(address);
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_DELEGATE, [
block,
address,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getDelegate(address, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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, key, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
this.validateAddress(address);
const keyUrl = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_BIG_MAP_KEY, [block, address], key);
if (this.has(keyUrl)) {
return this.get(keyUrl);
}
else {
const response = this.rpcClient.getBigMapKey(address, key, { block });
this.put(keyUrl, response);
return response;
}
});
}
/**
* @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, expr, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_BIG_MAP_EXPR, [
block,
id,
expr,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getBigMapExpr(id, expr, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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 = {}, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_ALL_DELEGATES, [
block,
args,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getAllDelegates(args, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
this.validateAddress(address);
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_DELEGATES, [
block,
address,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getDelegates(address, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
this.validateAddress(address);
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_VOTING_INFO, [
block,
address,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getVotingInfo(address, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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 } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_CONSTANTS, [
block,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getConstants({ block });
this.put(key, response);
return response;
}
});
}
/**
* @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 } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_BLOCK, [block]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getBlock({ block });
this.put(key, response);
return response;
}
});
}
/**
* @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 } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_BLOCK_HEADER, [
block,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getBlockHeader({ block });
this.put(key, response);
return response;
}
});
}
/**
* @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 } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_BLOCK_METADATA, [
block,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getBlockMetadata({ block });
this.put(key, response);
return response;
}
});
}
/**
* @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 = {}, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_BAKING_RIGHTS, [
block,
args,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getBakingRights(args, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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 = {}, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_ATTESTATION_RIGHTS, [block, args]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getAttestationRights(args, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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 } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_BALLOT_LIST, [
block,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getBallotList({ block });
this.put(key, response);
return response;
}
});
}
/**
* @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 } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_BALLOTS, [block]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getBallots({ block });
this.put(key, response);
return response;
}
});
}
/**
* @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, } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_CURRENT_PROPOSAL, [block]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getCurrentProposal({ block });
this.put(key, response);
return response;
}
});
}
/**
* @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, } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_CURRENT_QUORUM, [
block,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getCurrentQuorum({ block });
this.put(key, response);
return response;
}
});
}
/**
* @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, } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_VOTES_LISTINGS, [
block,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getVotesListings({ block });
this.put(key, response);
return response;
}
});
}
/**
* @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 } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_PROPOSALS, [
block,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getProposals({ block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
return this.rpcClient.forgeOperations(data, { block });
});
}
/**
* @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) {
return __awaiter(this, void 0, void 0, function* () {
return this.rpcClient.injectOperation(signedOpBytes);
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
return this.rpcClient.preapplyOperations(ops, { block });
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
this.validateContract(contract);
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_ENTRYPOINTS, [
block,
contract,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getEntrypoints(contract, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
return this.rpcClient.runOperation(op, { block });
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
return this.rpcClient.simulateOperation(op, { block });
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
return this.rpcClient.runCode(code, { block });
});
}
/**
* @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(_a, _b) {
var { unparsing_mode = 'Readable' } = _a, rest = __rest(_a, ["unparsing_mode"]);
var _c = _b === void 0 ? rpc_client_interface_2.defaultRPCOptions : _b, block = _c.block;
return __awaiter(this, void 0, void 0, function* () {
return this.rpcClient.runScriptView(Object.assign({ unparsing_mode }, rest), { block });
});
}
/**
* @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(_a, _b) {
var { unparsing_mode = 'Readable' } = _a, rest = __rest(_a, ["unparsing_mode"]);
var _c = _b === void 0 ? rpc_client_interface_2.defaultRPCOptions : _b, block = _c.block;
return __awaiter(this, void 0, void 0, function* () {
return this.rpcClient.runView(Object.assign({ unparsing_mode }, rest), { block });
});
}
getChainId() {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_CHAIN_ID, []);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getChainId();
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.PACK_DATA, [block], data);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.packData(data, { block });
this.put(key, response);
return response;
}
});
}
/**
*
* @description Return rpc root url
*/
getRpcUrl() {
return this.rpcClient.getRpcUrl();
}
/**
* @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, } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_CURRENT_PERIOD, [
block,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getCurrentPeriod({ block });
this.put(key, response);
return response;
}
});
}
/**
* @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, } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_SUCCESSOR_PERIOD, [block]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getSuccessorPeriod({ block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_SAPLING_DIFF_BY_ID, [block, id]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getSaplingDiffById(id, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_SAPLING_DIFF_BY_CONTRACT, [block, contract]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getSaplingDiffByContract(contract, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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 } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_PROTOCOLS, [
block,
]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getProtocols({ block });
this.put(key, response);
return response;
}
});
}
/**
* @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, { block } = rpc_client_interface_2.defaultRPCOptions) {
return __awaiter(this, void 0, void 0, function* () {
const key = this.formatCacheKey(this.rpcClient.getRpcUrl(), rpc_client_interface_1.RPCMethodName.GET_STORAGE_USED_SPACE, [block, contract]);
if (this.has(key)) {
return this.get(key);
}
else {
const response = this.rpcClient.getStorageUsedSpace(contract, { block });
this.put(key, response);
return response;
}
});
}
/**
* @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