Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sent_and_received method on Wallet #428

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ interface Wallet {

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

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

interface Update {};
Expand Down Expand Up @@ -247,6 +249,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 @@ -23,6 +23,7 @@ use crate::types::AddressInfo;
use crate::types::Balance;
use crate::types::LocalUtxo;
use crate::types::ScriptAmount;
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::types::Balance;
use crate::types::ScriptAmount;
Expand Down Expand Up @@ -93,6 +93,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
Loading