diff --git a/src/device.rs b/src/device.rs index 317aeff..d256911 100644 --- a/src/device.rs +++ b/src/device.rs @@ -5,7 +5,7 @@ use tsify::Tsify; use wasm_bindgen::prelude::*; use sp_client::{ - bitcoin::{absolute::Height, secp256k1::PublicKey, OutPoint, Transaction, XOnlyPublicKey}, + bitcoin::{absolute::Height, secp256k1::PublicKey, Amount, OutPoint, Transaction, XOnlyPublicKey}, silentpayments::{ utils::receiving::calculate_ecdh_shared_secret, SilentPaymentAddress @@ -52,6 +52,12 @@ impl Device { &mut self.outputs } + pub fn get_balance(&self) -> Amount { + self.outputs.values() + .filter(|output| output.spend_status == OutputSpendStatus::Unspent) + .fold(Amount::ZERO, |acc, x| acc + x.amount) + } + pub fn update_outputs_with_transaction(&mut self, tx: &Transaction, blockheight: u32, partial_tweak: PublicKey) -> anyhow::Result> { // First check that we haven't already scanned this transaction let txid = tx.txid();