From 0f6707560b7c8d3f10888ef928ae6edaf9aeab57 Mon Sep 17 00:00:00 2001 From: selankon Date: Fri, 2 Aug 2024 12:13:32 +0200 Subject: [PATCH] Implement tx costs --- src/api/chain.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/api/chain.ts b/src/api/chain.ts index c7593aae..1e85b646 100644 --- a/src/api/chain.ts +++ b/src/api/chain.ts @@ -14,6 +14,7 @@ enum ChainAPIMethods { INFO = '/chain/info', COSTS = '/chain/info/electionPriceFactors', CIRCUITS = '/chain/info/circuit', + TX_COSTS = '/chain/transactions/cost', TX_INFO = '/chain/transactions/reference', TX_INFO_BY_INDEX = '/chain/transactions/reference/index/{index}', TX_INFO_BLOCK = '/chain/transactions/{blockHeight}/{txIndex}', @@ -182,6 +183,26 @@ export enum TransactionType { SET_KEYKEEPER_TX = 'setKeykeeper', } +export interface IChainTxCosts { + costs: { + AddDelegateForAccount: number; + CollectFaucet: number; + CreateAccount: number; + DelAccountSIK: number; + DelDelegateForAccount: number; + NewProcess: number; + RegisterKey: number; + SendTokens: number; + SetAccountInfoURI: number; + SetAccountSIK: number; + SetAccountValidator: number; + SetProcessCensus: number; + SetProcessDuration: number; + SetProcessQuestionIndex: number; + SetProcessStatus: number; + }; +} + export interface IChainTxReference { /** * The number of the transaction. @@ -487,6 +508,19 @@ export abstract class ChainAPI extends API { .catch(this.isApiError); } + /** + * Returns the list of transactions and its cost + * @param url - API endpoint URL + */ + public static txCosts(url: string): Promise { + return axios + .get(url + ChainAPIMethods.TX_COSTS) + .then((response) => { + return response.data; + }) + .catch(this.isApiError); + } + /** * Fetches information about a transaction from the blockchain. *