use crate::generated::types::AuthorizationData;
use crate::generated::types::CollectionToggle;
use borsh::BorshDeserialize;
use borsh::BorshSerialize;
pub struct UpdateAsCollectionDelegateV2 {
pub authority: solana_program::pubkey::Pubkey,
pub delegate_record: Option<solana_program::pubkey::Pubkey>,
pub token: Option<solana_program::pubkey::Pubkey>,
pub mint: solana_program::pubkey::Pubkey,
pub metadata: solana_program::pubkey::Pubkey,
pub edition: Option<solana_program::pubkey::Pubkey>,
pub payer: solana_program::pubkey::Pubkey,
pub system_program: solana_program::pubkey::Pubkey,
pub sysvar_instructions: solana_program::pubkey::Pubkey,
pub authorization_rules_program: Option<solana_program::pubkey::Pubkey>,
pub authorization_rules: Option<solana_program::pubkey::Pubkey>,
}
impl UpdateAsCollectionDelegateV2 {
pub fn instruction(
&self,
args: UpdateAsCollectionDelegateV2InstructionArgs,
) -> solana_program::instruction::Instruction {
self.instruction_with_remaining_accounts(args, &[])
}
#[allow(clippy::vec_init_then_push)]
pub fn instruction_with_remaining_accounts(
&self,
args: UpdateAsCollectionDelegateV2InstructionArgs,
remaining_accounts: &[solana_program::instruction::AccountMeta],
) -> solana_program::instruction::Instruction {
let mut accounts = Vec::with_capacity(11 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.authority,
true,
));
if let Some(delegate_record) = self.delegate_record {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
delegate_record,
false,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_TOKEN_METADATA_ID,
false,
));
}
if let Some(token) = self.token {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
token, false,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_TOKEN_METADATA_ID,
false,
));
}
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.mint, false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
self.metadata,
false,
));
if let Some(edition) = self.edition {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
edition, false,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_TOKEN_METADATA_ID,
false,
));
}
accounts.push(solana_program::instruction::AccountMeta::new(
self.payer, true,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.system_program,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.sysvar_instructions,
false,
));
if let Some(authorization_rules_program) = self.authorization_rules_program {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
authorization_rules_program,
false,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_TOKEN_METADATA_ID,
false,
));
}
if let Some(authorization_rules) = self.authorization_rules {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
authorization_rules,
false,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_TOKEN_METADATA_ID,
false,
));
}
accounts.extend_from_slice(remaining_accounts);
let mut data = UpdateAsCollectionDelegateV2InstructionData::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_TOKEN_METADATA_ID,
accounts,
data,
}
}
}
#[derive(BorshDeserialize, BorshSerialize)]
struct UpdateAsCollectionDelegateV2InstructionData {
discriminator: u8,
update_as_collection_delegate_v2_discriminator: u8,
}
impl UpdateAsCollectionDelegateV2InstructionData {
fn new() -> Self {
Self {
discriminator: 50,
update_as_collection_delegate_v2_discriminator: 3,
}
}
}
#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UpdateAsCollectionDelegateV2InstructionArgs {
pub collection: CollectionToggle,
pub authorization_data: Option<AuthorizationData>,
}
#[derive(Default)]
pub struct UpdateAsCollectionDelegateV2Builder {
authority: Option<solana_program::pubkey::Pubkey>,
delegate_record: Option<solana_program::pubkey::Pubkey>,
token: Option<solana_program::pubkey::Pubkey>,
mint: Option<solana_program::pubkey::Pubkey>,
metadata: Option<solana_program::pubkey::Pubkey>,
edition: Option<solana_program::pubkey::Pubkey>,
payer: Option<solana_program::pubkey::Pubkey>,
system_program: Option<solana_program::pubkey::Pubkey>,
sysvar_instructions: Option<solana_program::pubkey::Pubkey>,
authorization_rules_program: Option<solana_program::pubkey::Pubkey>,
authorization_rules: Option<solana_program::pubkey::Pubkey>,
collection: Option<CollectionToggle>,
authorization_data: Option<AuthorizationData>,
__remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
}
impl UpdateAsCollectionDelegateV2Builder {
pub fn new() -> Self {
Self::default()
}
#[inline(always)]
pub fn authority(&mut self, authority: solana_program::pubkey::Pubkey) -> &mut Self {
self.authority = Some(authority);
self
}
#[inline(always)]
pub fn delegate_record(
&mut self,
delegate_record: Option<solana_program::pubkey::Pubkey>,
) -> &mut Self {
self.delegate_record = delegate_record;
self
}
#[inline(always)]
pub fn token(&mut self, token: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
self.token = token;
self
}
#[inline(always)]
pub fn mint(&mut self, mint: solana_program::pubkey::Pubkey) -> &mut Self {
self.mint = Some(mint);
self
}
#[inline(always)]
pub fn metadata(&mut self, metadata: solana_program::pubkey::Pubkey) -> &mut Self {
self.metadata = Some(metadata);
self
}
#[inline(always)]
pub fn edition(&mut self, edition: Option<solana_program::pubkey::Pubkey>) -> &mut Self {
self.edition = edition;
self
}
#[inline(always)]
pub fn payer(&mut self, payer: solana_program::pubkey::Pubkey) -> &mut Self {
self.payer = Some(payer);
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 sysvar_instructions(
&mut self,
sysvar_instructions: solana_program::pubkey::Pubkey,
) -> &mut Self {
self.sysvar_instructions = Some(sysvar_instructions);
self
}
#[inline(always)]
pub fn authorization_rules_program(
&mut self,
authorization_rules_program: Option<solana_program::pubkey::Pubkey>,
) -> &mut Self {
self.authorization_rules_program = authorization_rules_program;
self
}
#[inline(always)]
pub fn authorization_rules(
&mut self,
authorization_rules: Option<solana_program::pubkey::Pubkey>,
) -> &mut Self {
self.authorization_rules = authorization_rules;
self
}
#[inline(always)]
pub fn collection(&mut self, collection: CollectionToggle) -> &mut Self {
self.collection = Some(collection);
self
}
#[inline(always)]
pub fn authorization_data(&mut self, authorization_data: AuthorizationData) -> &mut Self {
self.authorization_data = Some(authorization_data);
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 = UpdateAsCollectionDelegateV2 {
authority: self.authority.expect("authority is not set"),
delegate_record: self.delegate_record,
token: self.token,
mint: self.mint.expect("mint is not set"),
metadata: self.metadata.expect("metadata is not set"),
edition: self.edition,
payer: self.payer.expect("payer is not set"),
system_program: self
.system_program
.unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
sysvar_instructions: self.sysvar_instructions.unwrap_or(solana_program::pubkey!(
"Sysvar1nstructions1111111111111111111111111"
)),
authorization_rules_program: self.authorization_rules_program,
authorization_rules: self.authorization_rules,
};
let args = UpdateAsCollectionDelegateV2InstructionArgs {
collection: self.collection.clone().unwrap_or(CollectionToggle::None),
authorization_data: self.authorization_data.clone(),
};
accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
}
}
pub struct UpdateAsCollectionDelegateV2CpiAccounts<'a, 'b> {
pub authority: &'b solana_program::account_info::AccountInfo<'a>,
pub delegate_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub token: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub mint: &'b solana_program::account_info::AccountInfo<'a>,
pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
pub edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub payer: &'b solana_program::account_info::AccountInfo<'a>,
pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
pub sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
pub authorization_rules_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub authorization_rules: Option<&'b solana_program::account_info::AccountInfo<'a>>,
}
pub struct UpdateAsCollectionDelegateV2Cpi<'a, 'b> {
pub __program: &'b solana_program::account_info::AccountInfo<'a>,
pub authority: &'b solana_program::account_info::AccountInfo<'a>,
pub delegate_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub token: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub mint: &'b solana_program::account_info::AccountInfo<'a>,
pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
pub edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub payer: &'b solana_program::account_info::AccountInfo<'a>,
pub system_program: &'b solana_program::account_info::AccountInfo<'a>,
pub sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
pub authorization_rules_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub authorization_rules: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub __args: UpdateAsCollectionDelegateV2InstructionArgs,
}
impl<'a, 'b> UpdateAsCollectionDelegateV2Cpi<'a, 'b> {
pub fn new(
program: &'b solana_program::account_info::AccountInfo<'a>,
accounts: UpdateAsCollectionDelegateV2CpiAccounts<'a, 'b>,
args: UpdateAsCollectionDelegateV2InstructionArgs,
) -> Self {
Self {
__program: program,
authority: accounts.authority,
delegate_record: accounts.delegate_record,
token: accounts.token,
mint: accounts.mint,
metadata: accounts.metadata,
edition: accounts.edition,
payer: accounts.payer,
system_program: accounts.system_program,
sysvar_instructions: accounts.sysvar_instructions,
authorization_rules_program: accounts.authorization_rules_program,
authorization_rules: accounts.authorization_rules,
__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(11 + remaining_accounts.len());
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.authority.key,
true,
));
if let Some(delegate_record) = self.delegate_record {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*delegate_record.key,
false,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_TOKEN_METADATA_ID,
false,
));
}
if let Some(token) = self.token {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*token.key, false,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_TOKEN_METADATA_ID,
false,
));
}
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.mint.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new(
*self.metadata.key,
false,
));
if let Some(edition) = self.edition {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*edition.key,
false,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_TOKEN_METADATA_ID,
false,
));
}
accounts.push(solana_program::instruction::AccountMeta::new(
*self.payer.key,
true,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.system_program.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.sysvar_instructions.key,
false,
));
if let Some(authorization_rules_program) = self.authorization_rules_program {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*authorization_rules_program.key,
false,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_TOKEN_METADATA_ID,
false,
));
}
if let Some(authorization_rules) = self.authorization_rules {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*authorization_rules.key,
false,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_TOKEN_METADATA_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 = UpdateAsCollectionDelegateV2InstructionData::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_TOKEN_METADATA_ID,
accounts,
data,
};
let mut account_infos = Vec::with_capacity(11 + 1 + remaining_accounts.len());
account_infos.push(self.__program.clone());
account_infos.push(self.authority.clone());
if let Some(delegate_record) = self.delegate_record {
account_infos.push(delegate_record.clone());
}
if let Some(token) = self.token {
account_infos.push(token.clone());
}
account_infos.push(self.mint.clone());
account_infos.push(self.metadata.clone());
if let Some(edition) = self.edition {
account_infos.push(edition.clone());
}
account_infos.push(self.payer.clone());
account_infos.push(self.system_program.clone());
account_infos.push(self.sysvar_instructions.clone());
if let Some(authorization_rules_program) = self.authorization_rules_program {
account_infos.push(authorization_rules_program.clone());
}
if let Some(authorization_rules) = self.authorization_rules {
account_infos.push(authorization_rules.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 UpdateAsCollectionDelegateV2CpiBuilder<'a, 'b> {
instruction: Box<UpdateAsCollectionDelegateV2CpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> UpdateAsCollectionDelegateV2CpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(UpdateAsCollectionDelegateV2CpiBuilderInstruction {
__program: program,
authority: None,
delegate_record: None,
token: None,
mint: None,
metadata: None,
edition: None,
payer: None,
system_program: None,
sysvar_instructions: None,
authorization_rules_program: None,
authorization_rules: None,
collection: None,
authorization_data: None,
__remaining_accounts: Vec::new(),
});
Self { instruction }
}
#[inline(always)]
pub fn authority(
&mut self,
authority: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.authority = Some(authority);
self
}
#[inline(always)]
pub fn delegate_record(
&mut self,
delegate_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
) -> &mut Self {
self.instruction.delegate_record = delegate_record;
self
}
#[inline(always)]
pub fn token(
&mut self,
token: Option<&'b solana_program::account_info::AccountInfo<'a>>,
) -> &mut Self {
self.instruction.token = token;
self
}
#[inline(always)]
pub fn mint(&mut self, mint: &'b solana_program::account_info::AccountInfo<'a>) -> &mut Self {
self.instruction.mint = Some(mint);
self
}
#[inline(always)]
pub fn metadata(
&mut self,
metadata: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.metadata = Some(metadata);
self
}
#[inline(always)]
pub fn edition(
&mut self,
edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
) -> &mut Self {
self.instruction.edition = edition;
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 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 sysvar_instructions(
&mut self,
sysvar_instructions: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.sysvar_instructions = Some(sysvar_instructions);
self
}
#[inline(always)]
pub fn authorization_rules_program(
&mut self,
authorization_rules_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
) -> &mut Self {
self.instruction.authorization_rules_program = authorization_rules_program;
self
}
#[inline(always)]
pub fn authorization_rules(
&mut self,
authorization_rules: Option<&'b solana_program::account_info::AccountInfo<'a>>,
) -> &mut Self {
self.instruction.authorization_rules = authorization_rules;
self
}
#[inline(always)]
pub fn collection(&mut self, collection: CollectionToggle) -> &mut Self {
self.instruction.collection = Some(collection);
self
}
#[inline(always)]
pub fn authorization_data(&mut self, authorization_data: AuthorizationData) -> &mut Self {
self.instruction.authorization_data = Some(authorization_data);
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 = UpdateAsCollectionDelegateV2InstructionArgs {
collection: self
.instruction
.collection
.clone()
.unwrap_or(CollectionToggle::None),
authorization_data: self.instruction.authorization_data.clone(),
};
let instruction = UpdateAsCollectionDelegateV2Cpi {
__program: self.instruction.__program,
authority: self.instruction.authority.expect("authority is not set"),
delegate_record: self.instruction.delegate_record,
token: self.instruction.token,
mint: self.instruction.mint.expect("mint is not set"),
metadata: self.instruction.metadata.expect("metadata is not set"),
edition: self.instruction.edition,
payer: self.instruction.payer.expect("payer is not set"),
system_program: self
.instruction
.system_program
.expect("system_program is not set"),
sysvar_instructions: self
.instruction
.sysvar_instructions
.expect("sysvar_instructions is not set"),
authorization_rules_program: self.instruction.authorization_rules_program,
authorization_rules: self.instruction.authorization_rules,
__args: args,
};
instruction.invoke_signed_with_remaining_accounts(
signers_seeds,
&self.instruction.__remaining_accounts,
)
}
}
struct UpdateAsCollectionDelegateV2CpiBuilderInstruction<'a, 'b> {
__program: &'b solana_program::account_info::AccountInfo<'a>,
authority: Option<&'b solana_program::account_info::AccountInfo<'a>>,
delegate_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
token: Option<&'b solana_program::account_info::AccountInfo<'a>>,
mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
payer: Option<&'b solana_program::account_info::AccountInfo<'a>>,
system_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
sysvar_instructions: Option<&'b solana_program::account_info::AccountInfo<'a>>,
authorization_rules_program: Option<&'b solana_program::account_info::AccountInfo<'a>>,
authorization_rules: Option<&'b solana_program::account_info::AccountInfo<'a>>,
collection: Option<CollectionToggle>,
authorization_data: Option<AuthorizationData>,
__remaining_accounts: Vec<(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)>,
}