Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions program/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ dist/
/tests/integration-tests/deps

# Codama generated clients
/clients/rust/src/generated/*
/clients/typescript/src/generated/*
# We'll check in the generated clients to make publishing to crates.io easier
#/clients/rust/src/generated/*
#/clients/typescript/src/generated/*

# Local test validator
*test-ledger*
141 changes: 141 additions & 0 deletions program/clients/rust/src/generated/accounts/merchant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
//! 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 borsh::BorshDeserialize;
use borsh::BorshSerialize;
use solana_pubkey::Pubkey;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Merchant {
pub discriminator: u8,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub owner: Pubkey,
pub bump: u8,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub settlement_wallet: Pubkey,
}

impl Merchant {
pub const LEN: usize = 66;

#[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 Merchant {
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_merchant(
rpc: &solana_client::rpc_client::RpcClient,
address: &solana_pubkey::Pubkey,
) -> Result<crate::shared::DecodedAccount<Merchant>, std::io::Error> {
let accounts = fetch_all_merchant(rpc, &[*address])?;
Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_merchant(
rpc: &solana_client::rpc_client::RpcClient,
addresses: &[solana_pubkey::Pubkey],
) -> Result<Vec<crate::shared::DecodedAccount<Merchant>>, 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<Merchant>> = 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 = Merchant::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_merchant(
rpc: &solana_client::rpc_client::RpcClient,
address: &solana_pubkey::Pubkey,
) -> Result<crate::shared::MaybeAccount<Merchant>, std::io::Error> {
let accounts = fetch_all_maybe_merchant(rpc, &[*address])?;
Ok(accounts[0].clone())
}

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

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

#[cfg(feature = "anchor")]
impl anchor_lang::Owner for Merchant {
fn owner() -> Pubkey {
crate::COMMERCE_PROGRAM_ID
}
}

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

#[cfg(feature = "anchor-idl-build")]
impl anchor_lang::Discriminator for Merchant {
const DISCRIMINATOR: &[u8] = &[0; 8];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
//! 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 crate::generated::types::FeeType;
use borsh::BorshDeserialize;
use borsh::BorshSerialize;
use solana_pubkey::Pubkey;

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct MerchantOperatorConfig {
pub discriminator: u8,
pub version: u32,
pub bump: u8,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub merchant: Pubkey,
#[cfg_attr(
feature = "serde",
serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
)]
pub operator: Pubkey,
pub operator_fee: u64,
pub fee_type: FeeType,
pub current_order_id: u32,
pub days_to_close: u16,
pub num_policies: u32,
pub num_accepted_currencies: u32,
}

impl MerchantOperatorConfig {
pub const LEN: usize = 93;

#[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 MerchantOperatorConfig {
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_merchant_operator_config(
rpc: &solana_client::rpc_client::RpcClient,
address: &solana_pubkey::Pubkey,
) -> Result<crate::shared::DecodedAccount<MerchantOperatorConfig>, std::io::Error> {
let accounts = fetch_all_merchant_operator_config(rpc, &[*address])?;
Ok(accounts[0].clone())
}

#[cfg(feature = "fetch")]
pub fn fetch_all_merchant_operator_config(
rpc: &solana_client::rpc_client::RpcClient,
addresses: &[solana_pubkey::Pubkey],
) -> Result<Vec<crate::shared::DecodedAccount<MerchantOperatorConfig>>, 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<MerchantOperatorConfig>> =
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 = MerchantOperatorConfig::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_merchant_operator_config(
rpc: &solana_client::rpc_client::RpcClient,
address: &solana_pubkey::Pubkey,
) -> Result<crate::shared::MaybeAccount<MerchantOperatorConfig>, std::io::Error> {
let accounts = fetch_all_maybe_merchant_operator_config(rpc, &[*address])?;
Ok(accounts[0].clone())
}

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

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

#[cfg(feature = "anchor")]
impl anchor_lang::Owner for MerchantOperatorConfig {
fn owner() -> Pubkey {
crate::COMMERCE_PROGRAM_ID
}
}

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

#[cfg(feature = "anchor-idl-build")]
impl anchor_lang::Discriminator for MerchantOperatorConfig {
const DISCRIMINATOR: &[u8] = &[0; 8];
}
16 changes: 16 additions & 0 deletions program/clients/rust/src/generated/accounts/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//! 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>
//!

pub(crate) mod r#merchant;
pub(crate) mod r#merchant_operator_config;
pub(crate) mod r#operator;
pub(crate) mod r#payment;

pub use self::r#merchant::*;
pub use self::r#merchant_operator_config::*;
pub use self::r#operator::*;
pub use self::r#payment::*;
Loading