2019-05-21 15:19:41 -07:00
|
|
|
//! named accounts for synthesized data accounts for bank state, etc.
|
|
|
|
//!
|
|
|
|
//! this account carries the Bank's most recent blockhashes for some N parents
|
|
|
|
//!
|
2019-10-08 22:34:26 -07:00
|
|
|
pub use crate::slot_hashes::{SlotHash, SlotHashes};
|
2019-11-04 12:31:24 -08:00
|
|
|
use crate::{account::Account, sysvar::Sysvar};
|
2019-06-21 20:43:24 -07:00
|
|
|
|
2019-05-22 19:07:56 -07:00
|
|
|
const ID: [u8; 32] = [
|
2019-07-12 19:08:51 -07:00
|
|
|
6, 167, 213, 23, 25, 47, 10, 175, 198, 242, 101, 227, 251, 119, 204, 122, 218, 130, 197, 41,
|
|
|
|
208, 190, 59, 19, 110, 45, 0, 85, 32, 0, 0, 0,
|
2019-05-21 15:19:41 -07:00
|
|
|
];
|
|
|
|
|
2019-11-04 12:31:24 -08:00
|
|
|
crate::solana_sysvar_id!(
|
|
|
|
ID,
|
|
|
|
"SysvarS1otHashes111111111111111111111111111",
|
|
|
|
SlotHashes
|
|
|
|
);
|
2019-05-21 21:45:38 -07:00
|
|
|
|
2019-05-22 19:07:56 -07:00
|
|
|
pub const MAX_SLOT_HASHES: usize = 512; // 512 slots to get your vote in
|
|
|
|
|
2019-11-04 12:31:24 -08:00
|
|
|
impl Sysvar for SlotHashes {
|
|
|
|
fn biggest() -> Self {
|
|
|
|
// override
|
|
|
|
SlotHashes::new(&[SlotHash::default(); MAX_SLOT_HASHES])
|
2019-05-21 15:19:41 -07:00
|
|
|
}
|
|
|
|
}
|
2019-05-22 19:07:56 -07:00
|
|
|
|
2019-09-08 11:13:59 -07:00
|
|
|
pub fn create_account(lamports: u64, slot_hashes: &[SlotHash]) -> Account {
|
2019-11-04 12:31:24 -08:00
|
|
|
SlotHashes::new(slot_hashes).create_account(lamports)
|
2019-05-21 15:19:41 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2019-05-22 19:07:56 -07:00
|
|
|
|
|
|
|
#[test]
|
2019-05-29 10:08:03 -07:00
|
|
|
fn test_create_account() {
|
2019-05-22 19:07:56 -07:00
|
|
|
let lamports = 42;
|
2019-06-21 20:43:24 -07:00
|
|
|
let account = create_account(lamports, &[]);
|
|
|
|
assert_eq!(account.data.len(), SlotHashes::size_of());
|
2019-09-10 18:53:02 -07:00
|
|
|
let slot_hashes = SlotHashes::from_account(&account);
|
2019-10-08 22:34:26 -07:00
|
|
|
assert_eq!(slot_hashes, Some(SlotHashes::default()));
|
2019-05-21 15:19:41 -07:00
|
|
|
}
|
|
|
|
}
|