From 6fc02b7424ffe258b73d34f7615057bfcd66b214 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Fri, 23 Nov 2018 16:53:36 -0700 Subject: [PATCH] Detect legacy programs upfront --- src/bank.rs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/bank.rs b/src/bank.rs index be44b23e71..160ec89bba 100644 --- a/src/bank.rs +++ b/src/bank.rs @@ -790,6 +790,13 @@ impl Bank { Ok(accounts) } + fn is_legacy_program(program_id: &Pubkey) -> bool { + system_program::check_id(program_id) + || budget_program::check_id(program_id) + || storage_program::check_id(program_id) + || vote_program::check_id(program_id) + } + /// Process an instruction /// This method calls the instruction's program entry pont method fn process_instruction( @@ -802,18 +809,19 @@ impl Bank { // Call the contract method // It's up to the contract to implement its own rules on moving funds - if system_program::check_id(&program_id) { - system_program::process(&tx, instruction_index, program_accounts) - .map_err(|err| BankError::ProgramError(instruction_index as u8, err))?; - } else if budget_program::check_id(&program_id) { - budget_program::process(&tx, instruction_index, program_accounts) - .map_err(|err| BankError::ProgramError(instruction_index as u8, err))?; - } else if storage_program::check_id(&program_id) { - storage_program::process(&tx, instruction_index, program_accounts) - .map_err(|err| BankError::ProgramError(instruction_index as u8, err))?; - } else if vote_program::check_id(&program_id) { - vote_program::process(&tx, instruction_index, program_accounts) - .map_err(|err| BankError::ProgramError(instruction_index as u8, err))?; + if Self::is_legacy_program(&program_id) { + let res = if system_program::check_id(&program_id) { + system_program::process(&tx, instruction_index, program_accounts) + } else if budget_program::check_id(&program_id) { + budget_program::process(&tx, instruction_index, program_accounts) + } else if storage_program::check_id(&program_id) { + storage_program::process(&tx, instruction_index, program_accounts) + } else if vote_program::check_id(&program_id) { + vote_program::process(&tx, instruction_index, program_accounts) + } else { + unreachable!(); + }; + res.map_err(|err| BankError::ProgramError(instruction_index as u8, err))?; } else { let mut accounts = self.load_executable_accounts(tx.program_ids[instruction_index])?; let mut keyed_accounts = create_keyed_accounts(&mut accounts);