{ for (id, balance) in unallocated { if balance > 0 { *allocated[vout].entry(id).or_default() += balance; } } } } // update outpoint balances let mut buffer: Vec = Vec::new(); for (vout, balances) in allocated.into_iter().enumerate() { if balances.is_empty() { continue; } // increment burned balances if tx.output[vout].script_pubkey.is_op_return() { for (id, balance) in &balances { *burned.entry(*id).or_default() += balance; } continue; } buffer.clear(); let mut balances = balances.into_iter().collect::>(); // Sort balances by id so tests can assert balances in a fixed order balances.sort(); for (id, balance) in balances { varint::encode_to_vec(id, &mut buffer); varint::encode_to_vec(balance, &mut buffer); } self.outpoint_to_balances.insert( &OutPoint { txid, vout: vout.try_into().unwrap(),