mallow-auction-client 0.2.0

Codama-generated Rust client for the mallow_auction Anchor program.
Documentation
//! This code was AUTOGENERATED using the codama library.
//! Please DO NOT EDIT THIS FILE, instead use visitors
//! to add features, then rerun codama to update it.
//!
//! <https://github.com/codama-idl/codama>
//!

use solana_address::Address;
use crate::generated::types::FeeConfig;
use borsh::BorshSerialize;
use borsh::BorshDeserialize;


#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
pub struct MarketplaceConfig {
pub discriminator: [u8; 8],
pub bump: [u8; 1],
pub version: u8,
/// Pubkey of the marketplace authority's wallet.
pub marketplace_authority: Address,
/// Fee information for the marketplace.
pub fee_config: FeeConfig,
/// Rewards config to use for user rewards
pub rewards_config: Address,
}


pub const MARKETPLACE_CONFIG_DISCRIMINATOR: [u8; 8] = [169, 22, 247, 131, 182, 200, 81, 124];

impl MarketplaceConfig {
      pub const LEN: usize = 144;
  
          /// Prefix values used to generate a PDA for this account.
    ///
    /// Values are positional and appear in the following order:
    ///
                  ///   0. `MarketplaceConfig::PREFIX`
                                ///   1. marketplace_authority (`Address`)
                    pub const PREFIX: &'static [u8] = "marketplace_config".as_bytes();
      
      pub fn create_pda(
                                                                marketplace_authority: Address,
                                  bump: u8,
    ) -> Result<solana_address::Address, solana_address::error::AddressError> {
      solana_address::Address::create_program_address(
        &[
                                    "marketplace_config".as_bytes(),
                                                marketplace_authority.as_ref(),
                                &[bump],
        ],
        &crate::MALLOW_AUCTION_ID,
      )
    }

    pub fn find_pda(
                                                    marketplace_authority: &Address,
                          ) -> (solana_address::Address, u8) {
      solana_address::Address::find_program_address(
        &[
                                    "marketplace_config".as_bytes(),
                                                marketplace_authority.as_ref(),
                              ],
        &crate::MALLOW_AUCTION_ID,
      )
    }
  
  #[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 MarketplaceConfig {
  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_marketplace_config(
  rpc: &solana_rpc_client::rpc_client::RpcClient,
  address: &solana_address::Address,
) -> Result<crate::shared::DecodedAccount<MarketplaceConfig>, std::io::Error> {
  let accounts = fetch_all_marketplace_config(rpc, &[*address])?;
  Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_marketplace_config(
  rpc: &solana_rpc_client::rpc_client::RpcClient,
  addresses: &[solana_address::Address],
) -> Result<Vec<crate::shared::DecodedAccount<MarketplaceConfig>>, std::io::Error> {
    let accounts = rpc.get_multiple_accounts(addresses)
      .map_err(|e| std::io::Error::other(e.to_string()))?;
    let mut decoded_accounts: Vec<crate::shared::DecodedAccount<MarketplaceConfig>> = Vec::new();
    for i in 0..addresses.len() {
      let address = addresses[i];
      let account = accounts[i].as_ref()
        .ok_or(std::io::Error::other(format!("Account not found: {address}")))?;
      let data = MarketplaceConfig::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_marketplace_config(
  rpc: &solana_rpc_client::rpc_client::RpcClient,
  address: &solana_address::Address,
) -> Result<crate::shared::MaybeAccount<MarketplaceConfig>, std::io::Error> {
    let accounts = fetch_all_maybe_marketplace_config(rpc, &[*address])?;
    Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_maybe_marketplace_config(
  rpc: &solana_rpc_client::rpc_client::RpcClient,
  addresses: &[solana_address::Address],
) -> Result<Vec<crate::shared::MaybeAccount<MarketplaceConfig>>, std::io::Error> {
    let accounts = rpc.get_multiple_accounts(addresses)
      .map_err(|e| std::io::Error::other(e.to_string()))?;
    let mut decoded_accounts: Vec<crate::shared::MaybeAccount<MarketplaceConfig>> = Vec::new();
    for i in 0..addresses.len() {
      let address = addresses[i];
      if let Some(account) = accounts[i].as_ref() {
        let data = MarketplaceConfig::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 MarketplaceConfig {
      fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
        Ok(Self::deserialize(buf)?)
      }
  }

  #[cfg(feature = "anchor")]
  impl anchor_lang::AccountSerialize for MarketplaceConfig {}

  #[cfg(feature = "anchor")]
  impl anchor_lang::Owner for MarketplaceConfig {
      fn owner() -> anchor_lang::solana_program::pubkey::Pubkey {
        anchor_lang::solana_program::pubkey::Pubkey::from(
          crate::MALLOW_AUCTION_ID.to_bytes()
        )
      }
  }

  #[cfg(feature = "anchor-idl-build")]
  impl anchor_lang::IdlBuild for MarketplaceConfig {}

  
  #[cfg(feature = "anchor-idl-build")]
  impl anchor_lang::Discriminator for MarketplaceConfig {
    const DISCRIMINATOR: &[u8] = &[0; 8];
  }