use crate::generated::types::AccountDiscriminator;
use crate::generated::types::ProgramAuthority;
use borsh::BorshDeserialize;
use borsh::BorshSerialize;
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct AuthorityConfig {
pub discriminator: AccountDiscriminator,
#[cfg_attr(feature = "serde", serde(with = "serde_big_array::BigArray"))]
pub authorities: [ProgramAuthority; 64],
}
pub const AUTHORITY_CONFIG_DISCRIMINATOR: AccountDiscriminator =
AccountDiscriminator::AuthorityConfig;
impl AuthorityConfig {
pub const LEN: usize = 4097;
#[inline(always)]
pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
let mut data = data;
Self::deserialize(&mut data)
}
}
impl<'a> TryFrom<&solana_account_info::AccountInfo<'a>> for AuthorityConfig {
type Error = std::io::Error;
fn try_from(account_info: &solana_account_info::AccountInfo<'a>) -> Result<Self, Self::Error> {
let mut data: &[u8] = &(*account_info.data).borrow();
Self::deserialize(&mut data)
}
}
#[cfg(feature = "fetch")]
pub fn fetch_authority_config(
rpc: &solana_client::rpc_client::RpcClient,
address: &solana_pubkey::Pubkey,
) -> Result<crate::shared::DecodedAccount<AuthorityConfig>, std::io::Error> {
let accounts = fetch_all_authority_config(rpc, &[*address])?;
Ok(accounts[0].clone())
}
#[cfg(feature = "fetch")]
pub fn fetch_all_authority_config(
rpc: &solana_client::rpc_client::RpcClient,
addresses: &[solana_pubkey::Pubkey],
) -> Result<Vec<crate::shared::DecodedAccount<AuthorityConfig>>, std::io::Error> {
let accounts = rpc
.get_multiple_accounts(addresses)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
let mut decoded_accounts: Vec<crate::shared::DecodedAccount<AuthorityConfig>> = Vec::new();
for i in 0..addresses.len() {
let address = addresses[i];
let account = accounts[i].as_ref().ok_or(std::io::Error::new(
std::io::ErrorKind::Other,
format!("Account not found: {}", address),
))?;
let data = AuthorityConfig::from_bytes(&account.data)?;
decoded_accounts.push(crate::shared::DecodedAccount {
address,
account: account.clone(),
data,
});
}
Ok(decoded_accounts)
}
#[cfg(feature = "fetch")]
pub fn fetch_maybe_authority_config(
rpc: &solana_client::rpc_client::RpcClient,
address: &solana_pubkey::Pubkey,
) -> Result<crate::shared::MaybeAccount<AuthorityConfig>, std::io::Error> {
let accounts = fetch_all_maybe_authority_config(rpc, &[*address])?;
Ok(accounts[0].clone())
}
#[cfg(feature = "fetch")]
pub fn fetch_all_maybe_authority_config(
rpc: &solana_client::rpc_client::RpcClient,
addresses: &[solana_pubkey::Pubkey],
) -> Result<Vec<crate::shared::MaybeAccount<AuthorityConfig>>, std::io::Error> {
let accounts = rpc
.get_multiple_accounts(addresses)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
let mut decoded_accounts: Vec<crate::shared::MaybeAccount<AuthorityConfig>> = Vec::new();
for i in 0..addresses.len() {
let address = addresses[i];
if let Some(account) = accounts[i].as_ref() {
let data = AuthorityConfig::from_bytes(&account.data)?;
decoded_accounts.push(crate::shared::MaybeAccount::Exists(
crate::shared::DecodedAccount {
address,
account: account.clone(),
data,
},
));
} else {
decoded_accounts.push(crate::shared::MaybeAccount::NotFound(address));
}
}
Ok(decoded_accounts)
}
#[cfg(feature = "anchor")]
impl anchor_lang::AccountDeserialize for AuthorityConfig {
fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
Ok(Self::deserialize(buf)?)
}
}
#[cfg(feature = "anchor")]
impl anchor_lang::AccountSerialize for AuthorityConfig {}
#[cfg(feature = "anchor")]
impl anchor_lang::Owner for AuthorityConfig {
fn owner() -> Pubkey {
crate::WAVEBREAK_ID
}
}
#[cfg(feature = "anchor-idl-build")]
impl anchor_lang::IdlBuild for AuthorityConfig {}
#[cfg(feature = "anchor-idl-build")]
impl anchor_lang::Discriminator for AuthorityConfig {
const DISCRIMINATOR: &[u8] = &[0; 8];
}