diff --git a/crates/cdk/src/wallet/balance.rs b/crates/cdk/src/wallet/balance.rs index 5b45ac48..ce095162 100644 --- a/crates/cdk/src/wallet/balance.rs +++ b/crates/cdk/src/wallet/balance.rs @@ -1,9 +1,6 @@ -use std::collections::HashMap; - use tracing::instrument; use crate::nuts::nut00::ProofsMethods; -use crate::nuts::CurrencyUnit; use crate::{Amount, Error, Wallet}; impl Wallet { @@ -15,29 +12,13 @@ impl Wallet { /// Total pending balance #[instrument(skip(self))] - pub async fn total_pending_balance(&self) -> Result, Error> { - let proofs = self.get_pending_proofs().await?; - - // TODO If only the proofs for this wallet's unit are retrieved, why build a map with key = unit? - let balances = proofs.iter().fold(HashMap::new(), |mut acc, proof| { - *acc.entry(self.unit.clone()).or_insert(Amount::ZERO) += proof.amount; - acc - }); - - Ok(balances) + pub async fn total_pending_balance(&self) -> Result { + Ok(self.get_pending_proofs().await?.total_amount()?) } /// Total reserved balance #[instrument(skip(self))] - pub async fn total_reserved_balance(&self) -> Result, Error> { - let proofs = self.get_reserved_proofs().await?; - - // TODO If only the proofs for this wallet's unit are retrieved, why build a map with key = unit? - let balances = proofs.iter().fold(HashMap::new(), |mut acc, proof| { - *acc.entry(self.unit.clone()).or_insert(Amount::ZERO) += proof.amount; - acc - }); - - Ok(balances) + pub async fn total_reserved_balance(&self) -> Result { + Ok(self.get_reserved_proofs().await?.total_amount()?) } }