feat: add getFeeCalculatorForBlockhash method

This commit is contained in:
Justin Starry
2020-06-04 18:12:59 +08:00
committed by Michael Vines
parent e876081d52
commit e622bb12b3
4 changed files with 119 additions and 2 deletions

View File

@ -783,6 +783,20 @@ const GetRecentBlockhashAndContextRpcResult = jsonRpcResultAndContext(
}),
);
/**
* Expected JSON RPC response for the "getFeeCalculatorForBlockhash" message
*/
const GetFeeCalculatorRpcResult = jsonRpcResultAndContext(
struct.union([
'null',
struct({
feeCalculator: struct({
lamportsPerSignature: 'number',
}),
}),
]),
);
/**
* Expected JSON RPC response for the "requestAirdrop" message
*/
@ -1506,6 +1520,31 @@ export class Connection {
return res.result;
}
/**
* Fetch the fee calculator for a recent blockhash from the cluster, return with context
*/
async getFeeCalculatorForBlockhash(
blockhash: Blockhash,
commitment: ?Commitment,
): Promise<RpcResponseAndContext<FeeCalculator | null>> {
const args = this._argsWithCommitment([blockhash], commitment);
const unsafeRes = await this._rpcRequest(
'getFeeCalculatorForBlockhash',
args,
);
const res = GetFeeCalculatorRpcResult(unsafeRes);
if (res.error) {
throw new Error('failed to get fee calculator: ' + res.error.message);
}
assert(typeof res.result !== 'undefined');
const {context, value} = res.result;
return {
context,
value: value && value.feeCalculator,
};
}
/**
* Fetch a recent blockhash from the cluster
* @return {Promise<{blockhash: Blockhash, feeCalculator: FeeCalculator}>}