feat: add convenience methods to EpochSchedule (#17810)
* first try, failing test * fix implementation and tests * lint:fix * move method tests to seperate test * lint fix * apply starry's comments and grab the bonus points * minor fixes after starry's second review Co-authored-by: Arrowana <8245419+Arrowana@users.noreply.github.com>
This commit is contained in:
@ -27,6 +27,7 @@ import RpcClient from 'jayson/lib/client/browser';
|
||||
import {IWSRequestParams} from 'rpc-websockets/dist/lib/client';
|
||||
|
||||
import {AgentManager} from './agent-manager';
|
||||
import {EpochSchedule} from './epoch-schedule';
|
||||
import {NonceAccount} from './nonce-account';
|
||||
import {PublicKey} from './publickey';
|
||||
import {Signer} from './keypair';
|
||||
@ -373,23 +374,6 @@ const GetEpochInfoResult = pick({
|
||||
transactionCount: optional(number()),
|
||||
});
|
||||
|
||||
/**
|
||||
* Epoch schedule
|
||||
* (see https://docs.solana.com/terminology#epoch)
|
||||
*/
|
||||
export type EpochSchedule = {
|
||||
/** The maximum number of slots in each epoch */
|
||||
slotsPerEpoch: number;
|
||||
/** The number of slots before beginning of an epoch to calculate a leader schedule for that epoch */
|
||||
leaderScheduleSlotOffset: number;
|
||||
/** Indicates whether epochs start short and grow */
|
||||
warmup: boolean;
|
||||
/** The first epoch with `slotsPerEpoch` slots */
|
||||
firstNormalEpoch: number;
|
||||
/** The first slot of `firstNormalEpoch` */
|
||||
firstNormalSlot: number;
|
||||
};
|
||||
|
||||
const GetEpochScheduleResult = pick({
|
||||
slotsPerEpoch: number(),
|
||||
leaderScheduleSlotOffset: number(),
|
||||
@ -2788,7 +2772,14 @@ export class Connection {
|
||||
if ('error' in res) {
|
||||
throw new Error('failed to get epoch schedule: ' + res.error.message);
|
||||
}
|
||||
return res.result;
|
||||
const epochSchedule = res.result;
|
||||
return new EpochSchedule(
|
||||
epochSchedule.slotsPerEpoch,
|
||||
epochSchedule.leaderScheduleSlotOffset,
|
||||
epochSchedule.warmup,
|
||||
epochSchedule.firstNormalEpoch,
|
||||
epochSchedule.firstNormalSlot,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user