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:
parent
1c261d293f
commit
61112d4826
|
@ -59,25 +59,22 @@ pub fn collect_token_balances(
|
||||||
|
|
||||||
for (_, transaction) in OrderedIterator::new(batch.transactions(), batch.iteration_order()) {
|
for (_, transaction) in OrderedIterator::new(batch.transactions(), batch.iteration_order()) {
|
||||||
let account_keys = &transaction.message.account_keys;
|
let account_keys = &transaction.message.account_keys;
|
||||||
let mut fetch_account_hash: HashMap<u8, bool> = HashMap::new();
|
let has_token_program = account_keys.iter().any(|p| is_token_program(p));
|
||||||
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 mut transaction_balances: Vec<TransactionTokenBalance> = vec![];
|
let mut transaction_balances: Vec<TransactionTokenBalance> = vec![];
|
||||||
for index in fetch_account_hash.keys() {
|
if has_token_program {
|
||||||
if let Some(account_id) = account_keys.get(*index as usize) {
|
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)) =
|
if let Some((mint, ui_token_amount)) =
|
||||||
collect_token_balance_from_account(&bank, account_id, &mut mint_decimals)
|
collect_token_balance_from_account(&bank, account_id, &mut mint_decimals)
|
||||||
{
|
{
|
||||||
transaction_balances.push(TransactionTokenBalance {
|
transaction_balances.push(TransactionTokenBalance {
|
||||||
account_index: *index,
|
account_index: index as u8,
|
||||||
mint,
|
mint,
|
||||||
ui_token_amount,
|
ui_token_amount,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue