fix: add api for getMinimumBalanceForRentExemption
This commit is contained in:
committed by
Michael Vines
parent
432345b4d4
commit
4ae90c2944
@ -294,6 +294,11 @@ const GetTransactionCountRpcResult = jsonRpcResult('number');
|
||||
*/
|
||||
const GetTotalSupplyRpcResult = jsonRpcResult('number');
|
||||
|
||||
/**
|
||||
* Expected JSON RPC response for the "getMinimumBalanceForRentExemption" message
|
||||
*/
|
||||
const GetMinimumBalanceForRentExemptionRpcResult = jsonRpcResult('number');
|
||||
|
||||
/**
|
||||
* Expected JSON RPC response for the "getRecentBlockhash" message
|
||||
*/
|
||||
@ -683,6 +688,23 @@ export class Connection {
|
||||
return GetInflationResult(res.result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the minimum balance needed to exempt an account of `dataLength`
|
||||
* size from rent
|
||||
*/
|
||||
async getMinimumBalanceForRentExemption(dataLength: number): Promise<number> {
|
||||
const unsafeRes = await this._rpcRequest(
|
||||
'getMinimumBalanceForRentExemption',
|
||||
[dataLength],
|
||||
);
|
||||
const res = GetMinimumBalanceForRentExemptionRpcResult(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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user