use pinocchio::{
account_info::AccountInfo,
instruction::{AccountMeta, Instruction, Signer},
program::invoke_signed,
ProgramResult,
};
pub struct WithdrawNonceAccount<'a> {
pub account: &'a AccountInfo,
pub recipient: &'a AccountInfo,
pub recent_blockhashes_sysvar: &'a AccountInfo,
pub rent_sysvar: &'a AccountInfo,
pub authority: &'a AccountInfo,
pub lamports: u64,
}
impl WithdrawNonceAccount<'_> {
#[inline(always)]
pub fn invoke(&self) -> ProgramResult {
self.invoke_signed(&[])
}
pub fn invoke_signed(&self, signers: &[Signer]) -> ProgramResult {
let account_metas: [AccountMeta; 5] = [
AccountMeta::writable(self.account.key()),
AccountMeta::writable(self.recipient.key()),
AccountMeta::readonly(self.recent_blockhashes_sysvar.key()),
AccountMeta::readonly(self.rent_sysvar.key()),
AccountMeta::readonly_signer(self.authority.key()),
];
let mut instruction_data = [0; 12];
instruction_data[0] = 5;
instruction_data[4..12].copy_from_slice(&self.lamports.to_le_bytes());
let instruction = Instruction {
program_id: &crate::ID,
accounts: &account_metas,
data: &instruction_data,
};
invoke_signed(
&instruction,
&[
self.account,
self.recipient,
self.recent_blockhashes_sysvar,
self.rent_sysvar,
self.authority,
],
signers,
)
}
}