Skip to content

Commit

Permalink
Temp 4
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Jun 9, 2023
1 parent ad6f50d commit 3c6bdcc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
11 changes: 10 additions & 1 deletion bdk-ffi/src/psbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ impl PartiallySignedTransaction {
// Return the inputs present in the PSBT.
pub(crate) fn inputs(&self) -> Vec<Arc<Input>> {
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()
}
}

Expand Down Expand Up @@ -111,6 +114,12 @@ impl From<BdkInput> for Input {
}
}

impl From<Input> 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
Expand Down
40 changes: 30 additions & 10 deletions bdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<BdkWallet<AnyDatabase>>,
Expand Down Expand Up @@ -373,7 +372,8 @@ impl TxBuilder {
) -> Arc<Self> {
// TODO: Why doesn't the OutPoint parameter here need an Arc?

let mut current_foreign_utxos: Vec<(OutPoint, Arc<Input>, u64)> = self.foreign_utxos.clone();
let mut current_foreign_utxos: Vec<(OutPoint, Arc<Input>, u64)> =
self.foreign_utxos.clone();
let new_foreign_utxo = (outpoint, psbt_input, satisfaction_weight);
current_foreign_utxos.push(new_foreign_utxo);
Arc::new(TxBuilder {
Expand Down Expand Up @@ -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<Input>, u64)> = self
// .foreign_utxos.iter().map(|(outpoint, input, value)| {
// (outpoint, input.clone(), *value)
// }
// ).collect();
// let foreign_utxos: Vec<(OutPoint, Arc<Input>, 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<BdkOutPoint> =
self.unspendable.iter().map(BdkOutPoint::from).collect();
Expand Down

0 comments on commit 3c6bdcc

Please sign in to comment.