Skip to content

Commit

Permalink
Add get minimal fees method (#549)
Browse files Browse the repository at this point in the history
* Add get minimal fees method

* Use fromMAS instead of custom conversion

* Fix doc getMinimalFees
  • Loading branch information
AurelienFT authored Apr 4, 2024
1 parent dfc9d29 commit df39410
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/massa-web3/src/interfaces/INodeStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ export interface INodeStatus {
pool_stats: { endorsement_count: number; operation_count: number }
version: string
chain_id: bigint
minimal_fees?: string
}
7 changes: 7 additions & 0 deletions packages/massa-web3/src/interfaces/IPublicApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,11 @@ export interface IPublicApiClient extends BaseClient {
getGraphInterval(
graphInterval: IGetGraphInterval
): Promise<Array<IGraphInterval>>

/**
* Get the minimal fees required for your operation to be accepted by the API provider
*
* @returns The minimal fees as bigint (in nano-MAS).
*/
getMinimalFees(): Promise<bigint>
}
27 changes: 26 additions & 1 deletion packages/massa-web3/src/web3/PublicApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { IDatastoreEntryInput } from '../interfaces/IDatastoreEntryInput'
import { IGetGraphInterval } from '../interfaces/IGetGraphInterval'
import { IGraphInterval } from '../interfaces/IGraphInterval'
import { IBlockcliqueBlockBySlot } from '../interfaces/IBlockcliqueBlockBySlot'
import { ISlot } from '@massalabs/web3-utils'
import { ISlot, fromMAS } from '@massalabs/web3-utils'

/**
* Public API client for interacting with a Massa node.
Expand All @@ -41,6 +41,7 @@ export class PublicApiClient extends BaseClient implements IPublicApiClient {

// public api methods
this.getNodeStatus = this.getNodeStatus.bind(this)
this.getMinimalFees = this.getMinimalFees.bind(this)
this.getAddresses = this.getAddresses.bind(this)
this.getBlocks = this.getBlocks.bind(this)
this.getEndorsements = this.getEndorsements.bind(this)
Expand Down Expand Up @@ -130,6 +131,30 @@ export class PublicApiClient extends BaseClient implements IPublicApiClient {
return { ...nodeStatus, chain_id: BigInt(nodeStatus.chain_id) }
}

/**
* Retrieves the minimal fees for operations to be accepted by the API provider.
*
* @returns The minimal fees as a bigint (in nano-MAS).
*/
public async getMinimalFees(): Promise<bigint> {
const jsonRpcRequestMethod = JSON_RPC_REQUEST_METHOD.GET_STATUS
let fees: string = '0'
if (this.clientConfig.retryStrategyOn) {
let result = await trySafeExecute<INodeStatus>(this.sendJsonRPCRequest, [
jsonRpcRequestMethod,
[],
])
fees = result.minimal_fees || '0'
} else {
let result = await this.sendJsonRPCRequest<INodeStatus>(
jsonRpcRequestMethod,
[]
)
fees = result.minimal_fees || '0'
}
return fromMAS(fees)
}

/**
* Retrieves data about a list of addresses, such as their balances and block creation details.
*
Expand Down

0 comments on commit df39410

Please sign in to comment.