mirror of
https://github.com/aljazceru/cdk.git
synced 2025-12-25 08:35:09 +01:00
Merge pull request #574 from ok300/ok300-address-wallet-todos
Align various wallet.balance() methods
This commit is contained in:
@@ -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<HashMap<CurrencyUnit, Amount>, 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<Amount, Error> {
|
||||
Ok(self.get_pending_proofs().await?.total_amount()?)
|
||||
}
|
||||
|
||||
/// Total reserved balance
|
||||
#[instrument(skip(self))]
|
||||
pub async fn total_reserved_balance(&self) -> Result<HashMap<CurrencyUnit, Amount>, 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<Amount, Error> {
|
||||
Ok(self.get_reserved_proofs().await?.total_amount()?)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user