use borsh::BorshDeserialize;
use borsh::BorshSerialize;
pub struct WithdrawSubsidy {
pub distribution: solana_program::pubkey::Pubkey,
pub recipient: Option<solana_program::pubkey::Pubkey>,
pub payer: solana_program::pubkey::Pubkey,
pub authority: Option<solana_program::pubkey::Pubkey>,
}
impl WithdrawSubsidy {
pub fn instruction(
&self,
args: WithdrawSubsidyInstructionArgs,
) -> solana_program::instruction::Instruction {
self.instruction_with_remaining_accounts(args, &[])
}
#[allow(clippy::vec_init_then_push)]
pub fn instruction_with_remaining_accounts(
&self,
args: WithdrawSubsidyInstructionArgs,
remaining_accounts: &[solana_program::instruction::AccountMeta],
) -> solana_program::instruction::Instruction {
let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new(
self.distribution,
false,
));
if let Some(recipient) = self.recipient {
accounts.push(solana_program::instruction::AccountMeta::new(
recipient, false,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_DISTRO_ID,
false,
));
}
accounts.push(solana_program::instruction::AccountMeta::new(
self.payer, true,
));
if let Some(authority) = self.authority {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
authority, true,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_DISTRO_ID,
false,
));
}
accounts.extend_from_slice(remaining_accounts);
let mut data = WithdrawSubsidyInstructionData::new().try_to_vec().unwrap();
let mut args = args.try_to_vec().unwrap();
data.append(&mut args);
solana_program::instruction::Instruction {
program_id: crate::MPL_DISTRO_ID,
accounts,
data,
}
}
}
#[derive(BorshDeserialize, BorshSerialize)]
struct WithdrawSubsidyInstructionData {
discriminator: u8,
}
impl WithdrawSubsidyInstructionData {
fn new() -> Self {
Self { discriminator: 6 }
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct WithdrawSubsidyInstructionArgs {
pub amount: u64,
}
#[derive(Default)]
pub struct WithdrawSubsidyBuilder {
distribution: Option<solana_program::pubkey::Pubkey>,
recipient: Option<solana_program::pubkey::Pubkey>,
payer: Option<solana_program::pubkey::Pubkey>,
authority: Option<solana_program::pubkey::Pubkey>,
amount: Option<u64>,
__remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
}
impl WithdrawSubsidyBuilder {
pub fn new() -> Self {
Self::default()
}
#[inline(always)]
pub fn distribution(&mut self, distribution: solana_program::pubkey::Pubkey) -> &mut Self {
self.distribution = Some(distribution);
self
}
#[inline(always)]
pub fn recipient(&mut self, recipient: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
self.recipient = recipient;
self
}
#[inline(always)]
pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
self.payer = Some(payer);
self
}
#[inline(always)]
pub fn authority(&mut self, authority: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
self.authority = authority;
self
}
#[inline(always)]
pub fn amount(&mut self, amount: u64) -> &mut Self {
self.amount = Some(amount);
self
}
#[inline(always)]
pub fn add_remaining_account(
&mut self,
account: solana_program::instruction::AccountMeta,
) -> &mut Self {
self.__remaining_accounts.push(account);
self
}
#[inline(always)]
pub fn add_remaining_accounts(
&mut self,
accounts: &[solana_program::instruction::AccountMeta],
) -> &mut Self {
self.__remaining_accounts.extend_from_slice(accounts);
self
}
#[allow(clippy::clone_on_copy)]
pub fn instruction(&self) -> solana_program::instruction::Instruction {
let accounts = WithdrawSubsidy {
distribution: self.distribution.expect("distribution is not set"),
recipient: self.recipient,
payer: self.payer.expect("payer is not set"),
authority: self.authority,
};
let args = WithdrawSubsidyInstructionArgs {
amount: self.amount.clone().expect("amount is not set"),
};
accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
}
}
pub struct WithdrawSubsidyCpiAccounts<'a, 'b> {
pub distribution: &'b solana_program::account_info::AccountInfo<'a>,
pub recipient: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub payer: &'b solana_program::account_info::AccountInfo<'a>,
pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
}
pub struct WithdrawSubsidyCpi<'a, 'b> {
pub __program: &'b solana_program::account_info::AccountInfo<'a>,
pub distribution: &'b solana_program::account_info::AccountInfo<'a>,
pub recipient: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub payer: &'b solana_program::account_info::AccountInfo<'a>,
pub authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub __args: WithdrawSubsidyInstructionArgs,
}
impl<'a, 'b> WithdrawSubsidyCpi<'a, 'b> {
pub fn new(
program: &'b solana_program::account_info::AccountInfo<'a>,
accounts: WithdrawSubsidyCpiAccounts<'a, 'b>,
args: WithdrawSubsidyInstructionArgs,
) -> Self {
Self {
__program: program,
distribution: accounts.distribution,
recipient: accounts.recipient,
payer: accounts.payer,
authority: accounts.authority,
__args: args,
}
}
#[inline(always)]
pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
self.invoke_signed_with_remaining_accounts(&[], &[])
}
#[inline(always)]
pub fn invoke_with_remaining_accounts(
&self,
remaining_accounts: &[(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)],
) -> solana_program::entrypoint::ProgramResult {
self.invoke_signed_with_remaining_accounts(&[], remaining_accounts)
}
#[inline(always)]
pub fn invoke_signed(
&self,
signers_seeds: &[&[&[u8]]],
) -> solana_program::entrypoint::ProgramResult {
self.invoke_signed_with_remaining_accounts(signers_seeds, &[])
}
#[allow(clippy::clone_on_copy)]
#[allow(clippy::vec_init_then_push)]
pub fn invoke_signed_with_remaining_accounts(
&self,
signers_seeds: &[&[&[u8]]],
remaining_accounts: &[(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)],
) -> solana_program::entrypoint::ProgramResult {
let mut accounts = Vec::with_capacity(4 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new(
*self.distribution.key,
false,
));
if let Some(recipient) = self.recipient {
accounts.push(solana_program::instruction::AccountMeta::new(
*recipient.key,
false,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_DISTRO_ID,
false,
));
}
accounts.push(solana_program::instruction::AccountMeta::new(
*self.payer.key,
true,
));
if let Some(authority) = self.authority {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*authority.key,
true,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_DISTRO_ID,
false,
));
}
remaining_accounts.iter().for_each(|remaining_account| {
accounts.push(solana_program::instruction::AccountMeta {
pubkey: *remaining_account.0.key,
is_signer: remaining_account.1,
is_writable: remaining_account.2,
})
});
let mut data = WithdrawSubsidyInstructionData::new().try_to_vec().unwrap();
let mut args = self.__args.try_to_vec().unwrap();
data.append(&mut args);
let instruction = solana_program::instruction::Instruction {
program_id: crate::MPL_DISTRO_ID,
accounts,
data,
};
let mut account_infos = Vec::with_capacity(4 + 1 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.distribution.clone());
if let Some(recipient) = self.recipient {
account_infos.push(recipient.clone());
}
account_infos.push(self.payer.clone());
if let Some(authority) = self.authority {
account_infos.push(authority.clone());
}
remaining_accounts
.iter()
.for_each(|remaining_account| account_infos.push(remaining_account.0.clone()));
if signers_seeds.is_empty() {
solana_program::program::invoke(&instruction, &account_infos)
} else {
solana_program::program::invoke_signed(&instruction, &account_infos, signers_seeds)
}
}
}
pub struct WithdrawSubsidyCpiBuilder<'a, 'b> {
instruction: Box<WithdrawSubsidyCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> WithdrawSubsidyCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(WithdrawSubsidyCpiBuilderInstruction {
__program: program,
distribution: None,
recipient: None,
payer: None,
authority: None,
amount: None,
__remaining_accounts: Vec::new(),
});
Self { instruction }
}
#[inline(always)]
pub fn distribution(
&mut self,
distribution: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.distribution = Some(distribution);
self
}
#[inline(always)]
pub fn recipient(
&mut self,
recipient: Option<&'b solana_program::account_info::AccountInfo<'a>>,
) -> &mut Self {
self.instruction.recipient = recipient;
self
}
#[inline(always)]
pub fn payer(&mut self, payer: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.payer = Some(payer);
self
}
#[inline(always)]
pub fn authority(
&mut self,
authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
) -> &mut Self {
self.instruction.authority = authority;
self
}
#[inline(always)]
pub fn amount(&mut self, amount: u64) -> &mut Self {
self.instruction.amount = Some(amount);
self
}
#[inline(always)]
pub fn add_remaining_account(
&mut self,
account: &'b solana_program::account_info::AccountInfo<'a>,
is_writable: bool,
is_signer: bool,
) -> &mut Self {
self.instruction
.__remaining_accounts
.push((account, is_writable, is_signer));
self
}
#[inline(always)]
pub fn add_remaining_accounts(
&mut self,
accounts: &[(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)],
) -> &mut Self {
self.instruction
.__remaining_accounts
.extend_from_slice(accounts);
self
}
#[inline(always)]
pub fn invoke(&self) -> solana_program::entrypoint::ProgramResult {
self.invoke_signed(&[])
}
#[allow(clippy::clone_on_copy)]
#[allow(clippy::vec_init_then_push)]
pub fn invoke_signed(
&self,
signers_seeds: &[&[&[u8]]],
) -> solana_program::entrypoint::ProgramResult {
let args = WithdrawSubsidyInstructionArgs {
amount: self.instruction.amount.clone().expect("amount is not set"),
};
let instruction = WithdrawSubsidyCpi {
__program: self.instruction.__program,
distribution: self
.instruction
.distribution
.expect("distribution is not set"),
recipient: self.instruction.recipient,
payer: self.instruction.payer.expect("payer is not set"),
authority: self.instruction.authority,
__args: args,
};
instruction.invoke_signed_with_remaining_accounts(
signers_seeds,
&self.instruction.__remaining_accounts,
)
}
}
struct WithdrawSubsidyCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
distribution: Option<&'b solana_program::account_info::AccountInfo<'a>>,
recipient: Option<&'b solana_program::account_info::AccountInfo<'a>>,
payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
amount: Option<u64>,
__remaining_accounts: Vec<(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)>,
}