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