1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//! Information about epoch duration.
//!
//! The _epoch schedule_ sysvar provides access to the [`EpochSchedule`] type,
//! which includes the number of slots per epoch, timing of leader schedule
//! selection, and information about epoch warm-up time.
//!
//! [`EpochSchedule`] implements [`Sysvar::get`] and can be loaded efficiently without
//! passing the sysvar account ID to the program.
//!
//! See also the Solana [documentation on the epoch schedule sysvar][sdoc].
//!
//! [sdoc]: https://docs.solanalabs.com/runtime/sysvars#epochschedule
//!
//! # Examples
//!
//! Accessing via on-chain program directly:
//!
//! ```no_run
//! # use rialo_s_account_info::AccountInfo;
//! # use rialo_s_epoch_schedule::EpochSchedule;
//! # use rialo_s_msg::msg;
//! # use rialo_s_program_error::{ProgramError, ProgramResult};
//! # use rialo_s_pubkey::Pubkey;
//! # use rialo_s_sdk_ids::sysvar::epoch_schedule;
//! # use rialo_s_sysvar::Sysvar;
//! fn process_instruction(
//! program_id: &Pubkey,
//! accounts: &[AccountInfo],
//! instruction_data: &[u8],
//! ) -> ProgramResult {
//!
//! let epoch_schedule = EpochSchedule::get()?;
//! msg!("epoch_schedule: {:#?}", epoch_schedule);
//!
//! Ok(())
//! }
//! #
//! # use rialo_s_sysvar_id::SysvarId;
//! # let p = EpochSchedule::id();
//! # let l = &mut 1120560;
//! # let d = &mut vec![0, 32, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
//! # let a = AccountInfo::new(&p, false, false, l, d, &p, false, 0);
//! # let accounts = &[a.clone(), a];
//! # process_instruction(
//! # &Pubkey::new_unique(),
//! # accounts,
//! # &[],
//! # )?;
//! # Ok::<(), ProgramError>(())
//! ```
//!
//! Accessing via on-chain program's account parameters:
//!
//! ```
//! # use rialo_s_account_info::{AccountInfo, next_account_info};
//! # use rialo_s_epoch_schedule::EpochSchedule;
//! # use rialo_s_msg::msg;
//! # use rialo_s_program_error::{ProgramError, ProgramResult};
//! # use rialo_s_pubkey::Pubkey;
//! # use rialo_s_sdk_ids::sysvar::epoch_schedule;
//! # use rialo_s_sysvar::Sysvar;
//! fn process_instruction(
//! program_id: &Pubkey,
//! accounts: &[AccountInfo],
//! instruction_data: &[u8],
//! ) -> ProgramResult {
//! let account_info_iter = &mut accounts.iter();
//! let epoch_schedule_account_info = next_account_info(account_info_iter)?;
//!
//! assert!(epoch_schedule::check_id(epoch_schedule_account_info.key));
//!
//! let epoch_schedule = EpochSchedule::from_account_info(epoch_schedule_account_info)?;
//! msg!("epoch_schedule: {:#?}", epoch_schedule);
//!
//! Ok(())
//! }
//! #
//! # use rialo_s_sysvar_id::SysvarId;
//! # let p = EpochSchedule::id();
//! # let l = &mut 1120560;
//! # let d = &mut vec![0, 32, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
//! # let a = AccountInfo::new(&p, false, false, l, d, &p, false, 0);
//! # let accounts = &[a.clone(), a];
//! # process_instruction(
//! # &Pubkey::new_unique(),
//! # accounts,
//! # &[],
//! # )?;
//! # Ok::<(), ProgramError>(())
//! ```
//!
//! Accessing via the RPC client:
//!
//! ```
//! # use rialo_s_epoch_schedule::EpochSchedule;
//! # use rialo_s_program::example_mocks::rialo_s_sdk;
//! # use rialo_s_program::example_mocks::solana_rpc_client;
//! # use solana_rpc_client::rpc_client::RpcClient;
//! # use rialo_s_sdk::account::Account;
//! # use rialo_s_sdk_ids::sysvar::epoch_schedule;
//! # use anyhow::Result;
//! #
//! fn print_sysvar_epoch_schedule(client: &RpcClient) -> Result<()> {
//! # client.set_get_account_response(epoch_schedule::ID, Account {
//! # kelvins: 1120560,
//! # data: vec![0, 32, 0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
//! # owner: rialo_s_sdk_ids::system_program::ID,
//! # executable: false,
//! # rent_epoch: 307,
//! # });
//! #
//! let epoch_schedule = client.get_account(&epoch_schedule::ID)?;
//! let data: EpochSchedule = bincode::deserialize(&epoch_schedule.data)?;
//!
//! Ok(())
//! }
//! #
//! # let client = RpcClient::new(String::new());
//! # print_sysvar_epoch_schedule(&client)?;
//! #
//! # Ok::<(), anyhow::Error>(())
//! ```
pub use EpochSchedule;
pub use ;
use crate::;