miclockwork_network_program/state/
config.rs

1use anchor_lang::{prelude::*, AnchorDeserialize};
2
3pub const SEED_CONFIG: &[u8] = b"config";
4
5/**
6 * Config
7 */
8
9#[account]
10#[derive(Debug)]
11pub struct Config {
12    pub admin: Pubkey,
13    pub epoch_thread: Pubkey,
14    pub hasher_thread: Pubkey,
15    pub mint: Pubkey,
16}
17
18impl Config {
19    pub fn pubkey() -> Pubkey {
20        Pubkey::find_program_address(&[SEED_CONFIG], &crate::ID).0
21    }
22}
23
24/**
25 * ConfigSettings
26 */
27
28#[derive(AnchorSerialize, AnchorDeserialize)]
29pub struct ConfigSettings {
30    pub admin: Pubkey,
31    pub epoch_thread: Pubkey,
32    pub hasher_thread: Pubkey,
33    pub mint: Pubkey,
34}
35
36/**
37 * ConfigAccount
38 */
39
40pub trait ConfigAccount {
41    fn init(&mut self, admin: Pubkey, mint: Pubkey) -> Result<()>;
42
43    fn update(&mut self, settings: ConfigSettings) -> Result<()>;
44}
45
46impl ConfigAccount for Account<'_, Config> {
47    fn init(&mut self, admin: Pubkey, mint: Pubkey) -> Result<()> {
48        self.admin = admin;
49        self.mint = mint;
50        Ok(())
51    }
52
53    fn update(&mut self, settings: ConfigSettings) -> Result<()> {
54        self.admin = settings.admin;
55        self.epoch_thread = settings.epoch_thread;
56        self.hasher_thread = settings.hasher_thread;
57        self.mint = settings.mint;
58        Ok(())
59    }
60}