From f7b79e9e8e0b162a64ed540351a85f5ecadff5aa Mon Sep 17 00:00:00 2001 From: thesimplekid Date: Fri, 10 May 2024 11:41:12 +0100 Subject: [PATCH] feat(wallet): total balance --- crates/cdk/src/wallet.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/cdk/src/wallet.rs b/crates/cdk/src/wallet.rs index aeef042e..ab7c6e98 100644 --- a/crates/cdk/src/wallet.rs +++ b/crates/cdk/src/wallet.rs @@ -124,6 +124,22 @@ impl Wallet { self.mnemonic.clone() } + /// Total Balance of wallet + pub async fn total_balance(&self) -> Result { + let mints = self.localstore.get_mints().await?; + let mut balance = Amount::ZERO; + + for (mint, _) in mints { + if let Some(proofs) = self.localstore.get_proofs(mint.clone()).await? { + let amount = proofs.iter().map(|p| p.amount).sum(); + + balance += amount; + } + } + + Ok(balance) + } + pub async fn mint_balances(&self) -> Result, Error> { let mints = self.localstore.get_mints().await?;