use borsh::BorshDeserialize;
use borsh::BorshSerialize;
use solana_program::pubkey::Pubkey;
pub struct UpdateDistribution {
pub distribution: solana_program::pubkey::Pubkey,
pub payer: solana_program::pubkey::Pubkey,
pub authority: Option<solana_program::pubkey::Pubkey>,
pub fee_wallet: solana_program::pubkey::Pubkey,
pub system_program: solana_program::pubkey::Pubkey,
}
impl UpdateDistribution {
pub fn instruction(
&self,
args: UpdateDistributionInstructionArgs,
) -> solana_program::instruction::Instruction {
self.instruction_with_remaining_accounts(args, &[])
}
#[allow(clippy::vec_init_then_push)]
pub fn instruction_with_remaining_accounts(
&self,
args: UpdateDistributionInstructionArgs,
remaining_accounts: &[solana_program::instruction::AccountMeta],
) -> solana_program::instruction::Instruction {
let mut accounts = Vec::with_capacity(5 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new(
self.distribution,
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.push(solana_program::instruction::AccountMeta::new(
self.fee_wallet,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.system_program,
false,
));
accounts.extend_from_slice(remaining_accounts);
let mut data = UpdateDistributionInstructionData::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 UpdateDistributionInstructionData {
discriminator: u8,
}
impl UpdateDistributionInstructionData {
fn new() -> Self {
Self { discriminator: 1 }
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UpdateDistributionInstructionArgs {
pub merkle_root: Option<[u8; 32]>,
pub tree_height: Option<u8>,
pub start_time: Option<i64>,
pub end_time: Option<i64>,
pub total_claimants: Option<u64>,
pub new_authority: Option<Pubkey>,
pub name: Option<String>,
pub new_permissioned_distributor: Option<Pubkey>,
}
#[derive(Default)]
pub struct UpdateDistributionBuilder {
distribution: Option<solana_program::pubkey::Pubkey>,
payer: Option<solana_program::pubkey::Pubkey>,
authority: Option<solana_program::pubkey::Pubkey>,
fee_wallet: Option<solana_program::pubkey::Pubkey>,
system_program: Option<solana_program::pubkey::Pubkey>,
merkle_root: Option<[u8; 32]>,
tree_height: Option<u8>,
start_time: Option<i64>,
end_time: Option<i64>,
total_claimants: Option<u64>,
new_authority: Option<Pubkey>,
name: Option<String>,
new_permissioned_distributor: Option<Pubkey>,
__remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
}
impl UpdateDistributionBuilder {
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 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 fee_wallet(&mut self, fee_wallet: solana_program::pubkey::Pubkey) -> &mut Self {
self.fee_wallet = Some(fee_wallet);
self
}
#[inline(always)]
pub fn system_program(&mut self, system_program: solana_program::pubkey::Pubkey) -> &mut Self {
self.system_program = Some(system_program);
self
}
#[inline(always)]
pub fn merkle_root(&mut self, merkle_root: [u8; 32]) -> &mut Self {
self.merkle_root = Some(merkle_root);
self
}
#[inline(always)]
pub fn tree_height(&mut self, tree_height: u8) -> &mut Self {
self.tree_height = Some(tree_height);
self
}
#[inline(always)]
pub fn start_time(&mut self, start_time: i64) -> &mut Self {
self.start_time = Some(start_time);
self
}
#[inline(always)]
pub fn end_time(&mut self, end_time: i64) -> &mut Self {
self.end_time = Some(end_time);
self
}
#[inline(always)]
pub fn total_claimants(&mut self, total_claimants: u64) -> &mut Self {
self.total_claimants = Some(total_claimants);
self
}
#[inline(always)]
pub fn new_authority(&mut self, new_authority: Pubkey) -> &mut Self {
self.new_authority = Some(new_authority);
self
}
#[inline(always)]
pub fn name(&mut self, name: String) -> &mut Self {
self.name = Some(name);
self
}
#[inline(always)]
pub fn new_permissioned_distributor(
&mut self,
new_permissioned_distributor: Pubkey,
) -> &mut Self {
self.new_permissioned_distributor = Some(new_permissioned_distributor);
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 = UpdateDistribution {
distribution: self.distribution.expect("distribution is not set"),
payer: self.payer.expect("payer is not set"),
authority: self.authority,
fee_wallet: self.fee_wallet.unwrap_or(solana_program::pubkey!(
"9kFjQsxtpBsaw8s7aUyiY3wazYDNgFP4Lj5rsBVVF8tb"
)),
system_program: self
.system_program
.unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
};
let args = UpdateDistributionInstructionArgs {
merkle_root: self.merkle_root.clone(),
tree_height: self.tree_height.clone(),
start_time: self.start_time.clone(),
end_time: self.end_time.clone(),
total_claimants: self.total_claimants.clone(),
new_authority: self.new_authority.clone(),
name: self.name.clone(),
new_permissioned_distributor: self.new_permissioned_distributor.clone(),
};
accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
}
}
pub struct UpdateDistributionCpiAccounts<'a, 'b> {
pub distribution: &'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 fee_wallet: &'b solana_program::account_info::AccountInfo<'a>,
pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
}
pub struct UpdateDistributionCpi<'a, 'b> {
pub __program: &'b solana_program::account_info::AccountInfo<'a>,
pub distribution: &'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 fee_wallet: &'b solana_program::account_info::AccountInfo<'a>,
pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
pub __args: UpdateDistributionInstructionArgs,
}
impl<'a, 'b> UpdateDistributionCpi<'a, 'b> {
pub fn new(
program: &'b solana_program::account_info::AccountInfo<'a>,
accounts: UpdateDistributionCpiAccounts<'a, 'b>,
args: UpdateDistributionInstructionArgs,
) -> Self {
Self {
__program: program,
distribution: accounts.distribution,
payer: accounts.payer,
authority: accounts.authority,
fee_wallet: accounts.fee_wallet,
system_program: accounts.system_program,
__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(5 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new(
*self.distribution.key,
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,
));
}
accounts.push(solana_program::instruction::AccountMeta::new(
*self.fee_wallet.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.system_program.key,
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 = UpdateDistributionInstructionData::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(5 + 1 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.distribution.clone());
account_infos.push(self.payer.clone());
if let Some(authority) = self.authority {
account_infos.push(authority.clone());
}
account_infos.push(self.fee_wallet.clone());
account_infos.push(self.system_program.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 UpdateDistributionCpiBuilder<'a, 'b> {
instruction: Box<UpdateDistributionCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> UpdateDistributionCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(UpdateDistributionCpiBuilderInstruction {
__program: program,
distribution: None,
payer: None,
authority: None,
fee_wallet: None,
system_program: None,
merkle_root: None,
tree_height: None,
start_time: None,
end_time: None,
total_claimants: None,
new_authority: None,
name: None,
new_permissioned_distributor: 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 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 fee_wallet(
&mut self,
fee_wallet: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.fee_wallet = Some(fee_wallet);
self
}
#[inline(always)]
pub fn system_program(
&mut self,
system_program: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.system_program = Some(system_program);
self
}
#[inline(always)]
pub fn merkle_root(&mut self, merkle_root: [u8; 32]) -> &mut Self {
self.instruction.merkle_root = Some(merkle_root);
self
}
#[inline(always)]
pub fn tree_height(&mut self, tree_height: u8) -> &mut Self {
self.instruction.tree_height = Some(tree_height);
self
}
#[inline(always)]
pub fn start_time(&mut self, start_time: i64) -> &mut Self {
self.instruction.start_time = Some(start_time);
self
}
#[inline(always)]
pub fn end_time(&mut self, end_time: i64) -> &mut Self {
self.instruction.end_time = Some(end_time);
self
}
#[inline(always)]
pub fn total_claimants(&mut self, total_claimants: u64) -> &mut Self {
self.instruction.total_claimants = Some(total_claimants);
self
}
#[inline(always)]
pub fn new_authority(&mut self, new_authority: Pubkey) -> &mut Self {
self.instruction.new_authority = Some(new_authority);
self
}
#[inline(always)]
pub fn name(&mut self, name: String) -> &mut Self {
self.instruction.name = Some(name);
self
}
#[inline(always)]
pub fn new_permissioned_distributor(
&mut self,
new_permissioned_distributor: Pubkey,
) -> &mut Self {
self.instruction.new_permissioned_distributor = Some(new_permissioned_distributor);
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 = UpdateDistributionInstructionArgs {
merkle_root: self.instruction.merkle_root.clone(),
tree_height: self.instruction.tree_height.clone(),
start_time: self.instruction.start_time.clone(),
end_time: self.instruction.end_time.clone(),
total_claimants: self.instruction.total_claimants.clone(),
new_authority: self.instruction.new_authority.clone(),
name: self.instruction.name.clone(),
new_permissioned_distributor: self.instruction.new_permissioned_distributor.clone(),
};
let instruction = UpdateDistributionCpi {
__program: self.instruction.__program,
distribution: self
.instruction
.distribution
.expect("distribution is not set"),
payer: self.instruction.payer.expect("payer is not set"),
authority: self.instruction.authority,
fee_wallet: self.instruction.fee_wallet.expect("fee_wallet is not set"),
system_program: self
.instruction
.system_program
.expect("system_program is not set"),
__args: args,
};
instruction.invoke_signed_with_remaining_accounts(
signers_seeds,
&self.instruction.__remaining_accounts,
)
}
}
struct UpdateDistributionCpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
distribution: 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>>,
fee_wallet: Option<&'b solana_program::account_info::AccountInfo<'a>>,
system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
merkle_root: Option<[u8; 32]>,
tree_height: Option<u8>,
start_time: Option<i64>,
end_time: Option<i64>,
total_claimants: Option<u64>,
new_authority: Option<Pubkey>,
name: Option<String>,
new_permissioned_distributor: Option<Pubkey>,
__remaining_accounts: Vec<(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)>,
}