Skip to content

Commit e759c9d

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

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ 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+
use crate::Transaction;
18+
1619
#[derive(Debug)]
1720
pub struct Wallet {
1821
// TODO 8: Do we really need the mutex on the wallet? Could this be an Arc?
@@ -92,6 +95,11 @@ impl Wallet {
9295
.sign(&mut psbt, SignOptions::default())
9396
.map_err(|e| BdkError::Generic(e.to_string()))
9497
}
98+
99+
pub fn sent_and_received(&self, tx: &Transaction) -> SentAndReceivedResult {
100+
let (sent, received): (u64, u64) = self.get_wallet().sent_and_received(&tx.clone().into());
101+
SentAndReceivedResult { sent, received }
102+
}
95103
}
96104

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

0 commit comments

Comments
 (0)