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#[derive(BorshSerialize, BorshDeserialize)]
14pub enum SyncInstruction {
15 V0(SyncRecordV0),
16}
17
18impl SyncInstruction {
19 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 pub fn identity(&self) -> &Pubkey {
27 match self {
28 Self::V0(r) => &r.identity,
29 }
30 }
31
32 pub fn addr(&mut self) -> &mut Option<String> {
34 match self {
35 Self::V0(v) => &mut v.addr,
36 }
37 }
38
39 pub fn base_fee(&mut self) -> &mut Option<u16> {
41 match self {
42 Self::V0(v) => &mut v.base_fee,
43 }
44 }
45
46 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 pub fn features(&mut self) -> &mut Option<FeaturesSet> {
55 match self {
56 Self::V0(v) => &mut v.features,
57 }
58 }
59
60 pub fn status(&mut self) -> &mut Option<ErStatus> {
62 match self {
63 Self::V0(v) => &mut v.status,
64 }
65 }
66
67 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}