Skip to content

Commit

Permalink
Implement tx costs
Browse files Browse the repository at this point in the history
  • Loading branch information
selankon authored and marcvelmer committed Aug 9, 2024
1 parent ef8eebc commit 0f67075
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/api/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}',
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<IChainTxCosts> {
return axios
.get<IChainTxCosts>(url + ChainAPIMethods.TX_COSTS)
.then((response) => {
return response.data;
})
.catch(this.isApiError);
}

/**
* Fetches information about a transaction from the blockchain.
*
Expand Down

0 comments on commit 0f67075

Please sign in to comment.