Skip to content

Commit e4e9837

Browse files
committed
implement invoke_signed_checked
1 parent 48f6f6f commit e4e9837

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

programs/system/src/instructions/create_account_checked.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,30 @@ pub struct CreateAccountChecked<'a> {
3333
impl CreateAccountChecked<'_> {
3434
#[inline(always)]
3535
pub fn invoke(&self) -> ProgramResult {
36-
self.invoke_signed(&[])
36+
self.invoke_signed_checked(&[])
3737
}
3838

3939
#[inline(always)]
40-
pub fn invoke_signed(&self, signers: &[Signer]) -> ProgramResult {
41-
// getting lamports from rent
40+
pub fn invoke_signed_checked(&self, signers: &[Signer]) -> ProgramResult {
41+
// Get lamports from rent
4242
let rent = Rent::from_account_info(self.sysvar_rent_account)?;
4343
let lamports = rent.minimum_balance(self.space as usize);
4444

45-
// checking if the funding account has enough lamports
45+
// Check if the funding account has enough lamports
4646
if self.from.lamports() < lamports {
4747
return Err(ProgramError::InsufficientFunds);
4848
}
4949

50-
// checking if the new account is already initialized
50+
// Check if the new account is already initialized
5151
if !self.to.data_is_empty() {
5252
return Err(ProgramError::InvalidAccountData);
5353
}
5454

55+
self.invoke_signed(signers, lamports)
56+
}
57+
58+
#[inline(always)]
59+
fn invoke_signed(&self, signers: &[Signer], lamports: u64) -> ProgramResult {
5560
// account metadata
5661
let account_metas: [AccountMeta; 2] = [
5762
AccountMeta::writable_signer(self.from.key()),

programs/system/src/instructions/create_account_with_seed_checked.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,35 @@ pub struct CreateAccountWithSeedChecked<'a, 'b, 'c> {
4545
impl CreateAccountWithSeed<'_, '_, '_> {
4646
#[inline(always)]
4747
pub fn invoke(&self) -> ProgramResult {
48-
self.invoke_signed(&[])
48+
self.invoke_signed_checked(&[])
4949
}
5050

5151
#[inline(always)]
52-
pub fn invoke_signed(&self, signers: &[Signer]) -> ProgramResult {
53-
// checking if the seed is valid
52+
pub fn invoke_signed_checked(&self, signers: &[Signer]) -> ProgramResult {
53+
// Get lamports from rent
54+
let rent = Rent::from_account_info(self.sysvar_rent_account)?;
55+
let lamports = rent.minimum_balance(self.space as usize);
56+
57+
// Check if the seed is valid
5458
if self.seed.len() > MAX_SEED_LEN {
5559
return Err(ProgramError::InvalidInstructionData);
5660
}
5761

58-
// getting lamports from rent
59-
let rent = Rent::from_account_info(self.sysvar_rent_account)?;
60-
let lamports = rent.minimum_balance(self.space as usize);
61-
62-
// checking if the funding account has enough lamports
62+
// Check if the funding account has enough lamports
6363
if self.from.lamports() < lamports {
6464
return Err(ProgramError::InsufficientFunds);
6565
}
6666

67-
// checking if the new account is already initialized
67+
// Check if the new account is already initialized
6868
if !self.to.data_is_empty() {
6969
return Err(ProgramError::InvalidAccountData);
7070
}
7171

72+
self.invoke_signed(signers, lamports)
73+
}
74+
75+
#[inline(always)]
76+
fn invoke_signed(&self, signers: &[Signer], lamports: u64) -> ProgramResult {
7277
// account metadata
7378
let account_metas: [AccountMeta; 3] = [
7479
AccountMeta::writable_signer(self.from.key()),

0 commit comments

Comments
 (0)