Detect legacy programs upfront

This commit is contained in:
Greg Fitzgerald
2018-11-23 16:53:36 -07:00
parent 30cdd85028
commit 6fc02b7424

View File

@ -790,6 +790,13 @@ impl Bank {
Ok(accounts) 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 /// Process an instruction
/// This method calls the instruction's program entry pont method /// This method calls the instruction's program entry pont method
fn process_instruction( fn process_instruction(
@ -802,18 +809,19 @@ impl Bank {
// Call the contract method // Call the contract method
// It's up to the contract to implement its own rules on moving funds // It's up to the contract to implement its own rules on moving funds
if system_program::check_id(&program_id) { if Self::is_legacy_program(&program_id) {
system_program::process(&tx, instruction_index, program_accounts) let res = if system_program::check_id(&program_id) {
.map_err(|err| BankError::ProgramError(instruction_index as u8, err))?; system_program::process(&tx, instruction_index, program_accounts)
} else if budget_program::check_id(&program_id) { } else if budget_program::check_id(&program_id) {
budget_program::process(&tx, instruction_index, program_accounts) 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) {
} else if storage_program::check_id(&program_id) { storage_program::process(&tx, instruction_index, program_accounts)
storage_program::process(&tx, instruction_index, program_accounts) } else if vote_program::check_id(&program_id) {
.map_err(|err| BankError::ProgramError(instruction_index as u8, err))?; vote_program::process(&tx, instruction_index, program_accounts)
} else if vote_program::check_id(&program_id) { } else {
vote_program::process(&tx, instruction_index, program_accounts) unreachable!();
.map_err(|err| BankError::ProgramError(instruction_index as u8, err))?; };
res.map_err(|err| BankError::ProgramError(instruction_index as u8, err))?;
} else { } else {
let mut accounts = self.load_executable_accounts(tx.program_ids[instruction_index])?; let mut accounts = self.load_executable_accounts(tx.program_ids[instruction_index])?;
let mut keyed_accounts = create_keyed_accounts(&mut accounts); let mut keyed_accounts = create_keyed_accounts(&mut accounts);