From 46e0324f28dbd5d508cea862edf201c28431ee25 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 924ccbc2..1229779e 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -107,6 +107,8 @@ interface Wallet { [Throws=BdkError] boolean sign(PartiallySignedTransaction psbt); + + SentAndReceivedValues sent_and_received([ByRef] Transaction tx); }; interface Update {}; @@ -247,6 +249,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 f02ad1a4..2edfb532 100644 --- a/bdk-ffi/src/lib.rs +++ b/bdk-ffi/src/lib.rs @@ -23,6 +23,7 @@ use crate::types::AddressInfo; use crate::types::Balance; use crate::types::LocalUtxo; use crate::types::ScriptAmount; +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 b1e1ccd6..c6f2c6ae 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::types::Balance; use crate::types::ScriptAmount; @@ -93,6 +93,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);