Skip to content

Commit 983412e

Browse files
committed
feat: add sent_and_received method on wallet
1 parent e5ded1a commit 983412e

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
@@ -95,6 +95,8 @@ interface Wallet {
9595

9696
[Throws=BdkError]
9797
boolean sign(PartiallySignedTransaction psbt);
98+
99+
SentAndReceivedValues sent_and_received([ByRef] Transaction tx);
98100
};
99101

100102
interface Update {};
@@ -235,6 +237,11 @@ dictionary ScriptAmount {
235237
u64 amount;
236238
};
237239

240+
dictionary SentAndReceivedValues {
241+
u64 sent;
242+
u64 received;
243+
};
244+
238245
// ------------------------------------------------------------------------
239246
// bdk crate - bitcoin re-exports
240247
// ------------------------------------------------------------------------

bdk-ffi/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use crate::keys::Mnemonic;
2020
use crate::wallet::TxBuilder;
2121
use crate::wallet::Update;
2222
use crate::wallet::Wallet;
23+
use crate::wallet::SentAndReceivedValues;
2324

2425
use bdk::keys::bip39::WordCount;
2526
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::{AddressIndex, AddressInfo, Network, ScriptAmount};
44
use crate::{Balance, Script};
@@ -92,6 +92,16 @@ impl Wallet {
9292
.sign(&mut psbt, SignOptions::default())
9393
.map_err(|e| BdkError::Generic(e.to_string()))
9494
}
95+
96+
pub fn sent_and_received(&self, tx: &Transaction) -> SentAndReceivedValues {
97+
let (sent, received): (u64, u64) = self.get_wallet().sent_and_received(&tx.clone().into());
98+
SentAndReceivedValues { sent, received }
99+
}
100+
}
101+
102+
pub struct SentAndReceivedValues {
103+
pub sent: u64,
104+
pub received: u64,
95105
}
96106

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

0 commit comments

Comments
 (0)