fn verify_and_update(
        message: &Message,
        instruction: &CompiledInstruction,
        pre_accounts: &mut [PreAccount],
        accounts: &[Rc<RefCell<Account>>],
        program_id: &Pubkey,
        rent: &Rent,
    ) -> Result<(), InstructionError> {
        // Verify the per-account instruction results
        let (mut pre_sum, mut post_sum) = (0_u128, 0_u128);
        let mut work = |_unique_index: usize, account_index: usize| {
            let key = &message.account_keys[account_index];
            let account = &accounts[account_index];
            // Find the matching PreAccount
            for pre_account in pre_accounts.iter_mut() {
                if *key == pre_account.key() {
                    // Verify account has no outstanding references and take one
                    let account = account
                        .try_borrow_mut()
                        .map_err(|_| InstructionError::AccountBorrowOutstanding)?;

                    pre_account.verify(&program_id, &rent, &account)?;
                    pre_sum += u128::from(pre_account.lamports());
                    post_sum += u128::from(account.lamports);

                    pre_account.update(&account);

                    return Ok(());
                }
            }
            Err(InstructionError::MissingAccount)
        };
        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 a cross-program instruction
Verify the results of a cross-program instruction
Verify the results of a cross - program instruction
fn verify_and_update(
        message: &Message,
        instruction: &CompiledInstruction,
        pre_accounts: &mut [PreAccount],
        accounts: &[Rc<RefCell<Account>>],
        program_id: &Pubkey,
        rent: &Rent,
    ) -> Result<(), InstructionError> {
        // Verify the per-account instruction results
        let (mut pre_sum, mut post_sum) = (0_u128, 0_u128);
        let mut work = |_unique_index: usize, account_index: usize| {
            let key = &message.account_keys[account_index];
            let account = &accounts[account_index];
            // Find the matching PreAccount
            for pre_account in pre_accounts.iter_mut() {
                if *key == pre_account.key() {
                    // Verify account has no outstanding references and take one
                    let account = account
                        .try_borrow_mut()
                        .map_err(|_| InstructionError::AccountBorrowOutstanding)?;
                    pre_account.verify(&program_id, &rent, &account)?;
                    pre_sum += u128::from(pre_account.lamports());
                    post_sum += u128::from(account.lamports);
                    pre_account.update(&account);
                    return Ok(());
                }
            }
            Err(InstructionError::MissingAccount)
        };
        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(())
    }
fn verify_and_update ( message : & Message , instruction : & CompiledInstruction , pre_accounts : & mut [ PreAccount ] , accounts : & [ Rc < RefCell < Account > > ] , program_id : & Pubkey , rent : & Rent , ) -> Result < ( ) , InstructionError > { // Verify the per-account instruction results let ( mut pre_sum , mut post_sum ) = ( 0_u128 , 0_u128 ) ; let mut work = | _unique_index : usize , account_index : usize | { let key = & message . account_keys [ account_index ] ; let account = & accounts [ account_index ] ; // Find the matching PreAccount for pre_account in pre_accounts . iter_mut ( ) { if * key == pre_account . key ( ) { // Verify account has no outstanding references and take one let account = account . try_borrow_mut ( ) . map_err ( | _ | InstructionError :: AccountBorrowOutstanding ) ? ; pre_account . verify ( & program_id , & rent , & account ) ? ; pre_sum += u128 :: from ( pre_account . lamports ( ) ) ; post_sum += u128 :: from ( account . lamports ) ; pre_account . update ( & account ) ; return Ok ( ( ) ) ; } } Err ( InstructionError :: MissingAccount ) } ; 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 a cross-program instruction
Verify the results of a cross - program instruction
message
&Message
instruction
&CompiledInstruction
pre_accounts
&mut [PreAccount]
accounts
&[Rc<RefCell<Account>>]
program_id
&Pubkey
rent
&Rent
message
&Message
instruction
&CompiledInstruction
pre_accounts
&mut [PreAccount]
accounts
&[Rc<RefCell<Account>>]
program_id
&Pubkey
rent
&Rent