Expose getTotalSupply RPC method (#370)

This commit is contained in:
Trent Nelson
2019-06-25 09:31:22 -06:00
committed by Michael Vines
parent fd2ddef520
commit 034f31d3bc
3 changed files with 38 additions and 0 deletions

View File

@ -214,6 +214,11 @@ const GetSignatureStatusRpcResult = jsonRpcResult(
*/
const GetTransactionCountRpcResult = jsonRpcResult('number');
/**
* Expected JSON RPC response for the "getTotalSupply" message
*/
const GetTotalSupplyRpcResult = jsonRpcResult('number');
/**
* Expected JSON RPC response for the "getRecentBlockhash" message
*/
@ -524,6 +529,19 @@ export class Connection {
return Number(res.result);
}
/**
* Fetch the current total currency supply of the cluster
*/
async getTotalSupply(): Promise<number> {
const unsafeRes = await this._rpcRequest('getTotalSupply', []);
const res = GetTotalSupplyRpcResult(unsafeRes);
if (res.error) {
throw new Error(res.error.message);
}
assert(typeof res.result !== 'undefined');
return Number(res.result);
}
/**
* Fetch a recent blockhash from the cluster
*/