Skip to content

Commit

Permalink
Added finalize
Browse files Browse the repository at this point in the history
clippy

map to OtherPsbtErr

otherwise uniffi is giving a warning

clippy
  • Loading branch information
andreasgriffin committed Sep 14, 2024
1 parent 014504e commit 9fb72e0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,9 @@ interface Psbt {
[Throws=PsbtError]
Psbt combine(Psbt other);

[Throws=PsbtError]
Psbt finalize();

string json_serialize();
};

Expand Down
11 changes: 11 additions & 0 deletions bdk-ffi/src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ use bdk_wallet::bitcoin::consensus::encode::serialize;
use bdk_wallet::bitcoin::consensus::Decodable;
use bdk_wallet::bitcoin::io::Cursor;
use bdk_wallet::bitcoin::psbt::ExtractTxError;
use bdk_wallet::bitcoin::secp256k1::Secp256k1;
use bdk_wallet::bitcoin::Address as BdkAddress;
use bdk_wallet::bitcoin::Network;
use bdk_wallet::bitcoin::Psbt as BdkPsbt;
use bdk_wallet::bitcoin::Transaction as BdkTransaction;
use bdk_wallet::bitcoin::TxIn as BdkTxIn;
use bdk_wallet::bitcoin::TxOut as BdkTxOut;
use bdk_wallet::miniscript::psbt::PsbtExt as MiniscriptPsbtExt;

use std::fmt::Display;
use std::ops::Deref;
Expand Down Expand Up @@ -166,6 +168,15 @@ impl Psbt {
psbt.to_string()
}

pub(crate) fn finalize(&self) -> Result<Arc<Psbt>, PsbtError> {
let secp = Secp256k1::new();
let result = self.0.lock().unwrap().clone().finalize(&secp);
match result {
Ok(psbt) => Ok(Arc::new(Psbt::from(psbt))),
Err((_psbt, _errors)) => Err(PsbtError::OtherPsbtErr),
}
}

pub(crate) fn extract_tx(&self) -> Result<Arc<Transaction>, ExtractTxError> {
let tx: BdkTransaction = self.0.lock().unwrap().clone().extract_tx()?;
let transaction: Transaction = tx.into();
Expand Down

0 comments on commit 9fb72e0

Please sign in to comment.