Skip to content

Commit 81cba97

Browse files
committed
feat: add sent_and_received method on wallet
1 parent 6b177f0 commit 81cba97

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

bdk-ffi/src/bdk.udl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ interface Wallet {
107107

108108
[Throws=BdkError]
109109
boolean sign(PartiallySignedTransaction psbt);
110+
111+
SentAndReceivedValues sent_and_received([ByRef] Transaction tx);
110112
};
111113

112114
interface Update {};
@@ -247,6 +249,11 @@ dictionary ScriptAmount {
247249
u64 amount;
248250
};
249251

252+
dictionary SentAndReceivedValues {
253+
u64 sent;
254+
u64 received;
255+
};
256+
250257
// ------------------------------------------------------------------------
251258
// bdk crate - bitcoin re-exports
252259
// ------------------------------------------------------------------------

bdk-ffi/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate::types::ScriptAmount;
2626
use crate::wallet::TxBuilder;
2727
use crate::wallet::Update;
2828
use crate::wallet::Wallet;
29+
use crate::wallet::SentAndReceivedValues;
2930

3031
use bdk::keys::bip39::WordCount;
3132
use bdk::wallet::tx_builder::ChangeSpendPolicy;

bdk-ffi/src/wallet.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::bitcoin::{OutPoint, PartiallySignedTransaction};
1+
use crate::bitcoin::{OutPoint, PartiallySignedTransaction, Transaction};
22
use crate::descriptor::Descriptor;
33
use crate::types::Balance;
44
use crate::types::ScriptAmount;
@@ -93,6 +93,16 @@ impl Wallet {
9393
.sign(&mut psbt, SignOptions::default())
9494
.map_err(|e| BdkError::Generic(e.to_string()))
9595
}
96+
97+
pub fn sent_and_received(&self, tx: &Transaction) -> SentAndReceivedValues {
98+
let (sent, received): (u64, u64) = self.get_wallet().sent_and_received(&tx.clone().into());
99+
SentAndReceivedValues { sent, received }
100+
}
101+
}
102+
103+
pub struct SentAndReceivedValues {
104+
pub sent: u64,
105+
pub received: u64,
96106
}
97107

98108
pub struct Update(pub(crate) BdkUpdate);

0 commit comments

Comments
 (0)