From 5ef2bf8a1ecc6da55ba1e7be38f4b0e613137f27 Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Fri, 10 May 2024 16:09:10 -0400 Subject: [PATCH] feat: add fee method on psbt type --- bdk-ffi/src/bdk.udl | 3 +++ bdk-ffi/src/bitcoin.rs | 26 +++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index 211b38b..1d81b34 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -654,6 +654,9 @@ interface Psbt { [Throws=ExtractTxError] Transaction extract_tx(); + + [Throws=PsbtError] + u64 fee(); }; dictionary OutPoint { diff --git a/bdk-ffi/src/bitcoin.rs b/bdk-ffi/src/bitcoin.rs index 09c9e66..d994205 100644 --- a/bdk-ffi/src/bitcoin.rs +++ b/bdk-ffi/src/bitcoin.rs @@ -1,4 +1,4 @@ -use crate::error::{AddressError, FeeRateError, PsbtParseError, TransactionError}; +use crate::error::{AddressError, FeeRateError, PsbtError, PsbtParseError, TransactionError}; use bdk::bitcoin::address::{NetworkChecked, NetworkUnchecked}; use bdk::bitcoin::amount::ParseAmountError; @@ -219,6 +219,30 @@ impl Psbt { let transaction: Transaction = tx.into(); Ok(Arc::new(transaction)) } + + pub(crate) fn fee(&self) -> Result { + self + .0 + .lock() + .unwrap() + .fee() + .map(|fee| fee.to_sat()) + .map_err(PsbtError::from) + } + + // + // pub(crate) fn combine( + // &self, + // other: Arc, + // ) -> Result, > { + // let other_psbt = other.inner.lock().unwrap().clone(); + // let mut original_psbt = self.inner.lock().unwrap().clone(); + // + // original_psbt.combine(other_psbt)?; + // Ok(Arc::new(PartiallySignedTransaction { + // inner: Mutex::new(original_psbt), + // })) + // } } impl From for Psbt {