fix: add missing getSlot API

This commit is contained in:
Michael Vines
2019-08-02 16:06:54 -07:00
parent 60ac6fc5b7
commit 2eeaf668fa
3 changed files with 45 additions and 0 deletions

View File

@ -160,6 +160,11 @@ const GetProgramAccountsRpcResult = jsonRpcResult(
*/
const ConfirmTransactionRpcResult = jsonRpcResult('boolean');
/**
* Expected JSON RPC response for the "getSlot" message
*/
const GetSlot = jsonRpcResult('number');
/**
* Expected JSON RPC response for the "getSlotLeader" message
*/
@ -535,6 +540,20 @@ export class Connection {
return res.result;
}
/**
* Fetch the current slot that the node is processing
*/
async getSlot(): Promise<number> {
const unsafeRes = await this._rpcRequest('getSlot', []);
const res = GetSlot(unsafeRes);
if (res.error) {
throw new Error(res.error.message);
}
assert(typeof res.result !== 'undefined');
return res.result;
}
/**
* Fetch the current slot leader of the cluster
*/