sablier_network_program/state/
registry.rs1use std::{
2 collections::hash_map::DefaultHasher,
3 hash::{Hash, Hasher},
4};
5
6use anchor_lang::{prelude::*, AnchorDeserialize};
7
8use crate::constants::SEED_REGISTRY;
9
10#[account]
13#[derive(Debug, InitSpace)]
14pub struct Registry {
15 pub current_epoch: u64,
16 pub locked: bool,
17 pub nonce: u64,
18 pub total_pools: u64,
19 pub total_unstakes: u64,
20 pub total_workers: u64,
21 pub bump: u8,
22}
23
24impl Registry {
25 pub fn pubkey() -> Pubkey {
26 Pubkey::find_program_address(&[SEED_REGISTRY], &crate::ID).0
27 }
28}
29
30pub trait RegistryAccount {
35 fn init(&mut self, bump: u8) -> Result<()>;
36
37 fn hash_nonce(&mut self) -> Result<()>;
38}
39
40impl RegistryAccount for Account<'_, Registry> {
41 fn init(&mut self, bump: u8) -> Result<()> {
42 self.current_epoch = 0;
43 self.locked = false;
44 self.total_workers = 0;
45 self.bump = bump;
46 Ok(())
47 }
48
49 fn hash_nonce(&mut self) -> Result<()> {
50 let mut hasher = DefaultHasher::new();
51 Clock::get()?.slot.hash(&mut hasher);
52 self.nonce.hash(&mut hasher);
53 self.nonce = hasher.finish();
54 Ok(())
55 }
56}