fix: compute pre/post token balances on all accounts if token program 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
This commit is contained in:
Josh 2021-03-16 09:49:22 -07:00 committed by GitHub
parent 1c261d293f
commit 61112d4826
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 13 deletions

View File

@ -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,
});