diff --git a/transaction-status/src/token_balances.rs b/transaction-status/src/token_balances.rs index 03c3a16c1efba3..8368bdc92b1314 100644 --- a/transaction-status/src/token_balances.rs +++ b/transaction-status/src/token_balances.rs @@ -59,25 +59,22 @@ pub fn collect_token_balances( for (_, transaction) in OrderedIterator::new(batch.transactions(), batch.iteration_order()) { let account_keys = &transaction.message.account_keys; - let mut fetch_account_hash: HashMap = HashMap::new(); - for instruction in transaction.message.instructions.iter() { - if let Some(program_id) = account_keys.get(instruction.program_id_index as usize) { - if is_token_program(&program_id) { - for account in &instruction.accounts { - fetch_account_hash.insert(*account, true); - } - } - } - } + let has_token_program = account_keys.iter().any(|p| is_token_program(p)); let mut transaction_balances: Vec = vec![]; - for index in fetch_account_hash.keys() { - if let Some(account_id) = account_keys.get(*index as usize) { + if has_token_program { + for (index, account_id) in account_keys.iter().enumerate() { + if is_token_program(account_id) + || transaction.message.program_ids().contains(&account_id) + { + continue; + } + if let Some((mint, ui_token_amount)) = collect_token_balance_from_account(&bank, account_id, &mut mint_decimals) { transaction_balances.push(TransactionTokenBalance { - account_index: *index, + account_index: index as u8, mint, ui_token_amount, });