feat(wallet): total balance

This commit is contained in:
thesimplekid
2024-05-10 11:41:12 +01:00
parent 1105dfab48
commit f7b79e9e8e

View File

@@ -124,6 +124,22 @@ impl Wallet {
self.mnemonic.clone()
}
/// Total Balance of wallet
pub async fn total_balance(&self) -> Result<Amount, Error> {
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<HashMap<UncheckedUrl, Amount>, Error> {
let mints = self.localstore.get_mints().await?;