From 82ad50350595214cb61d0fbedb7ec0555765066c Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Mon, 3 Feb 2025 08:24:06 +0100 Subject: [PATCH] Align various wallet.balance() methods --- crates/cdk/src/wallet/balance.rs | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) 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()?) } }