Add credit-only info to AccountMetadata (#4405)

* Add credit-only flag to AccountMeta, default to false

* Sort keys by is_credit_only within signed/unsigned groupings

* Process and de-dupe program keys along with other account keys

* Add message helper functions

* Fix test

* Improve comment

* s/is_credit_only/is_debitable

* Add InstructionKeys helper struct, and simplify program_position method
This commit is contained in:
Tyera Eulberg
2019-05-23 18:19:53 -04:00
committed by GitHub
parent 0b892b2579
commit 943cd0a24a
6 changed files with 254 additions and 32 deletions

View File

@@ -626,7 +626,7 @@ mod tests {
let accounts: Vec<(Pubkey, Account)> = Vec::new();
let mut error_counters = ErrorCounters::default();
let instructions = vec![CompiledInstruction::new(1, &(), vec![0])];
let instructions = vec![CompiledInstruction::new(0, &(), vec![0])];
let tx = Transaction::new_with_compiled_instructions::<Keypair>(
&[],
&[],

View File

@@ -221,10 +221,15 @@ impl MessageProcessor {
tick_height: u64,
) -> Result<(), TransactionError> {
for (instruction_index, instruction) in message.instructions.iter().enumerate() {
let executable_accounts = &mut loaders
[message.program_index_in_program_ids(instruction.program_ids_index) as usize];
let executable_index = message
.program_position(instruction.program_ids_index as usize)
.ok_or(TransactionError::InvalidAccountIndex)?;
let executable_accounts = &mut loaders[executable_index];
let mut program_accounts = get_subset_unchecked_mut(accounts, &instruction.accounts)
.map_err(|err| TransactionError::InstructionError(instruction_index as u8, err))?;
// TODO: `get_subset_unchecked_mut` panics on an index out of bounds if an executable
// account is also included as a regular account for an instruction, because the
// executable account is not passed in as part of the accounts slice
self.execute_instruction(
message,
instruction,