gemachain_program/sysvar/
slot_hashes.rs

1//! named accounts for synthesized data accounts for bank state, etc.
2//!
3//! this account carries the Bank's most recent bank hashes for some N parents
4//!
5pub use crate::slot_hashes::SlotHashes;
6
7use crate::{account_info::AccountInfo, program_error::ProgramError, sysvar::Sysvar};
8
9crate::declare_sysvar_id!("SysvarS1otHashes111111111111111111111111111", SlotHashes);
10
11impl Sysvar for SlotHashes {
12    // override
13    fn size_of() -> usize {
14        // hard-coded so that we don't have to construct an empty
15        20_488 // golden, update if MAX_ENTRIES changes
16    }
17    fn from_account_info(_account_info: &AccountInfo) -> Result<Self, ProgramError> {
18        // This sysvar is too large to bincode::deserialize in-program
19        Err(ProgramError::UnsupportedSysvar)
20    }
21}
22
23#[cfg(test)]
24mod tests {
25    use super::*;
26    use crate::{clock::Slot, hash::Hash, slot_hashes::MAX_ENTRIES};
27
28    #[test]
29    fn test_size_of() {
30        assert_eq!(
31            SlotHashes::size_of(),
32            bincode::serialized_size(
33                &(0..MAX_ENTRIES)
34                    .map(|slot| (slot as Slot, Hash::default()))
35                    .collect::<SlotHashes>()
36            )
37            .unwrap() as usize
38        );
39    }
40}