From 3c6bdccc81c8227cd4ed25b7ea944aa5c39d8efe Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Fri, 9 Jun 2023 10:04:05 -0400 Subject: [PATCH] Temp 4 --- bdk-ffi/src/psbt.rs | 11 ++++++++++- bdk-ffi/src/wallet.rs | 40 ++++++++++++++++++++++++++++++---------- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/bdk-ffi/src/psbt.rs b/bdk-ffi/src/psbt.rs index 869454cc..56f02610 100644 --- a/bdk-ffi/src/psbt.rs +++ b/bdk-ffi/src/psbt.rs @@ -81,7 +81,10 @@ impl PartiallySignedTransaction { // Return the inputs present in the PSBT. pub(crate) fn inputs(&self) -> Vec> { let psbt = self.internal.lock().unwrap(); - psbt.inputs.iter().map(|i| Arc::new(i.clone().into())).collect() + psbt.inputs + .iter() + .map(|i| Arc::new(i.clone().into())) + .collect() } } @@ -111,6 +114,12 @@ impl From for Input { } } +impl From for BdkInput { + fn from(input: Input) -> Self { + input.inner + } +} + /// A Signature hash type for the corresponding input. As of taproot upgrade, the signature hash /// type can be either [`EcdsaSighashType`] or [`SchnorrSighashType`] but it is not possible to know /// directly which signature hash type the user is dealing with. Therefore, the user is responsible diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index 97c9bfd5..7e5613d2 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -1,3 +1,11 @@ +use crate::blockchain::Blockchain; +use crate::database::DatabaseConfig; +use crate::descriptor::Descriptor; +use crate::psbt::{Input, PartiallySignedTransaction, PsbtSighashType}; +use crate::{ + AddressIndex, AddressInfo, Balance, BdkError, LocalUtxo, OutPoint, Progress, ProgressHolder, + RbfValue, Script, ScriptAmount, TransactionDetails, TxBuilderResult, +}; use bdk::bitcoin::blockdata::script::Script as BdkScript; use bdk::bitcoin::{Address as BdkAddress, Network, OutPoint as BdkOutPoint, Sequence, Txid}; use bdk::database::any::AnyDatabase; @@ -12,15 +20,6 @@ use std::ops::Deref; use std::str::FromStr; use std::sync::{Arc, Mutex, MutexGuard}; -use crate::blockchain::Blockchain; -use crate::database::DatabaseConfig; -use crate::descriptor::Descriptor; -use crate::psbt::{Input, PartiallySignedTransaction, PsbtSighashType}; -use crate::{ - AddressIndex, AddressInfo, Balance, BdkError, LocalUtxo, OutPoint, Progress, ProgressHolder, - RbfValue, Script, ScriptAmount, TransactionDetails, TxBuilderResult, -}; - #[derive(Debug)] pub(crate) struct Wallet { pub(crate) wallet_mutex: Mutex>, @@ -373,7 +372,8 @@ impl TxBuilder { ) -> Arc { // 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 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 { @@ -494,6 +494,26 @@ impl TxBuilder { let utxos: &[BdkOutPoint] = &bdk_utxos; tx_builder.add_utxos(utxos)?; } + if !self.foreign_utxos.is_empty() { + // TODO: Not sure why the double dereference ** is needed here... it just works? + // I really just need to grab the Input inside the Arc but not sure how else to do it. + for (outpoint, input, value) in self.foreign_utxos.iter() { + let input_new: Input = (**input).clone(); + tx_builder.add_foreign_utxo(outpoint.into(), input_new.into(), *value as usize)?; + } + + // let bdk_foreign_utxos: Vec<(OutPoint, Arc, u64)> = self + // .foreign_utxos.iter().map(|(outpoint, input, value)| { + // (outpoint, input.clone(), *value) + // } + // ).collect(); + // let foreign_utxos: Vec<(OutPoint, Arc, u64)> = bdk_foreign_utxos; + // for (outpoint, input, value) in foreign_utxos.iter() { + + // foreign_utxos.forEach(|(outpoint, input, value)| { + // tx_builder.add_foreign_utxo(outpoint, input, value)?; + // }); + } if !self.unspendable.is_empty() { let bdk_unspendable: Vec = self.unspendable.iter().map(BdkOutPoint::from).collect();