From aa2663423fff41f61e8a35482c09b21467d39b91 Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Wed, 7 Jun 2023 15:15:49 -0400 Subject: [PATCH] Temp 3 --- bdk-ffi/src/psbt.rs | 43 +++++-------------------------------------- bdk-ffi/src/wallet.rs | 17 ++++++++++------- 2 files changed, 15 insertions(+), 45 deletions(-) diff --git a/bdk-ffi/src/psbt.rs b/bdk-ffi/src/psbt.rs index 4aca9842..98dba7ee 100644 --- a/bdk-ffi/src/psbt.rs +++ b/bdk-ffi/src/psbt.rs @@ -4,15 +4,12 @@ use bdk::bitcoin::util::psbt::PartiallySignedTransaction as BdkPartiallySignedTr use bdk::bitcoin::util::psbt::PsbtSighashType as BdkPsbtSighashType; use bdk::bitcoin::{EcdsaSighashType, SchnorrSighashType}; use bdk::bitcoincore_rpc::jsonrpc::serde_json; -use bdk::bitcoin::psbt::Input as BdkInput; use bdk::psbt::PsbtUtils; use std::ops::Deref; use std::str::FromStr; use std::sync::{Arc, Mutex}; -use bdk::bitcoin::consensus::{Decodable, Encodable}; -use bdk::miniscript::serde::Serialize; -use crate::{BdkError, FeeRate, Transaction, TxOut}; +use crate::{BdkError, FeeRate, Transaction}; #[derive(Debug)] pub(crate) struct PartiallySignedTransaction { @@ -82,44 +79,14 @@ impl PartiallySignedTransaction { } // Return the inputs present in the PSBT. - pub(crate) fn inputs(&self) -> Vec { + pub(crate) fn inputs(&self) -> Vec> { let psbt = self.internal.lock().unwrap(); - psbt.inputs().iter().map(|i| i.into()).collect() + psbt.inputs.iter().map(|i| Arc::new(i.clone().into())).collect() } } -#[derive(Debug)] -pub(crate) struct Input { - pub(crate) internal: Mutex, -} - -impl Input { - pub(crate) fn non_witness_utxo(&self) -> Option> { - let input = self.internal.lock().unwrap(); - input.non_witness_utxo().map(|tx| Arc::new(tx.into())) - } - - pub(crate) fn witness_utxo(&self) -> Option> { - let input = self.internal.lock().unwrap(); - input.witness_utxo().map(|tx| Arc::new(tx.into())) - } - - // pub(crate) fn new(raw_input: Vec) -> Self { - // let input: BdkInput = BdkInput::consensus_decode(&raw_input[..]).unwrap(); - // Input { - // internal: Mutex::new(input), - // } - // } - - // pub(crate) fn concensus_encode(&self) -> Vec { - // let input = self.internal.lock().unwrap(); - // input.consensus_encode() - // } -} - -/// A key-value map for an input of the corresponding index in the unsigned -/// transaction. -#[derive(Debug)] +/// A key-value map for an input of the corresponding index in the unsigned transaction. +#[derive(Clone, Debug)] pub(crate) struct Input { _inner: BdkInput, } diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index 0d832f4b..97c9bfd5 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -265,7 +265,7 @@ pub(crate) struct TxBuilder { pub(crate) drain_to: Option, pub(crate) rbf: Option, pub(crate) data: Vec, - pub(crate) foreign_utxos: Vec<(OutPoint, Input, u64)>, + pub(crate) foreign_utxos: Vec<(OutPoint, Arc, u64)>, } impl TxBuilder { @@ -365,16 +365,19 @@ impl TxBuilder { /// /// Note unless you set only_witness_utxo any non-taproot psbt_input you pass to this method must /// have non_witness_utxo set otherwise you will get an error when finish is called. - pub fn add_foreign_utxo( - &mut self, + pub(crate) fn add_foreign_utxo( + &self, outpoint: OutPoint, - psbt_input: Input, + psbt_input: Arc, satisfaction_weight: u64, ) -> Arc { - let mut foreign_utxos = self.foreign_utxos.to_vec(); - foreign_utxos.append((outpoint, psbt_input, satisfaction_weight)); + // TODO: Why doesn't the OutPoint parameter here need an Arc? + + let mut current_foreign_utxos: Vec<(OutPoint, Arc, u64)> = self.foreign_utxos.clone(); + let new_foreign_utxo = (outpoint, psbt_input, satisfaction_weight); + current_foreign_utxos.push(new_foreign_utxo); Arc::new(TxBuilder { - foreign_utxos: foreign_utxos, + foreign_utxos: current_foreign_utxos, ..self.clone() }) }