satrush-client 0.1.14

Rust client to interact with SatRush's on-chain 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 borsh::BorshSerialize;
use borsh::BorshDeserialize;


#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
pub struct Affiliate {
pub discriminator: [u8; 8],
/// Struct version.
pub version: u16,
/// PDA bump seed.
pub bump: u8,
/// The affiliate's wallet; signs redemptions.
pub authority: Address,
/// The unique tag, zero-padded. The charset (`a-z0-9_-`) excludes NUL, so
/// the padding is unambiguous and no length field is needed.
pub tag: [u8; 16],
/// The affiliate's share of the protocol fee leg, in bps. Applies to
/// future accruals only; admin-adjustable (`set_affiliate_rate`).
pub rate_bps: u16,
/// Unclaimed points (USD base units, valued at accrual): credited by
/// referred deploys, debited by exchanges. Cumulative earned/spent totals
/// are tracked off-chain.
pub point_amount: u64,
/// Reserved.
pub reserved: [u8; 30],
}


pub const AFFILIATE_DISCRIMINATOR: [u8; 8] = [136, 95, 107, 149, 36, 195, 146, 35];

impl Affiliate {
      pub const LEN: usize = 99;
  
  
  
  #[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 Affiliate {
  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_affiliate(
  rpc: &solana_rpc_client::rpc_client::RpcClient,
  address: &solana_address::Address,
) -> Result<crate::shared::DecodedAccount<Affiliate>, std::io::Error> {
  let accounts = fetch_all_affiliate(rpc, &[*address])?;
  Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_affiliate(
  rpc: &solana_rpc_client::rpc_client::RpcClient,
  addresses: &[solana_address::Address],
) -> Result<Vec<crate::shared::DecodedAccount<Affiliate>>, 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<Affiliate>> = 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 = Affiliate::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_affiliate(
  rpc: &solana_rpc_client::rpc_client::RpcClient,
  address: &solana_address::Address,
) -> Result<crate::shared::MaybeAccount<Affiliate>, std::io::Error> {
    let accounts = fetch_all_maybe_affiliate(rpc, &[*address])?;
    Ok(accounts[0].clone())
}

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

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

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

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

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