sablier_network_program/state/
config.rs1use anchor_lang::{prelude::*, AnchorDeserialize};
2
3use crate::constants::SEED_CONFIG;
4
5#[account(zero_copy)]
10#[derive(Debug, InitSpace)]
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#[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
36pub 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 AccountLoader<'_, Config> {
47 fn init(&mut self, admin: Pubkey, mint: Pubkey) -> Result<()> {
48 let mut config = self.load_init()?;
49 config.admin = admin;
50 config.mint = mint;
51 Ok(())
52 }
53
54 fn update(&mut self, settings: ConfigSettings) -> Result<()> {
55 let mut config = self.load_mut()?;
56 config.admin = settings.admin;
57 config.epoch_thread = settings.epoch_thread;
58 config.hasher_thread = settings.hasher_thread;
59 config.mint = settings.mint;
60 Ok(())
61 }
62}