mirror of
https://github.com/serai-dex/serai.git
synced 2024-11-17 01:17:36 +00:00
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:
parent
445bb3786e
commit
35a4f5bf9f
1 changed files with 14 additions and 10 deletions
|
@ -7,7 +7,7 @@ use curve25519_dalek::{constants::ED25519_BASEPOINT_TABLE, scalar::Scalar, edwar
|
|||
use crate::{
|
||||
Commitment,
|
||||
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,
|
||||
rpc::{Rpc, RpcError},
|
||||
wallet::{PaymentId, Extra, Scanner, uniqueness, shared_key, amount_decryption, commitment_mask},
|
||||
|
@ -373,18 +373,22 @@ impl Scanner {
|
|||
};
|
||||
|
||||
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) {
|
||||
res.push(timelock);
|
||||
}
|
||||
index += tx
|
||||
.prefix
|
||||
.outputs
|
||||
.iter()
|
||||
// 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)))
|
||||
// Since we can't get the length of an iterator, map each value to 1 and sum
|
||||
.sum::<u64>();
|
||||
index += u64::try_from(
|
||||
tx.prefix
|
||||
.outputs
|
||||
.iter()
|
||||
// Filter to miner TX outputs/0-amount outputs since we're tacking the 0-amount index
|
||||
// This will fail to scan blocks containing pre-RingCT miner TXs
|
||||
.filter(|output| {
|
||||
matches!(tx.prefix.inputs.get(0), Some(Input::Gen(..))) || (output.amount == 0)
|
||||
})
|
||||
.count(),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
Ok(res)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue