use crate::generated::types::VerificationArgs;
#[cfg(feature = "anchor")]
use anchor_lang::prelude::{AnchorDeserialize, AnchorSerialize};
#[cfg(not(feature = "anchor"))]
use borsh::{BorshDeserialize, BorshSerialize};
pub struct Unverify {
pub authority: solana_program::pubkey::Pubkey,
pub delegate_record: Option<solana_program::pubkey::Pubkey>,
pub metadata: solana_program::pubkey::Pubkey,
pub collection_mint: Option<solana_program::pubkey::Pubkey>,
pub collection_metadata: Option<solana_program::pubkey::Pubkey>,
pub system_program: solana_program::pubkey::Pubkey,
pub sysvar_instructions: solana_program::pubkey::Pubkey,
}
impl Unverify {
pub fn instruction(
&self,
args: UnverifyInstructionArgs,
) -> solana_program::instruction::Instruction {
self.instruction_with_remaining_accounts(args, &[])
}
#[allow(clippy::vec_init_then_push)]
pub fn instruction_with_remaining_accounts(
&self,
args: UnverifyInstructionArgs,
remaining_accounts: &[solana_program::instruction::AccountMeta],
) -> solana_program::instruction::Instruction {
let mut accounts = Vec::with_capacity(7 + 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,
));
}
accounts.push(solana_program::instruction::AccountMeta::new(
self.metadata,
false,
));
if let Some(collection_mint) = self.collection_mint {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
collection_mint,
false,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_TOKEN_METADATA_ID,
false,
));
}
if let Some(collection_metadata) = self.collection_metadata {
accounts.push(solana_program::instruction::AccountMeta::new(
collection_metadata,
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.system_program,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
self.sysvar_instructions,
false,
));
accounts.extend_from_slice(remaining_accounts);
let mut data = borsh::to_vec(&(UnverifyInstructionData::new())).unwrap();
let mut args = borsh::to_vec(&args).unwrap();
data.append(&mut args);
solana_program::instruction::Instruction {
program_id: crate::MPL_TOKEN_METADATA_ID,
accounts,
data,
}
}
}
#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
pub struct UnverifyInstructionData {
discriminator: u8,
}
impl UnverifyInstructionData {
pub fn new() -> Self {
Self { discriminator: 53 }
}
}
#[cfg_attr(not(feature = "anchor"), derive(BorshSerialize, BorshDeserialize))]
#[cfg_attr(feature = "anchor", derive(AnchorSerialize, AnchorDeserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UnverifyInstructionArgs {
pub verification_args: VerificationArgs,
}
#[derive(Default)]
pub struct UnverifyBuilder {
authority: Option<solana_program::pubkey::Pubkey>,
delegate_record: Option<solana_program::pubkey::Pubkey>,
metadata: Option<solana_program::pubkey::Pubkey>,
collection_mint: Option<solana_program::pubkey::Pubkey>,
collection_metadata: Option<solana_program::pubkey::Pubkey>,
system_program: Option<solana_program::pubkey::Pubkey>,
sysvar_instructions: Option<solana_program::pubkey::Pubkey>,
verification_args: Option<VerificationArgs>,
__remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
}
impl UnverifyBuilder {
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 metadata(&mut self, metadata: solana_program::pubkey::Pubkey) -> &mut Self {
self.metadata = Some(metadata);
self
}
#[inline(always)]
pub fn collection_mint(
&mut self,
collection_mint: Option<solana_program::pubkey::Pubkey>,
) -> &mut Self {
self.collection_mint = collection_mint;
self
}
#[inline(always)]
pub fn collection_metadata(
&mut self,
collection_metadata: Option<solana_program::pubkey::Pubkey>,
) -> &mut Self {
self.collection_metadata = collection_metadata;
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 verification_args(&mut self, verification_args: VerificationArgs) -> &mut Self {
self.verification_args = Some(verification_args);
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 = Unverify {
authority: self.authority.expect("authority is not set"),
delegate_record: self.delegate_record,
metadata: self.metadata.expect("metadata is not set"),
collection_mint: self.collection_mint,
collection_metadata: self.collection_metadata,
system_program: self
.system_program
.unwrap_or(solana_program::pubkey!("11111111111111111111111111111111")),
sysvar_instructions: self.sysvar_instructions.unwrap_or(solana_program::pubkey!(
"Sysvar1nstructions1111111111111111111111111"
)),
};
let args = UnverifyInstructionArgs {
verification_args: self
.verification_args
.clone()
.expect("verification_args is not set"),
};
accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
}
}
pub struct UnverifyCpiAccounts<'a, 'b> {
pub authority: &'b solana_program::account_info::AccountInfo<'a>,
pub delegate_record: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub metadata: &'b solana_program::account_info::AccountInfo<'a>,
pub collection_mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub collection_metadata: Option<&'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 struct UnverifyCpi<'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 metadata: &'b solana_program::account_info::AccountInfo<'a>,
pub collection_mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
pub collection_metadata: Option<&'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 __args: UnverifyInstructionArgs,
}
impl<'a, 'b> UnverifyCpi<'a, 'b> {
pub fn new(
program: &'b solana_program::account_info::AccountInfo<'a>,
accounts: UnverifyCpiAccounts<'a, 'b>,
args: UnverifyInstructionArgs,
) -> Self {
Self {
__program: program,
authority: accounts.authority,
delegate_record: accounts.delegate_record,
metadata: accounts.metadata,
collection_mint: accounts.collection_mint,
collection_metadata: accounts.collection_metadata,
system_program: accounts.system_program,
sysvar_instructions: accounts.sysvar_instructions,
__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(7 + 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,
));
}
accounts.push(solana_program::instruction::AccountMeta::new(
*self.metadata.key,
false,
));
if let Some(collection_mint) = self.collection_mint {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*collection_mint.key,
false,
));
} else {
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
crate::MPL_TOKEN_METADATA_ID,
false,
));
}
if let Some(collection_metadata) = self.collection_metadata {
accounts.push(solana_program::instruction::AccountMeta::new(
*collection_metadata.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.system_program.key,
false,
));
accounts.push(solana_program::instruction::AccountMeta::new_readonly(
*self.sysvar_instructions.key,
false,
));
remaining_accounts.iter().for_each(|remaining_account| {
accounts.push(solana_program::instruction::AccountMeta {
pubkey: *remaining_account.0.key,
is_writable: remaining_account.1,
is_signer: remaining_account.2,
})
});
let mut data = borsh::to_vec(&(UnverifyInstructionData::new())).unwrap();
let mut args = borsh::to_vec(&self.__args).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(7 + 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());
}
account_infos.push(self.metadata.clone());
if let Some(collection_mint) = self.collection_mint {
account_infos.push(collection_mint.clone());
}
if let Some(collection_metadata) = self.collection_metadata {
account_infos.push(collection_metadata.clone());
}
account_infos.push(self.system_program.clone());
account_infos.push(self.sysvar_instructions.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 UnverifyCpiBuilder<'a, 'b> {
instruction: Box<UnverifyCpiBuilderInstruction<'a, 'b>>,
}
impl<'a, 'b> UnverifyCpiBuilder<'a, 'b> {
pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
let instruction = Box::new(UnverifyCpiBuilderInstruction {
__program: program,
authority: None,
delegate_record: None,
metadata: None,
collection_mint: None,
collection_metadata: None,
system_program: None,
sysvar_instructions: None,
verification_args: 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 metadata(
&mut self,
metadata: &'b solana_program::account_info::AccountInfo<'a>,
) -> &mut Self {
self.instruction.metadata = Some(metadata);
self
}
#[inline(always)]
pub fn collection_mint(
&mut self,
collection_mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
) -> &mut Self {
self.instruction.collection_mint = collection_mint;
self
}
#[inline(always)]
pub fn collection_metadata(
&mut self,
collection_metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
) -> &mut Self {
self.instruction.collection_metadata = collection_metadata;
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 verification_args(&mut self, verification_args: VerificationArgs) -> &mut Self {
self.instruction.verification_args = Some(verification_args);
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 = UnverifyInstructionArgs {
verification_args: self
.instruction
.verification_args
.clone()
.expect("verification_args is not set"),
};
let instruction = UnverifyCpi {
__program: self.instruction.__program,
authority: self.instruction.authority.expect("authority is not set"),
delegate_record: self.instruction.delegate_record,
metadata: self.instruction.metadata.expect("metadata is not set"),
collection_mint: self.instruction.collection_mint,
collection_metadata: self.instruction.collection_metadata,
system_program: self
.instruction
.system_program
.expect("system_program is not set"),
sysvar_instructions: self
.instruction
.sysvar_instructions
.expect("sysvar_instructions is not set"),
__args: args,
};
instruction.invoke_signed_with_remaining_accounts(
signers_seeds,
&self.instruction.__remaining_accounts,
)
}
}
struct UnverifyCpiBuilderInstruction<'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>>,
metadata: Option<&'b solana_program::account_info::AccountInfo<'a>>,
collection_mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
collection_metadata: 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>>,
verification_args: Option<VerificationArgs>,
__remaining_accounts: Vec<(
&'b solana_program::account_info::AccountInfo<'a>,
bool,
bool,
)>,
}