solana-config-program-client 1.1.0

A generated Rust library for the Config program
Documentation
//! This code was AUTOGENERATED using the codama library.
//! Please DO NOT EDIT THIS FILE, instead use visitors
//! to add features, then rerun codama to update it.
//!
//! <https://github.com/codama-idl/codama>

use {
    crate::hooked::ConfigKeys,
    borsh::{BorshDeserialize, BorshSerialize},
    kaigan::types::RemainderVec,
};

/// Accounts.
#[derive(Debug)]
pub struct Store {
    /// The config account to be modified.
    /// Must sign during the first call to `store` to initialize the account,
    /// or if no signers are configured in the config data.
    pub config_account: (solana_program::pubkey::Pubkey, bool),
}

impl Store {
    pub fn instruction(
        &self,
        args: StoreInstructionArgs,
    ) -> solana_program::instruction::Instruction {
        self.instruction_with_remaining_accounts(args, &[])
    }
    #[allow(clippy::vec_init_then_push)]
    pub fn instruction_with_remaining_accounts(
        &self,
        args: StoreInstructionArgs,
        remaining_accounts: &[solana_program::instruction::AccountMeta],
    ) -> solana_program::instruction::Instruction {
        let mut accounts = Vec::with_capacity(1 + remaining_accounts.len());
        accounts.push(solana_program::instruction::AccountMeta::new(
            self.config_account.0,
            self.config_account.1,
        ));
        accounts.extend_from_slice(remaining_accounts);
        let mut data = borsh::to_vec(&StoreInstructionData::new()).unwrap();
        let mut args = borsh::to_vec(&args).unwrap();
        data.append(&mut args);

        solana_program::instruction::Instruction {
            program_id: crate::SOLANA_CONFIG_ID,
            accounts,
            data,
        }
    }
}

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct StoreInstructionData {}

impl StoreInstructionData {
    pub fn new() -> Self {
        Self {}
    }
}

impl Default for StoreInstructionData {
    fn default() -> Self {
        Self::new()
    }
}

#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct StoreInstructionArgs {
    pub keys: ConfigKeys,
    pub data: RemainderVec<u8>,
}

/// Instruction builder for `Store`.
///
/// ### Accounts:
///
///   0. `[writable, signer]` config_account
#[derive(Clone, Debug, Default)]
pub struct StoreBuilder {
    config_account: Option<(solana_program::pubkey::Pubkey, bool)>,
    keys: Option<ConfigKeys>,
    data: Option<RemainderVec<u8>>,
    __remaining_accounts: Vec<solana_program::instruction::AccountMeta>,
}

impl StoreBuilder {
    pub fn new() -> Self {
        Self::default()
    }
    /// The config account to be modified.
    /// Must sign during the first call to `store` to initialize the account,
    /// or if no signers are configured in the config data.
    #[inline(always)]
    pub fn config_account(
        &mut self,
        config_account: solana_program::pubkey::Pubkey,
        as_signer: bool,
    ) -> &mut Self {
        self.config_account = Some((config_account, as_signer));
        self
    }
    #[inline(always)]
    pub fn keys(&mut self, keys: ConfigKeys) -> &mut Self {
        self.keys = Some(keys);
        self
    }
    #[inline(always)]
    pub fn data(&mut self, data: RemainderVec<u8>) -> &mut Self {
        self.data = Some(data);
        self
    }
    /// Add an additional 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 = Store {
            config_account: self.config_account.expect("config_account is not set"),
        };
        let args = StoreInstructionArgs {
            keys: self.keys.clone().expect("keys is not set"),
            data: self.data.clone().expect("data is not set"),
        };

        accounts.instruction_with_remaining_accounts(args, &self.__remaining_accounts)
    }
}

/// `store` CPI accounts.
pub struct StoreCpiAccounts<'a, 'b> {
    /// The config account to be modified.
    /// Must sign during the first call to `store` to initialize the account,
    /// or if no signers are configured in the config data.
    pub config_account: (&'b solana_program::account_info::AccountInfo<'a>, bool),
}

