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