mpl-token-metadata 5.1.2-alpha.2

Metaplex Token Metadata SDK
Documentation
//! This code was AUTOGENERATED using the kinobi library.
//! Please DO NOT EDIT THIS FILE, instead use visitors
//! to add features, then rerun kinobi to update it.
//!
//! [https://github.com/metaplex-foundation/kinobi]
//!

#[cfg(feature = "anchor")]
use anchor_lang::prelude::{AnchorDeserialize, AnchorSerialize};
#[cfg(not(feature = "anchor"))]
use borsh::{BorshDeserialize, BorshSerialize};

/// Accounts.
pub struct ConvertMasterEditionV1ToV2 {
    /// Master Record Edition V1 (pda of ['metadata', program id, master metadata mint id, 'edition'])
    pub master_edition: solana_program::pubkey::Pubkey,
    /// One time authorization mint
    pub one_time_auth: solana_program::pubkey::Pubkey,
    /// Printing mint
    pub printing_mint: solana_program::pubkey::Pubkey,
}

impl ConvertMasterEditionV1ToV2 {
    pub fn instruction(&self) -> solana_program::instruction::Instruction {
        self.instruction_with_remaining_accounts(&[])
    }
    #[allow(clippy::vec_init_then_push)]
    pub fn instruction_with_remaining_accounts(
        &self,
        remaining_accounts: &[solana_program::instruction::AccountMeta],
    ) -> solana_program::instruction::Instruction {
        let mut accounts = Vec::with_capacity(3 + remaining_accounts.len());
        accounts.push(solana_program::instruction::AccountMeta::new(
            self.master_edition,
            false,
        ));
        accounts.push(solana_program::instruction::AccountMeta::new(
            self.one_time_auth,
            false,
        ));
        accounts.push(solana_program::instruction::AccountMeta::new(
            self.printing_mint,
            false,
        ));
        accounts.extend_from_slice(remaining_accounts);
        let data = borsh::to_vec(&(ConvertMasterEditionV1ToV2InstructionData::new())).unwrap();

        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 ConvertMasterEditionV1ToV2InstructionData {
    discriminator: u8,
}

impl ConvertMasterEditionV1ToV2InstructionData {
    pub fn new() -> Self {
        Self { discriminator: 12 }
    }
}

/// Instruction builder for `ConvertMasterEditionV1ToV2`.
///
/// ### Accounts:
///
///   0. `[writable]` master_edition
///   1. `[writable]` one_time_auth
///   2. `[writable]` printing_mint
#[derive(Default)]
pub struct ConvertMasterEditionV1ToV2Builder {
    master_edition: Option<solana_program::pubkey::Pubkey>,
    one_time_auth: Option<solana_program::pubkey::Pubkey>,
    printing_mint: Option<solana_program::pubkey::Pubkey>,
    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
}

impl ConvertMasterEditionV1ToV2Builder {
    pub fn new() -> Self {
        Self::default()
    }
    /// Master Record Edition V1 (pda of ['metadata', program id, master metadata mint id, 'edition'])
    #[inline(always)]
    pub fn master_edition(&mut self, master_edition: solana_program::pubkey::Pubkey) -> &mut Self {
        self.master_edition = Some(master_edition);
        self
    }
    /// One time authorization mint
    #[inline(always)]
    pub fn one_time_auth(&mut self, one_time_auth: solana_program::pubkey::Pubkey) -> &mut Self {
        self.one_time_auth = Some(one_time_auth);
        self
    }
    /// Printing mint
    #[inline(always)]
    pub fn printing_mint(&mut self, printing_mint: solana_program::pubkey::Pubkey) -> &mut Self {
        self.printing_mint = Some(printing_mint);
        self
    }
    /// Add an aditional account to the instruction.
    #[inline(always)]
    pub fn add_remaining_account(
        &mut self,
        account: solana_program::instruction::AccountMeta,
    ) -> &mut Self {
        self.__remaining_accounts.push(account);
        self
    }
    /// Add additional accounts to the instruction.
    #[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 = ConvertMasterEditionV1ToV2 {
            master_edition: self.master_edition.expect("master_edition is not set"),
            one_time_auth: self.one_time_auth.expect("one_time_auth is not set"),
            printing_mint: self.printing_mint.expect("printing_mint is not set"),
        };

        accounts.instruction_with_remaining_accounts(&self.__remaining_accounts)
    }
}

/// `convert_master_edition_v1_to_v2` CPI accounts.
pub struct ConvertMasterEditionV1ToV2CpiAccounts<'a, 'b> {
    /// Master Record Edition V1 (pda of ['metadata', program id, master metadata mint id, 'edition'])
    pub master_edition: &'b solana_program::account_info::AccountInfo<'a>,
    /// One time authorization mint
    pub one_time_auth: &'b solana_program::account_info::AccountInfo<'a>,
    /// Printing mint
    pub printing_mint: &'b solana_program::account_info::AccountInfo<'a>,
}

