Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
fix: compute pre/post token balances on all accounts if token program…
Browse files Browse the repository at this point in the history
… present (#15900)

* fix: compute pre/post token balances on all accounts if token program present

* fix: skip token program in balance query

* fix: prevent program ids from being collected
  • Loading branch information
oJshua authored Mar 16, 2021
1 parent 1c261d2 commit 61112d4
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions transaction-status/src/token_balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8, bool> = 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<TransactionTokenBalance> = 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,
});
Expand Down

0 comments on commit 61112d4

Please sign in to comment.