feat: add getLeaderSchedule api
This commit is contained in:
committed by
Justin Starry
parent
74b4830ba6
commit
d0e139ffff
@ -288,6 +288,21 @@ const GetEpochScheduleResult = struct({
|
||||
firstNormalSlot: 'number',
|
||||
});
|
||||
|
||||
/**
|
||||
* Leader schedule
|
||||
* (see https://docs.solana.com/terminology#leader-schedule)
|
||||
*
|
||||
* @typedef {Object} LeaderSchedule
|
||||
*/
|
||||
type LeaderSchedule = {
|
||||
[address: string]: number[],
|
||||
};
|
||||
|
||||
const GetLeaderScheduleResult = struct.record([
|
||||
'string',
|
||||
struct.array(['number']),
|
||||
]);
|
||||
|
||||
/**
|
||||
* Transaction error or null
|
||||
*/
|
||||
@ -424,6 +439,13 @@ const GetEpochScheduleRpcResult = struct({
|
||||
result: GetEpochScheduleResult,
|
||||
});
|
||||
|
||||
/**
|
||||
* Expected JSON RPC response for the "getLeaderSchedule" message
|
||||
*/
|
||||
const GetLeaderScheduleRpcResult = jsonRpcResult(
|
||||
GetLeaderScheduleResult,
|
||||
);
|
||||
|
||||
/**
|
||||
* Expected JSON RPC response for the "getBalance" message
|
||||
*/
|
||||
@ -1476,6 +1498,20 @@ export class Connection {
|
||||
return GetEpochScheduleResult(res.result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the leader schedule for the current epoch
|
||||
* @return {Promise<RpcResponseAndContext<LeaderSchedule>>}
|
||||
*/
|
||||
async getLeaderSchedule(): Promise<LeaderSchedule> {
|
||||
const unsafeRes = await this._rpcRequest('getLeaderSchedule', []);
|
||||
const res = GetLeaderScheduleRpcResult(unsafeRes);
|
||||
if (res.error) {
|
||||
throw new Error('failed to get leader schedule: ' + res.error.message);
|
||||
}
|
||||
assert(typeof res.result !== 'undefined');
|
||||
return res.result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the minimum balance needed to exempt an account of `dataLength`
|
||||
* size from rent
|
||||
|
Reference in New Issue
Block a user