From 9662e9e1afc5ef80acaf5d5386d2bdaa587b6872 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Sat, 7 Jan 2023 03:13:54 -0500 Subject: [PATCH] Have Coin::get_outputs return by transaction, not by block --- processor/src/coin/mod.rs | 2 +- processor/src/coin/monero.rs | 42 +++++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/processor/src/coin/mod.rs b/processor/src/coin/mod.rs index 6cb19509..1bc609b2 100644 --- a/processor/src/coin/mod.rs +++ b/processor/src/coin/mod.rs @@ -69,7 +69,7 @@ pub trait Coin { &self, block: &Self::Block, key: ::G, - ) -> Result, CoinError>; + ) -> Result>, CoinError>; #[allow(clippy::too_many_arguments)] async fn prepare_send( diff --git a/processor/src/coin/monero.rs b/processor/src/coin/monero.rs index 1a132147..78a6751a 100644 --- a/processor/src/coin/monero.rs +++ b/processor/src/coin/monero.rs @@ -169,25 +169,33 @@ impl Coin for Monero { &self, block: &Self::Block, key: dfg::EdwardsPoint, - ) -> Result, CoinError> { - Ok( - self - .scanner(key) - .scan(&self.rpc, block) - .await - .map_err(|_| CoinError::ConnectionError)? - .iter() - .flat_map(|outputs| outputs.not_locked()) - // This should be pointless as we shouldn't be able to scan for any other subaddress - // This just ensures nothing invalid makes it in - .filter_map(|output| { - if ![EXTERNAL_SUBADDRESS, BRANCH_SUBADDRESS, CHANGE_SUBADDRESS] + ) -> Result>, CoinError> { + let mut transactions = self + .scanner(key) + .scan(&self.rpc, block) + .await + .map_err(|_| CoinError::ConnectionError)? + .iter() + .map(|outputs| outputs.not_locked()) + .collect::>(); + + // This should be pointless as we shouldn't be able to scan for any other subaddress + // This just ensures nothing invalid makes it through + for transaction in transactions.iter_mut() { + *transaction = transaction + .drain(..) + .filter(|output| { + [EXTERNAL_SUBADDRESS, BRANCH_SUBADDRESS, CHANGE_SUBADDRESS] .contains(&output.output.metadata.subaddress) - { - return None; - } - Some(Output::from(output)) }) + .collect(); + } + transactions = transactions.drain(..).filter(|outputs| !outputs.is_empty()).collect(); + + Ok( + transactions + .drain(..) + .map(|mut transaction| transaction.drain(..).map(Output::from).collect()) .collect(), ) }