From c97547a63e0a438aee190f3f6518cb6c23ce17c8 Mon Sep 17 00:00:00 2001 From: Matthew Date: Wed, 29 Nov 2023 16:52:49 -0600 Subject: [PATCH] feat: add sent_and_received method on wallet --- bdk-ffi/src/bdk.udl | 7 +++++++ bdk-ffi/src/lib.rs | 1 + bdk-ffi/src/wallet.rs | 12 +++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index 58acc0f5..bfffeceb 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -95,6 +95,8 @@ interface Wallet { [Throws=BdkError] boolean sign(PartiallySignedTransaction psbt); + + SentAndReceivedValues sent_and_received([ByRef] Transaction tx); }; interface Update {}; @@ -235,6 +237,11 @@ dictionary ScriptAmount { u64 amount; }; +dictionary SentAndReceivedValues { + u64 sent; + u64 received; +}; + // ------------------------------------------------------------------------ // bdk crate - bitcoin re-exports // ------------------------------------------------------------------------ diff --git a/bdk-ffi/src/lib.rs b/bdk-ffi/src/lib.rs index 185529b4..84fe38da 100644 --- a/bdk-ffi/src/lib.rs +++ b/bdk-ffi/src/lib.rs @@ -17,6 +17,7 @@ use crate::keys::DerivationPath; use crate::keys::DescriptorPublicKey; use crate::keys::DescriptorSecretKey; use crate::keys::Mnemonic; +use crate::wallet::SentAndReceivedValues; use crate::wallet::TxBuilder; use crate::wallet::Update; use crate::wallet::Wallet; diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index 5778e55f..843b8977 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -1,4 +1,4 @@ -use crate::bitcoin::{OutPoint, PartiallySignedTransaction}; +use crate::bitcoin::{OutPoint, PartiallySignedTransaction, Transaction}; use crate::descriptor::Descriptor; use crate::{AddressIndex, AddressInfo, Network, ScriptAmount}; use crate::{Balance, Script}; @@ -92,6 +92,16 @@ impl Wallet { .sign(&mut psbt, SignOptions::default()) .map_err(|e| BdkError::Generic(e.to_string())) } + + pub fn sent_and_received(&self, tx: &Transaction) -> SentAndReceivedValues { + let (sent, received): (u64, u64) = self.get_wallet().sent_and_received(&tx.clone().into()); + SentAndReceivedValues { sent, received } + } +} + +pub struct SentAndReceivedValues { + pub sent: u64, + pub received: u64, } pub struct Update(pub(crate) BdkUpdate);