miclockwork_network_program/state/
snapshot.rs1use anchor_lang::{prelude::*, AnchorDeserialize};
2
3pub const SEED_SNAPSHOT: &[u8] = b"snapshot";
4
5#[account]
7#[derive(Debug)]
8pub struct Snapshot {
9 pub id: u64,
10 pub total_frames: u64,
11 pub total_stake: u64,
12}
13
14impl Snapshot {
15 pub fn pubkey(id: u64) -> Pubkey {
16 Pubkey::find_program_address(&[SEED_SNAPSHOT, id.to_be_bytes().as_ref()], &crate::ID).0
17 }
18}
19
20pub trait SnapshotAccount {
22 fn pubkey(&self) -> Pubkey;
23
24 fn init(&mut self, id: u64) -> Result<()>;
25}
26
27impl SnapshotAccount for Account<'_, Snapshot> {
28 fn pubkey(&self) -> Pubkey {
29 Snapshot::pubkey(self.id)
30 }
31
32 fn init(&mut self, id: u64) -> Result<()> {
33 self.id = id;
34 self.total_frames = 0;
35 self.total_stake = 0;
36 Ok(())
37 }
38}