/// `store` CPI instruction.
pub struct StoreCpi<'a, 'b> {
    /// The program to invoke.
    pub __program: &'b solana_program::account_info::AccountInfo<'a>,
    /// The config account to be modified.
    /// Must sign during the first call to `store` to initialize the account,
    /// or if no signers are configured in the config data.
    pub config_account: (&'b solana_program::account_info::AccountInfo<'a>, bool),
    /// The arguments for the instruction.
    pub __args: StoreInstructionArgs,
}

impl<'a, 'b> StoreCpi<'a, 'b> {
    pub fn new(
        program: &'b solana_program::account_info::AccountInfo<'a>,
        accounts: StoreCpiAccounts<'a, 'b>,
        args: StoreInstructionArgs,
    ) -> Self {
        Self {
            __program: program,
            config_account: accounts.config_account,
            __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(1 + remaining_accounts.len());
        accounts.push(solana_program::instruction::AccountMeta::new(
            *self.config_account.0.key,
            self.config_account.1,
        ));
        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 = borsh::to_vec(&StoreInstructionData::new()).unwrap();
        let mut args = borsh::to_vec(&self.__args).unwrap();
        data.append(&mut args);

        let instruction = solana_program::instruction::Instruction {
            program_id: crate::SOLANA_CONFIG_ID,
            accounts,
            data,
        };
        let mut account_infos = Vec::with_capacity(2 + remaining_accounts.len());
        account_infos.push(self.__program.clone());
        account_infos.push(self.config_account.0.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 `Store` via CPI.
///
/// ### Accounts:
///
///   0. `[writable, signer]` config_account
#[derive(Clone, Debug)]
pub struct StoreCpiBuilder<'a, 'b> {
    instruction: Box<StoreCpiBuilderInstruction<'a, 'b>>,
}

impl<'a, 'b> StoreCpiBuilder<'a, 'b> {
    pub fn new(program: &'b solana_program::account_info::AccountInfo<'a>) -> Self {
        let instruction = Box::new(StoreCpiBuilderInstruction {
            __program: program,
            config_account: None,
            keys: None,
            data: None,
            __remaining_accounts: Vec::new(),
        });
        Self { instruction }
    }
    /// The config account to be modified.
    /// Must sign during the first call to `store` to initialize the account,
    /// or if no signers are configured in the config data.
    #[inline(always)]
    pub fn config_account(
        &mut self,
        config_account: &'b solana_program::account_info::AccountInfo<'a>,
        as_signer: bool,
    ) -> &mut Self {
        self.instruction.config_account = Some((config_account, as_signer));
        self
    }
    #[inline(always)]
    pub fn keys(&mut self, keys: ConfigKeys) -> &mut Self {
        self.instruction.keys = Some(keys);
        self
    }
    #[inline(always)]
    pub fn data(&mut self, data: RemainderVec<u8>) -> &mut Self {
        self.instruction.data = Some(data);
        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 args = StoreInstructionArgs {
            keys: self.instruction.keys.clone().expect("keys is not set"),
            data: self.instruction.data.clone().expect("data is not set"),
        };
        let instruction = StoreCpi {
            __program: self.instruction.__program,

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

#[derive(Clone, Debug)]
struct StoreCpiBuilderInstruction<'a, 'b> {
    __program: &'b solana_program::account_info::AccountInfo<'a>,
    config_account: Option<(&'b solana_program::account_info::AccountInfo<'a>, bool)>,
    keys: Option<ConfigKeys>,
    data: Option<RemainderVec<u8>>,
    /// Additional instruction accounts `(AccountInfo, is_writable, is_signer)`.
    __remaining_accounts: Vec<(
        &'b solana_program::account_info::AccountInfo<'a>,
        bool,
        bool,
    )>,
}