use pinocchio::{
cpi::invoke,
instruction::{InstructionAccount, InstructionView},
AccountView, Address, ProgramResult,
};
pub struct InitializeNonceAccount<'a, 'b> {
pub account: &'a AccountView,
pub recent_blockhashes_sysvar: &'a AccountView,
pub rent_sysvar: &'a AccountView,
pub authority: &'b Address,
}
impl InitializeNonceAccount<'_, '_> {
#[inline(always)]
pub fn invoke(&self) -> ProgramResult {
let instruction_accounts: [InstructionAccount; 3] = [
InstructionAccount::writable(self.account.address()),
InstructionAccount::readonly(self.recent_blockhashes_sysvar.address()),
InstructionAccount::readonly(self.rent_sysvar.address()),
];
let mut instruction_data = [0; 36];
instruction_data[0] = 6;
instruction_data[4..36].copy_from_slice(self.authority.as_array());
let instruction = InstructionView {
program_id: &crate::ID,
accounts: &instruction_accounts,
data: &instruction_data,
};
invoke(
&instruction,
&[
self.account,
self.recent_blockhashes_sysvar,
self.rent_sysvar,
],
)
}
}