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