use pinocchio::{
account_info::AccountInfo,
instruction::{AccountMeta, Instruction, Signer},
program::invoke_signed,
ProgramResult,
};
pub struct Allocate<'a> {
pub account: &'a AccountInfo,
pub space: u64,
}
impl Allocate<'_> {
#[inline(always)]
pub fn invoke(&self) -> ProgramResult {
self.invoke_signed(&[])
}
#[inline(always)]
pub fn invoke_signed(&self, signers: &[Signer]) -> ProgramResult {
let account_metas: [AccountMeta; 1] = [AccountMeta::writable_signer(self.account.key())];
let mut instruction_data = [0; 12];
instruction_data[0] = 8;
instruction_data[4..12].copy_from_slice(&self.space.to_le_bytes());
let instruction = Instruction {
program_id: &crate::ID,
accounts: &account_metas,
data: &instruction_data,
};
invoke_signed(&instruction, &[self.account], signers)
}
}