commerce_program_client/generated/accounts/
merchant_operator_config.rs1use solana_pubkey::Pubkey;
9use crate::generated::types::FeeType;
10use borsh::BorshSerialize;
11use borsh::BorshDeserialize;
12
13
14#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
15#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16pub struct MerchantOperatorConfig {
17pub discriminator: u8,
18pub version: u32,
19pub bump: u8,
20#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
21pub merchant: Pubkey,
22#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
23pub operator: Pubkey,
24pub operator_fee: u64,
25pub fee_type: FeeType,
26pub current_order_id: u32,
27pub days_to_close: u16,
28pub num_policies: u32,
29pub num_accepted_currencies: u32,
30}
31
32
33
34
35impl MerchantOperatorConfig {
36 pub const LEN: usize = 93;
37
38
39
40 #[inline(always)]
41 pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
42 let mut data = data;
43 Self::deserialize(&mut data)
44 }
45}
46
47impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for MerchantOperatorConfig {
48 type Error = std::io::Error;
49
50 fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
51 let mut data: &[u8] = &(*account_info.data).borrow();
52 Self::deserialize(&mut data)
53 }
54}
55
56#[cfg(feature = "fetch")]
57pub fn fetch_merchant_operator_config(
58 rpc: &solana_client::rpc_client::RpcClient,
59 address: &solana_pubkey::Pubkey,
60) -> Result<crate::shared::DecodedAccount<MerchantOperatorConfig>, std::io::Error> {
61 let accounts = fetch_all_merchant_operator_config(rpc, &[*address])?;
62 Ok(accounts[0].clone())
63}
64
65#[cfg(feature = "fetch")]
66pub fn fetch_all_merchant_operator_config(
67 rpc: &solana_client::rpc_client::RpcClient,
68 addresses: &[solana_pubkey::Pubkey],
69) -> Result<Vec<crate::shared::DecodedAccount<MerchantOperatorConfig>>, std::io::Error> {
70 let accounts = rpc.get_multiple_accounts(addresses)
71 .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
72 let mut decoded_accounts: Vec<crate::shared::DecodedAccount<MerchantOperatorConfig>> = Vec::new();
73 for i in 0..addresses.len() {
74 let address = addresses[i];
75 let account = accounts[i].as_ref()
76 .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?;
77 let data = MerchantOperatorConfig::from_bytes(&account.data)?;
78 decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
79 }
80 Ok(decoded_accounts)
81}
82
83#[cfg(feature = "fetch")]
84pub fn fetch_maybe_merchant_operator_config(
85 rpc: &solana_client::rpc_client::RpcClient,
86 address: &solana_pubkey::Pubkey,
87) -> Result<crate::shared::MaybeAccount<MerchantOperatorConfig>, std::io::Error> {
88 let accounts = fetch_all_maybe_merchant_operator_config(rpc, &[*address])?;
89 Ok(accounts[0].clone())
90}
91
92#[cfg(feature = "fetch")]
93pub fn fetch_all_maybe_merchant_operator_config(
94 rpc: &solana_client::rpc_client::RpcClient,
95 addresses: &[solana_pubkey::Pubkey],
96) -> Result<Vec<crate::shared::MaybeAccount<MerchantOperatorConfig>>, std::io::Error> {
97 let accounts = rpc.get_multiple_accounts(addresses)
98 .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
99 let mut decoded_accounts: Vec<crate::shared::MaybeAccount<MerchantOperatorConfig>> = Vec::new();
100 for i in 0..addresses.len() {
101 let address = addresses[i];
102 if let Some(account) = accounts[i].as_ref() {
103 let data = MerchantOperatorConfig::from_bytes(&account.data)?;
104 decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
105 } else {
106 decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
107 }
108 }
109 Ok(decoded_accounts)
110}
111
112 #[cfg(feature = "anchor")]
113 impl anchor_lang::AccountDeserialize for MerchantOperatorConfig {
114 fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
115 Ok(Self::deserialize(buf)?)
116 }
117 }
118
119 #[cfg(feature = "anchor")]
120 impl anchor_lang::AccountSerialize for MerchantOperatorConfig {}
121
122 #[cfg(feature = "anchor")]
123 impl anchor_lang::Owner for MerchantOperatorConfig {
124 fn owner() -> Pubkey {
125 crate::COMMERCE_PROGRAM_ID
126 }
127 }
128
129 #[cfg(feature = "anchor-idl-build")]
130 impl anchor_lang::IdlBuild for MerchantOperatorConfig {}
131
132
133 #[cfg(feature = "anchor-idl-build")]
134 impl anchor_lang::Discriminator for MerchantOperatorConfig {
135 const DISCRIMINATOR: &[u8] = &[0; 8];
136 }
137