Skip to content

Commit

Permalink
feat: add sent_and_received method on wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
reez committed Dec 2, 2023
1 parent e5ded1a commit c97547a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ interface Wallet {

[Throws=BdkError]
boolean sign(PartiallySignedTransaction psbt);

SentAndReceivedValues sent_and_received([ByRef] Transaction tx);
};

interface Update {};
Expand Down Expand Up @@ -235,6 +237,11 @@ dictionary ScriptAmount {
u64 amount;
};

dictionary SentAndReceivedValues {
u64 sent;
u64 received;
};

// ------------------------------------------------------------------------
// bdk crate - bitcoin re-exports
// ------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions bdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::keys::DerivationPath;
use crate::keys::DescriptorPublicKey;
use crate::keys::DescriptorSecretKey;
use crate::keys::Mnemonic;
use crate::wallet::SentAndReceivedValues;
use crate::wallet::TxBuilder;
use crate::wallet::Update;
use crate::wallet::Wallet;
Expand Down
12 changes: 11 additions & 1 deletion bdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::bitcoin::{OutPoint, PartiallySignedTransaction};
use crate::bitcoin::{OutPoint, PartiallySignedTransaction, Transaction};
use crate::descriptor::Descriptor;
use crate::{AddressIndex, AddressInfo, Network, ScriptAmount};
use crate::{Balance, Script};
Expand Down Expand Up @@ -92,6 +92,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);
Expand Down

0 comments on commit c97547a

Please sign in to comment.