feat: add support for getFirstAvailableBlock method
This commit is contained in:
committed by
Michael Vines
parent
1b8fe71230
commit
925c225885
@ -417,9 +417,9 @@ const GetBlockTimeRpcResult = struct({
|
||||
});
|
||||
|
||||
/**
|
||||
* Expected JSON RPC response for the "minimumLedgerSlot" message
|
||||
* Expected JSON RPC response for the "minimumLedgerSlot" and "getFirstAvailableBlock" messages
|
||||
*/
|
||||
const MinimumLedgerSlotRpcResult = struct({
|
||||
const SlotRpcResult = struct({
|
||||
jsonrpc: struct.literal('2.0'),
|
||||
id: 'string',
|
||||
error: 'any?',
|
||||
@ -1081,7 +1081,7 @@ export class Connection {
|
||||
*/
|
||||
async getMinimumLedgerSlot(): Promise<number> {
|
||||
const unsafeRes = await this._rpcRequest('minimumLedgerSlot', []);
|
||||
const res = MinimumLedgerSlotRpcResult(unsafeRes);
|
||||
const res = SlotRpcResult(unsafeRes);
|
||||
if (res.error) {
|
||||
throw new Error(
|
||||
'failed to get minimum ledger slot: ' + res.error.message,
|
||||
@ -1091,6 +1091,21 @@ export class Connection {
|
||||
return res.result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the slot of the lowest confirmed block that has not been purged from the ledger
|
||||
*/
|
||||
async getFirstAvailableBlock(): Promise<number> {
|
||||
const unsafeRes = await this._rpcRequest('getFirstAvailableBlock', []);
|
||||
const res = SlotRpcResult(unsafeRes);
|
||||
if (res.error) {
|
||||
throw new Error(
|
||||
'failed to get first available block: ' + res.error.message,
|
||||
);
|
||||
}
|
||||
assert(typeof res.result !== 'undefined');
|
||||
return res.result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch information about the current supply
|
||||
*/
|
||||
|
Reference in New Issue
Block a user