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