|
@@ -136,6 +136,41 @@ impl Wallet {
|
|
Ok(())
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// Total Balance of wallet for given unit
|
|
|
|
+ #[instrument(skip(self))]
|
|
|
|
+ pub async fn unit_balance(&self, unit: CurrencyUnit) -> Result<Amount, Error> {
|
|
|
|
+ let balance = match self
|
|
|
|
+ .localstore
|
|
|
|
+ .get_proofs(None, Some(unit), Some(vec![State::Unspent]), None)
|
|
|
|
+ .await?
|
|
|
|
+ {
|
|
|
|
+ Some(proofs) => proofs.iter().map(|p| p.proof.amount).sum(),
|
|
|
|
+ None => Amount::ZERO,
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ Ok(balance)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /// Total pending and reserved balance of wallet for given unit
|
|
|
|
+ #[instrument(skip(self))]
|
|
|
|
+ pub async fn pending_unit_balance(&self, unit: CurrencyUnit) -> Result<Amount, Error> {
|
|
|
|
+ let balance = match self
|
|
|
|
+ .localstore
|
|
|
|
+ .get_proofs(
|
|
|
|
+ None,
|
|
|
|
+ Some(unit),
|
|
|
|
+ Some(vec![State::Pending, State::Reserved]),
|
|
|
|
+ None,
|
|
|
|
+ )
|
|
|
|
+ .await?
|
|
|
|
+ {
|
|
|
|
+ Some(proofs) => proofs.iter().map(|p| p.proof.amount).sum(),
|
|
|
|
+ None => Amount::ZERO,
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ Ok(balance)
|
|
|
|
+ }
|
|
|
|
+
|
|
/// Total Balance of wallet
|
|
/// Total Balance of wallet
|
|
#[instrument(skip(self))]
|
|
#[instrument(skip(self))]
|
|
pub async fn total_balance(&self) -> Result<HashMap<CurrencyUnit, Amount>, Error> {
|
|
pub async fn total_balance(&self) -> Result<HashMap<CurrencyUnit, Amount>, Error> {
|