mdp/instructions/
sync.rs

1use borsh::{BorshDeserialize, BorshSerialize};
2use solana_program::pubkey::Pubkey;
3
4use crate::{
5    consts::ER_RECORD_SEED,
6    state::{features::FeaturesSet, record::CountryCode, status::ErStatus},
7    ID,
8};
9
10use super::version::v0::SyncRecordV0;
11
12/// Versioned sync program instruction
13#[derive(BorshSerialize, BorshDeserialize)]
14pub enum SyncInstruction {
15    V0(SyncRecordV0),
16}
17
18impl SyncInstruction {
19    /// Compute the record PDA for given ER node identity
20    pub fn pda(&self) -> Pubkey {
21        let seeds = [ER_RECORD_SEED, self.identity().as_ref()];
22        Pubkey::find_program_address(&seeds, &ID).0
23    }
24
25    /// Returns identity pubkey of the ER node
26    pub fn identity(&self) -> &Pubkey {
27        match self {
28            Self::V0(r) => &r.identity,
29        }
30    }
31
32    /// Returns address of the ER node, if set
33    pub fn addr(&mut self) -> &mut Option<String> {
34        match self {
35            Self::V0(v) => &mut v.addr,
36        }
37    }
38
39    /// Returns base transaction fee charged by ER node, if set
40    pub fn base_fee(&mut self) -> &mut Option<u16> {
41        match self {
42            Self::V0(v) => &mut v.base_fee,
43        }
44    }
45
46    /// Returns the block time in ms of the given ER node, if set
47    pub fn block_time_ms(&mut self) -> &mut Option<u16> {
48        match self {
49            Self::V0(v) => &mut v.block_time_ms,
50        }
51    }
52
53    /// Returns the features set supported by ER node, if set
54    pub fn features(&mut self) -> &mut Option<FeaturesSet> {
55        match self {
56            Self::V0(v) => &mut v.features,
57        }
58    }
59
60    /// Returns the status of ER node, if set
61    pub fn status(&mut self) -> &mut Option<ErStatus> {
62        match self {
63            Self::V0(v) => &mut v.status,
64        }
65    }
66
67    /// Returns last observed average load on the given ER node, if set
68    pub fn load_average(&mut self) -> &mut Option<u32> {
69        match self {
70            Self::V0(v) => &mut v.load_average,
71        }
72    }
73
74    pub fn country_code(&mut self) -> &mut Option<CountryCode> {
75        match self {
76            Self::V0(v) => &mut v.country_code,
77        }
78    }
79}