/// `convert_master_edition_v1_to_v2` CPI instruction.
pub struct ConvertMasterEditionV1ToV2Cpi<'a, 'b> {
    /// The program to invoke.
    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
    /// Master Record Edition V1 (pda of ['metadata', program id, master metadata mint id, 'edition'])
    pub master_edition: &'b solana_program::account_info::AccountInfo<'a>,
    /// One time authorization mint
    pub one_time_auth: &'b solana_program::account_info::AccountInfo<'a>,
    /// Printing mint
    pub printing_mint: &'b solana_program::account_info::AccountInfo<'a>,
}

impl<'a, 'b> ConvertMasterEditionV1ToV2Cpi<'a, 'b> {
    pub fn new(
        program: &'b solana_program::account_info::AccountInfo<'a>,
        accounts: ConvertMasterEditionV1ToV2CpiAccounts<'a, 'b>,
    ) -> Self {
        Self {
            __program: program,
            master_edition: accounts.master_edition,
            one_time_auth: accounts.one_time_auth,
            printing_mint: accounts.printing_mint,
        }
    }
    #[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(3 + remaining_accounts.len());
        accounts.push(solana_program::instruction::AccountMeta::new(
            *self.master_edition.key,
            false,
        ));
        accounts.push(solana_program::instruction::AccountMeta::new(
            *self.one_time_auth.key,
            false,
        ));
        accounts.push(solana_program::instruction::AccountMeta::new(
            *self.printing_mint.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 data = borsh::to_vec(&(ConvertMasterEditionV1ToV2InstructionData::new())).unwrap();

        let instruction = solana_program::instruction::Instruction {
            program_id: crate::MPL_TOKEN_METADATA_ID,
            accounts,
            data,
        };
        let mut account_infos = Vec::with_capacity(3 + 1 + remaining_accounts.len());
        account_infos.push(self.__program.clone());
        account_infos.push(self.master_edition.clone());
        account_infos.push(self.one_time_auth.clone());
        account_infos.push(self.printing_mint.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)
        }
    }
}

/// Instruction builder for `ConvertMasterEditionV1ToV2` via CPI.
///
/// ### Accounts:
///
///   0. `[writable]` master_edition
///   1. `[writable]` one_time_auth
///   2. `[writable]` printing_mint
pub struct ConvertMasterEditionV1ToV2CpiBuilder<'a, 'b> {
    instruction: Box<ConvertMasterEditionV1ToV2CpiBuilderInstruction<'a, 'b>>,
}

impl<'a, 'b> ConvertMasterEditionV1ToV2CpiBuilder<'a, 'b> {
    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
        let instruction = Box::new(ConvertMasterEditionV1ToV2CpiBuilderInstruction {
            __program: program,
            master_edition: None,
            one_time_auth: None,
            printing_mint: None,
            __remaining_accounts: Vec::new(),
        });
        Self { instruction }
    }
    /// Master Record Edition V1 (pda of ['metadata', program id, master metadata mint id, 'edition'])
    #[inline(always)]
    pub fn master_edition(
        &mut self,
        master_edition: &'b solana_program::account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.master_edition = Some(master_edition);
        self
    }
    /// One time authorization mint
    #[inline(always)]
    pub fn one_time_auth(
        &mut self,
        one_time_auth: &'b solana_program::account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.one_time_auth = Some(one_time_auth);
        self
    }
    /// Printing mint
    #[inline(always)]
    pub fn printing_mint(
        &mut self,
        printing_mint: &'b solana_program::account_info::AccountInfo<'a>,
    ) -> &mut Self {
        self.instruction.printing_mint = Some(printing_mint);
        self
    }
    /// Add an additional account to the instruction.
    #[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
    }
    /// Add additional accounts to the instruction.
    ///
    /// Each account is represented by a tuple of the `AccountInfo`, a `bool` indicating whether the account is writable or not,
    /// and a `bool` indicating whether the account is a signer or not.
    #[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 instruction = ConvertMasterEditionV1ToV2Cpi {
            __program: self.instruction.__program,

            master_edition: self
                .instruction
                .master_edition
                .expect("master_edition is not set"),

            one_time_auth: self
                .instruction
                .one_time_auth
                .expect("one_time_auth is not set"),

            printing_mint: self
                .instruction
                .printing_mint
                .expect("printing_mint is not set"),
        };
        instruction.invoke_signed_with_remaining_accounts(
            signers_seeds,
            &self.instruction.__remaining_accounts,
        )
    }
}

struct ConvertMasterEditionV1ToV2CpiBuilderInstruction<'a, 'b> {
    __program: &'b solana_program::account_info::AccountInfo<'a>,
    master_edition: Option<&'b solana_program::account_info::AccountInfo<'a>>,
    one_time_auth: Option<&'b solana_program::account_info::AccountInfo<'a>>,
    printing_mint: Option<&'b solana_program::account_info::AccountInfo<'a>>,
    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
    __remaining_accounts: Vec<(
        &'b solana_program::account_info::AccountInfo<'a>,
        bool,
        bool,
    )>,
}