feat: add minimumLedgerSlot api

This commit is contained in:
Justin Starry
2020-05-21 16:58:17 +08:00
committed by Michael Vines
parent 839e93480c
commit 6558e05fd0
4 changed files with 47 additions and 0 deletions

View File

@ -370,6 +370,16 @@ const GetBlockTimeRpcResult = struct({
result: struct.union(['null', 'number']),
});
/**
* Expected JSON RPC response for the "minimumLedgerSlot" message
*/
const MinimumLedgerSlotRpcResult = struct({
jsonrpc: struct.literal('2.0'),
id: 'string',
error: 'any?',
result: 'number',
});
/**
* Expected JSON RPC response for the "getVersion" message
*/
@ -964,6 +974,22 @@ export class Connection {
return res.result;
}
/**
* Fetch the lowest slot that the node has information about in its ledger.
* This value may increase over time if the node is configured to purge older ledger data
*/
async getMinimumLedgerSlot(): Promise<number> {
const unsafeRes = await this._rpcRequest('minimumLedgerSlot', []);
const res = MinimumLedgerSlotRpcResult(unsafeRes);
if (res.error) {
throw new Error(
'failed to get minimum ledger slot: ' + res.error.message,
);
}
assert(typeof res.result !== 'undefined');
return res.result;
}
/**
* Fetch all the account info for the specified public key, return with context
*/