@@ -128,6 +128,59 @@ impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for {{ account.
128128 }
129129}
130130
131+ #[cfg(feature = "fetch")]
132+ pub fn fetch_{{ account .name | snakeCase }} (
133+ rpc: &solana_client::rpc_client::RpcClient,
134+ address: &Pubkey,
135+ ) -> Result<super::DecodedAccount <{{ account.name | pascalCase }} >, Error> {
136+ let accounts = fetch_all_{{ account .name | snakeCase }} (rpc, vec![address])?;
137+ Ok(accounts[0].clone())
138+ }
139+
140+ #[cfg(feature = "fetch")]
141+ pub fn fetch_all_{{ account .name | snakeCase }} (
142+ rpc: &solana_client::rpc_client::RpcClient,
143+ addresses: Vec<Pubkey >,
144+ ) -> Result<Vec <super::DecodedAccount <{{ account.name | pascalCase }} >>, Error> {
145+ let accounts = rpc.get_multiple_accounts(&addresses)?;
146+ let mut decoded_accounts: Vec<super::DecodedAccount <{{ account.name | pascalCase }} >> = Vec::new();
147+ for i in 0..addresses.len() {
148+ let address = addresses[i];
149+ let account = accounts[i].as_ref().ok_or(format!("Account not found: {}", address))?;
150+ let data = {{ account .name | pascalCase }} ::from_bytes(&account.data)?;
151+ decoded_accounts.push(super::DecodedAccount { address, account: account.clone(), data });
152+ }
153+ Ok(decoded_accounts)
154+ }
155+
156+ #[cfg(feature = "fetch")]
157+ pub fn fetch_maybe_{{ account .name | snakeCase }} (
158+ rpc: &solana_client::rpc_client::RpcClient,
159+ address: &Pubkey,
160+ ) -> Result<super::MaybeAccount <{{ account.name | pascalCase }} >, Error> {
161+ let accounts = fetch_all_maybe_{{ account .name | snakeCase }} (rpc, vec![address])?;
162+ Ok(accounts[0].clone())
163+ }
164+
165+ #[cfg(feature = "fetch")]
166+ pub fn fetch_all_maybe_{{ account .name | snakeCase }} (
167+ rpc: &solana_client::rpc_client::RpcClient,
168+ addresses: Vec<Pubkey >,
169+ ) -> Result<Vec <super::MaybeAccount <{{ account.name | pascalCase }} >>, Error> {
170+ let accounts = rpc.get_multiple_accounts(&addresses)?;
171+ let mut decoded_accounts: Vec<super::MaybeAccount <{{ account.name | pascalCase }} >> = Vec::new();
172+ for i in 0..addresses.len() {
173+ let address = addresses[i];
174+ if let Some(account) = accounts[i].as_ref() {
175+ let data = {{ account .name | pascalCase }} ::from_bytes(&account.data)?;
176+ decoded_accounts.push(super::MaybeAccount::Exists(super::DecodedAccount { address, account: account.clone(), data }));
177+ } else {
178+ decoded_accounts.push(super::MaybeAccount::NotFound(address));
179+ }
180+ }
181+ Ok(decoded_accounts)
182+ }
183+
131184#[cfg(feature = "anchor")]
132185impl anchor_lang::AccountDeserialize for {{ account .name | pascalCase }} {
133186 fn try_deserialize_unchecked(buf: &mut & [u8]) -> anchor_lang::Result<Self > {
0 commit comments