@@ -45,30 +45,35 @@ pub struct CreateAccountWithSeedChecked<'a, 'b, 'c> {
4545impl 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