atlas_config_program_client/generated/accounts/
config.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
7use {
8    crate::hooked::ConfigKeys,
9    borsh::{BorshDeserialize, BorshSerialize},
10    kaigan::types::RemainderVec,
11};
12
13#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
14#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
15pub struct Config {
16    /// List of pubkeys stored in the config account,
17    /// and whether each pubkey needs to sign subsequent calls to `store`.
18    pub keys: ConfigKeys,
19    /// Arbitrary data to store in the config account.
20    pub data: RemainderVec<u8>,
21}
22
23impl Config {
24    #[inline(always)]
25    pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
26        let mut data = data;
27        Self::deserialize(&mut data)
28    }
29}
30
31impl<'a> TryFrom<&crate::atlas_program::account_info::AccountInfo<'a>> for Config {
32    type Error = std::io::Error;
33
34    fn try_from(
35        account_info: &crate::atlas_program::account_info::AccountInfo<'a>,
36    ) -> Result<Self, Self::Error> {
37        let mut data: &[u8] = &(*account_info.data).borrow();
38        Self::deserialize(&mut data)
39    }
40}
41
42#[cfg(feature = "fetch")]
43pub fn fetch_config(
44    rpc: &crate::atlas_compat::crate::atlas_client::rpc_client::RpcClient,
45    address: &crate::atlas_program::pubkey::Pubkey,
46) -> Result<crate::shared::DecodedAccount<Config>, std::io::Error> {
47    let accounts = fetch_all_config(rpc, &[*address])?;
48    Ok(accounts[0].clone())
49}
50
51#[cfg(feature = "fetch")]
52pub fn fetch_all_config(
53    rpc: &crate::atlas_client::rpc_client::RpcClient,
54    addresses: &[crate::atlas_program::pubkey::Pubkey],
55) -> Result<Vec<crate::shared::DecodedAccount<Config>>, std::io::Error> {
56    let accounts = rpc
57        .get_multiple_accounts(addresses)
58        .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
59    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<Config>> = Vec::new();
60    for i in 0..addresses.len() {
61        let address = addresses[i];
62        let account = accounts[i].as_ref().ok_or(std::io::Error::new(
63            std::io::ErrorKind::Other,
64            format!("Account not found: {}", address),
65        ))?;
66        let data = Config::from_bytes(&account.data)?;
67        decoded_accounts.push(crate::shared::DecodedAccount {
68            address,
69            account: account.clone(),
70            data,
71        });
72    }
73    Ok(decoded_accounts)
74}
75
76#[cfg(feature = "fetch")]
77pub fn fetch_maybe_config(
78    rpc: &crate::atlas_client::rpc_client::RpcClient,
79    address: &crate::atlas_program::pubkey::Pubkey,
80) -> Result<crate::shared::MaybeAccount<Config>, std::io::Error> {
81    let accounts = fetch_all_maybe_config(rpc, &[*address])?;
82    Ok(accounts[0].clone())
83}
84
85#[cfg(feature = "fetch")]
86pub fn fetch_all_maybe_config(
87    rpc: &crate::atlas_client::rpc_client::RpcClient,
88    addresses: &[crate::atlas_program::pubkey::Pubkey],
89) -> Result<Vec<crate::shared::MaybeAccount<Config>>, std::io::Error> {
90    let accounts = rpc
91        .get_multiple_accounts(addresses)
92        .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
93    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<Config>> = Vec::new();
94    for i in 0..addresses.len() {
95        let address = addresses[i];
96        if let Some(account) = accounts[i].as_ref() {
97            let data = Config::from_bytes(&account.data)?;
98            decoded_accounts.push(crate::shared::MaybeAccount::Exists(
99                crate::shared::DecodedAccount {
100                    address,
101                    account: account.clone(),
102                    data,
103                },
104            ));
105        } else {
106            decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
107        }
108    }
109    Ok(decoded_accounts)
110}