use pinocchio::{
account_info::AccountInfo,
instruction::{AccountMeta, Instruction, Signer},
program::invoke_signed,
pubkey::Pubkey,
ProgramResult,
};
pub struct InitializeNonceAccount<'a, 'b> {
pub account: &'a AccountInfo,
pub recent_blockhashes_sysvar: &'a AccountInfo,
pub rent_sysvar: &'a AccountInfo,
pub authority: &'b Pubkey,
}
impl InitializeNonceAccount<'_, '_> {
#[inline(always)]
pub fn invoke(&self) -> ProgramResult {
self.invoke_signed(&[])
}
pub fn invoke_signed(&self, signers: &[Signer]) -> ProgramResult {
let account_metas: [AccountMeta; 3] = [
AccountMeta::writable(self.account.key()),
AccountMeta::readonly(self.recent_blockhashes_sysvar.key()),
AccountMeta::readonly(self.rent_sysvar.key()),
];
let mut instruction_data = [0; 36];
instruction_data[0] = 6;
instruction_data[4..36].copy_from_slice(self.authority);
let instruction = Instruction {
program_id: &crate::ID,
accounts: &account_metas,
data: &instruction_data,
};
invoke_signed(
&instruction,
&[
self.account,
self.recent_blockhashes_sysvar,
self.rent_sysvar,
],
signers,
)
}
}