Add get_balance to Device
This commit is contained in:
parent
6a2be13b7c
commit
b61cc90ede
@ -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<HashMap<OutPoint, OwnedOutput>> {
|
||||
// First check that we haven't already scanned this transaction
|
||||
let txid = tx.txid();
|
||||
|
Loading…
x
Reference in New Issue
Block a user