Use count instead of iter.map(|_| 1).sum

Also replaces the expectation the miner TX was first with a check for
Input::Gen.
This commit is contained in:
Luke Parker
2022-12-24 15:17:49 -05:00
parent 445bb3786e
commit 35a4f5bf9f

View File

@@ -7,7 +7,7 @@ use curve25519_dalek::{constants::ED25519_BASEPOINT_TABLE, scalar::Scalar, edwar
use crate::{ use crate::{
Commitment, Commitment,
serialize::{read_byte, read_u32, read_u64, read_bytes, read_scalar, read_point, read_raw_vec}, serialize::{read_byte, read_u32, read_u64, read_bytes, read_scalar, read_point, read_raw_vec},
transaction::{Timelock, Transaction}, transaction::{Input, Timelock, Transaction},
block::Block, block::Block,
rpc::{Rpc, RpcError}, rpc::{Rpc, RpcError},
wallet::{PaymentId, Extra, Scanner, uniqueness, shared_key, amount_decryption, commitment_mask}, wallet::{PaymentId, Extra, Scanner, uniqueness, shared_key, amount_decryption, commitment_mask},
@@ -373,18 +373,22 @@ impl Scanner {
}; };
let mut res = vec![]; let mut res = vec![];
for (i, tx) in txs.drain(..).enumerate() { for tx in txs.drain(..) {
if let Some(timelock) = map(self.scan_transaction(&tx), index) { if let Some(timelock) = map(self.scan_transaction(&tx), index) {
res.push(timelock); res.push(timelock);
} }
index += tx index += u64::try_from(
.prefix tx.prefix
.outputs .outputs
.iter() .iter()
// Filter to miner TX outputs/0-amount outputs since we're tacking the 0-amount index // Filter to miner TX outputs/0-amount outputs since we're tacking the 0-amount index
.filter_map(|output| Some(1).filter(|_| (i == 0) || (output.amount == 0))) // This will fail to scan blocks containing pre-RingCT miner TXs
// Since we can't get the length of an iterator, map each value to 1 and sum .filter(|output| {
.sum::<u64>(); matches!(tx.prefix.inputs.get(0), Some(Input::Gen(..))) || (output.amount == 0)
})
.count(),
)
.unwrap()
} }
Ok(res) Ok(res)
} }