commerce_program_client/generated/accounts/
merchant.rs

1//! This code was AUTOGENERATED using the codama library.
2//! Please DO NOT EDIT THIS FILE, instead use visitors
3//! to add features, then rerun codama to update it.
4//!
5//! <https://github.com/codama-idl/codama>
6//!
7
8use solana_pubkey::Pubkey;
9use borsh::BorshSerialize;
10use borsh::BorshDeserialize;
11
12
13#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15pub struct Merchant {
16pub discriminator: u8,
17#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
18pub owner: Pubkey,
19pub bump: u8,
20#[cfg_attr(feature = "serde", serde(with = "serde_with::As::<serde_with::DisplayFromStr>"))]
21pub settlement_wallet: Pubkey,
22}
23
24
25
26
27impl Merchant {
28      pub const LEN: usize = 66;
29  
30  
31  
32  #[inline(always)]
33  pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
34    let mut data = data;
35    Self::deserialize(&mut data)
36  }
37}
38
39impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for Merchant {
40  type Error = std::io::Error;
41
42  fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
43      let mut data: &[u8] = &(*account_info.data).borrow();
44      Self::deserialize(&mut data)
45  }
46}
47
48#[cfg(feature = "fetch")]
49pub fn fetch_merchant(
50  rpc: &solana_client::rpc_client::RpcClient,
51  address: &solana_pubkey::Pubkey,
52) -> Result<crate::shared::DecodedAccount<Merchant>, std::io::Error> {
53  let accounts = fetch_all_merchant(rpc, &[*address])?;
54  Ok(accounts[0].clone())
55}
56
57#[cfg(feature = "fetch")]
58pub fn fetch_all_merchant(
59  rpc: &solana_client::rpc_client::RpcClient,
60  addresses: &[solana_pubkey::Pubkey],
61) -> Result<Vec<crate::shared::DecodedAccount<Merchant>>, std::io::Error> {
62    let accounts = rpc.get_multiple_accounts(addresses)
63      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
64    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<Merchant>> = Vec::new();
65    for i in 0..addresses.len() {
66      let address = addresses[i];
67      let account = accounts[i].as_ref()
68        .ok_or(std::io::Error::new(std::io::ErrorKind::Other, format!("Account not found: {}", address)))?;
69      let data = Merchant::from_bytes(&account.data)?;
70      decoded_accounts.push(crate::shared::DecodedAccount { address, account: account.clone(), data });
71    }
72    Ok(decoded_accounts)
73}
74
75#[cfg(feature = "fetch")]
76pub fn fetch_maybe_merchant(
77  rpc: &solana_client::rpc_client::RpcClient,
78  address: &solana_pubkey::Pubkey,
79) -> Result<crate::shared::MaybeAccount<Merchant>, std::io::Error> {
80    let accounts = fetch_all_maybe_merchant(rpc, &[*address])?;
81    Ok(accounts[0].clone())
82}
83
84#[cfg(feature = "fetch")]
85pub fn fetch_all_maybe_merchant(
86  rpc: &solana_client::rpc_client::RpcClient,
87  addresses: &[solana_pubkey::Pubkey],
88) -> Result<Vec<crate::shared::MaybeAccount<Merchant>>, std::io::Error> {
89    let accounts = rpc.get_multiple_accounts(addresses)
90      .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
91    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<Merchant>> = Vec::new();
92    for i in 0..addresses.len() {
93      let address = addresses[i];
94      if let Some(account) = accounts[i].as_ref() {
95        let data = Merchant::from_bytes(&account.data)?;
96        decoded_accounts.push(crate::shared::MaybeAccount::Exists(crate::shared::DecodedAccount { address, account: account.clone(), data }));
97      } else {
98        decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
99      }
100    }
101  Ok(decoded_accounts)
102}
103
104  #[cfg(feature = "anchor")]
105  impl anchor_lang::AccountDeserialize for Merchant {
106      fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
107        Ok(Self::deserialize(buf)?)
108      }
109  }
110
111  #[cfg(feature = "anchor")]
112  impl anchor_lang::AccountSerialize for Merchant {}
113
114  #[cfg(feature = "anchor")]
115  impl anchor_lang::Owner for Merchant {
116      fn owner() -> Pubkey {
117        crate::COMMERCE_PROGRAM_ID
118      }
119  }
120
121  #[cfg(feature = "anchor-idl-build")]
122  impl anchor_lang::IdlBuild for Merchant {}
123
124  
125  #[cfg(feature = "anchor-idl-build")]
126  impl anchor_lang::Discriminator for Merchant {
127    const DISCRIMINATOR: &[u8] = &[0; 8];
128  }
129