miclockwork_network_program/state/
snapshot_entry.rs1use anchor_lang::{prelude::*, AnchorDeserialize};
2
3pub const SEED_SNAPSHOT_ENTRY: &[u8] = b"snapshot_entry";
4
5#[account]
10#[derive(Debug)]
11pub struct SnapshotEntry {
12 pub delegation: Pubkey,
13 pub id: u64,
14 pub snapshot_frame: Pubkey,
15 pub stake_amount: u64,
16}
17
18impl SnapshotEntry {
19 pub fn pubkey(snapshot_frame: Pubkey, id: u64) -> Pubkey {
20 Pubkey::find_program_address(
21 &[
22 SEED_SNAPSHOT_ENTRY,
23 snapshot_frame.as_ref(),
24 id.to_be_bytes().as_ref(),
25 ],
26 &crate::ID,
27 )
28 .0
29 }
30}
31
32pub trait SnapshotEntryAccount {
37 fn pubkey(&self) -> Pubkey;
38
39 fn init(
40 &mut self,
41 delegation: Pubkey,
42 id: u64,
43 snapshot_frame: Pubkey,
44 stake_amount: u64,
45 ) -> Result<()>;
46}
47
48impl SnapshotEntryAccount for Account<'_, SnapshotEntry> {
49 fn pubkey(&self) -> Pubkey {
50 SnapshotEntry::pubkey(self.snapshot_frame, self.id)
51 }
52
53 fn init(
54 &mut self,
55 delegation: Pubkey,
56 id: u64,
57 snapshot_frame: Pubkey,
58 stake_amount: u64,
59 ) -> Result<()> {
60 self.delegation = delegation;
61 self.id = id;
62 self.snapshot_frame = snapshot_frame;
63 self.stake_amount = stake_amount;
64 Ok(())
65 }
66}