feat: add sent_and_received method on wallet

This commit is contained in:
Matthew 2023-11-29 16:52:49 -06:00
parent 6b177f0893
commit 46e0324f28
No known key found for this signature in database
GPG Key ID: 8D4FCD82DD54DDD2
3 changed files with 19 additions and 1 deletions

View File

@ -107,6 +107,8 @@ interface Wallet {
[Throws=BdkError]
boolean sign(PartiallySignedTransaction psbt);
SentAndReceivedValues sent_and_received([ByRef] Transaction tx);
};
interface Update {};
@ -247,6 +249,11 @@ dictionary ScriptAmount {
u64 amount;
};
dictionary SentAndReceivedValues {
u64 sent;
u64 received;
};
// ------------------------------------------------------------------------
// bdk crate - bitcoin re-exports
// ------------------------------------------------------------------------

View File

@ -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;

View File

@ -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;
@ -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);