Have Coin::get_outputs return by transaction, not by block

This commit is contained in:
Luke Parker 2023-01-07 03:13:54 -05:00
parent b303649f9d
commit 9662e9e1af
No known key found for this signature in database
2 changed files with 26 additions and 18 deletions

View file

@ -69,7 +69,7 @@ pub trait Coin {
&self, &self,
block: &Self::Block, block: &Self::Block,
key: <Self::Curve as Ciphersuite>::G, key: <Self::Curve as Ciphersuite>::G,
) -> Result<Vec<Self::Output>, CoinError>; ) -> Result<Vec<Vec<Self::Output>>, CoinError>;
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
async fn prepare_send( async fn prepare_send(

View file

@ -169,25 +169,33 @@ impl Coin for Monero {
&self, &self,
block: &Self::Block, block: &Self::Block,
key: dfg::EdwardsPoint, key: dfg::EdwardsPoint,
) -> Result<Vec<Self::Output>, CoinError> { ) -> Result<Vec<Vec<Self::Output>>, CoinError> {
Ok( let mut transactions = self
self
.scanner(key) .scanner(key)
.scan(&self.rpc, block) .scan(&self.rpc, block)
.await .await
.map_err(|_| CoinError::ConnectionError)? .map_err(|_| CoinError::ConnectionError)?
.iter() .iter()
.flat_map(|outputs| outputs.not_locked()) .map(|outputs| outputs.not_locked())
.collect::<Vec<_>>();
// This should be pointless as we shouldn't be able to scan for any other subaddress // This should be pointless as we shouldn't be able to scan for any other subaddress
// This just ensures nothing invalid makes it in // This just ensures nothing invalid makes it through
.filter_map(|output| { for transaction in transactions.iter_mut() {
if ![EXTERNAL_SUBADDRESS, BRANCH_SUBADDRESS, CHANGE_SUBADDRESS] *transaction = transaction
.drain(..)
.filter(|output| {
[EXTERNAL_SUBADDRESS, BRANCH_SUBADDRESS, CHANGE_SUBADDRESS]
.contains(&output.output.metadata.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(), .collect(),
) )
} }