pub fn verify(
        message: &Message,
        instruction: &CompiledInstruction,
        pre_accounts: &[PreAccount],
        executable_accounts: &[(Pubkey, RefCell<Account>)],
        accounts: &[Rc<RefCell<Account>>],
        rent: &Rent,
    ) -> Result<(), InstructionError> {
        // Verify all executable accounts have zero outstanding refs
        Self::verify_account_references(executable_accounts)?;

        // Verify the per-account instruction results
        let (mut pre_sum, mut post_sum) = (0_u128, 0_u128);
        {
            let program_id = instruction.program_id(&message.account_keys);
            let mut work = |unique_index: usize, account_index: usize| {
                // Verify account has no outstanding references and take one
                let account = accounts[account_index]
                    .try_borrow_mut()
                    .map_err(|_| InstructionError::AccountBorrowOutstanding)?;
                pre_accounts[unique_index].verify(&program_id, rent, &account)?;
                pre_sum += u128::from(pre_accounts[unique_index].lamports());
                post_sum += u128::from(account.lamports);
                Ok(())
            };
            instruction.visit_each_account(&mut work)?;
        }

        // Verify that the total sum of all the lamports did not change
        if pre_sum != post_sum {
            return Err(InstructionError::UnbalancedInstruction);
        }
        Ok(())
    }
/// Verify the results of an instruction
Verify the results of an instruction
Verify the results of an instruction
pub fn verify(
        message: &Message,
        instruction: &CompiledInstruction,
        pre_accounts: &[PreAccount],
        executable_accounts: &[(Pubkey, RefCell<Account>)],
        accounts: &[Rc<RefCell<Account>>],
        rent: &Rent,
    ) -> Result<(), InstructionError> {
        // Verify all executable accounts have zero outstanding refs
        Self::verify_account_references(executable_accounts)?;
        // Verify the per-account instruction results
        let (mut pre_sum, mut post_sum) = (0_u128, 0_u128);
        {
            let program_id = instruction.program_id(&message.account_keys);
            let mut work = |unique_index: usize, account_index: usize| {
                // Verify account has no outstanding references and take one
                let account = accounts[account_index]
                    .try_borrow_mut()
                    .map_err(|_| InstructionError::AccountBorrowOutstanding)?;
                pre_accounts[unique_index].verify(&program_id, rent, &account)?;
                pre_sum += u128::from(pre_accounts[unique_index].lamports());
                post_sum += u128::from(account.lamports);
                Ok(())
            };
            instruction.visit_each_account(&mut work)?;
        }
        // Verify that the total sum of all the lamports did not change
        if pre_sum != post_sum {
            return Err(InstructionError::UnbalancedInstruction);
        }
        Ok(())
    }
pub fn verify ( message : & Message , instruction : & CompiledInstruction , pre_accounts : & [ PreAccount ] , executable_accounts : & [ ( Pubkey , RefCell < Account > ) ] , accounts : & [ Rc < RefCell < Account > > ] , rent : & Rent , ) -> Result < ( ) , InstructionError > { // Verify all executable accounts have zero outstanding refs Self :: verify_account_references ( executable_accounts ) ? ; // Verify the per-account instruction results let ( mut pre_sum , mut post_sum ) = ( 0_u128 , 0_u128 ) ; { let program_id = instruction . program_id ( & message . account_keys ) ; let mut work = | unique_index : usize , account_index : usize | { // Verify account has no outstanding references and take one let account = accounts [ account_index ] . try_borrow_mut ( ) . map_err ( | _ | InstructionError :: AccountBorrowOutstanding ) ? ; pre_accounts [ unique_index ] . verify ( & program_id , rent , & account ) ? ; pre_sum += u128 :: from ( pre_accounts [ unique_index ] . lamports ( ) ) ; post_sum += u128 :: from ( account . lamports ) ; Ok ( ( ) ) } ; instruction . visit_each_account ( & mut work ) ? ; } // Verify that the total sum of all the lamports did not change if pre_sum != post_sum { return Err ( InstructionError :: UnbalancedInstruction ) ; } Ok ( ( ) ) }
Verify the results of an instruction
Verify the results of an instruction
message
&Message
instruction
&CompiledInstruction
pre_accounts
&[PreAccount]
executable_accounts
&[(Pubkey, RefCell<Account>)]
accounts
&[Rc<RefCell<Account>>]
rent
&Rent
message
&Message
instruction
&CompiledInstruction
pre_accounts
&[PreAccount]
executable_accounts
&[(Pubkey, RefCell<Account>)]
accounts
&[Rc<RefCell<Account>>]
rent
&Rent