Skip to content

Commit 55c36b5

Browse files
committed
feat: add sent_and_received method on wallet
1 parent e5ded1a commit 55c36b5

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-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+
SentAndReceivedResult sent_and_received([ByRef] Transaction tx);
98100
};
99101

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

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

bdk-ffi/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ pub struct ScriptAmount {
3939
pub amount: u64,
4040
}
4141

42+
pub struct SentAndReceivedResult {
43+
pub sent: u64,
44+
pub received: u64,
45+
}
46+
4247
/// A derived address and the index it was found at.
4348
pub struct AddressInfo {
4449
/// Child index of this address.

bdk-ffi/src/wallet.rs

Lines changed: 8 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};
@@ -13,6 +13,8 @@ use bdk::{SignOptions, Wallet as BdkWallet};
1313
use bdk::wallet::tx_builder::ChangeSpendPolicy;
1414
use std::sync::{Arc, Mutex, MutexGuard};
1515

16+
use crate::SentAndReceivedResult;
17+
1618
#[derive(Debug)]
1719
pub struct Wallet {
1820
// TODO 8: Do we really need the mutex on the wallet? Could this be an Arc?
@@ -92,6 +94,11 @@ impl Wallet {
9294
.sign(&mut psbt, SignOptions::default())
9395
.map_err(|e| BdkError::Generic(e.to_string()))
9496
}
97+
98+
pub fn sent_and_received(&self, tx: &Transaction) -> SentAndReceivedResult {
99+
let (sent, received): (u64, u64) = self.get_wallet().sent_and_received(&tx.clone().into());
100+
SentAndReceivedResult { sent, received }
101+
}
95102
}
96103

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

0 commit comments

Comments
 (0)