feat: add fee method on psbt type

This commit is contained in:
thunderbiscuit 2024-05-10 16:09:10 -04:00
parent 7fc8da5451
commit 5ef2bf8a1e
No known key found for this signature in database
GPG Key ID: 88253696EB836462
2 changed files with 28 additions and 1 deletions

View File

@ -654,6 +654,9 @@ interface Psbt {
[Throws=ExtractTxError] [Throws=ExtractTxError]
Transaction extract_tx(); Transaction extract_tx();
[Throws=PsbtError]
u64 fee();
}; };
dictionary OutPoint { dictionary OutPoint {

View File

@ -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::address::{NetworkChecked, NetworkUnchecked};
use bdk::bitcoin::amount::ParseAmountError; use bdk::bitcoin::amount::ParseAmountError;
@ -219,6 +219,30 @@ impl Psbt {
let transaction: Transaction = tx.into(); let transaction: Transaction = tx.into();
Ok(Arc::new(transaction)) Ok(Arc::new(transaction))
} }
pub(crate) fn fee(&self) -> Result<u64, PsbtError> {
self
.0
.lock()
.unwrap()
.fee()
.map(|fee| fee.to_sat())
.map_err(PsbtError::from)
}
//
// pub(crate) fn combine(
// &self,
// other: Arc<Psbt>,
// ) -> Result<Arc<Psbt>, > {
// 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<BdkPsbt> for Psbt { impl From<BdkPsbt> for Psbt {