Skip to content

Commit

Permalink
Temp 3
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Jun 9, 2023
1 parent eb82226 commit ad6f50d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 45 deletions.
43 changes: 5 additions & 38 deletions bdk-ffi/src/psbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -82,44 +79,14 @@ impl PartiallySignedTransaction {
}

// Return the inputs present in the PSBT.
pub(crate) fn inputs(&self) -> Vec<Input> {
pub(crate) fn inputs(&self) -> Vec<Arc<Input>> {
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<BdkInput>,
}

impl Input {
pub(crate) fn non_witness_utxo(&self) -> Option<Arc<Transaction>> {
let input = self.internal.lock().unwrap();
input.non_witness_utxo().map(|tx| Arc::new(tx.into()))
}

pub(crate) fn witness_utxo(&self) -> Option<Arc<TxOut>> {
let input = self.internal.lock().unwrap();
input.witness_utxo().map(|tx| Arc::new(tx.into()))
}

// pub(crate) fn new(raw_input: Vec<u8>) -> Self {
// let input: BdkInput = BdkInput::consensus_decode(&raw_input[..]).unwrap();
// Input {
// internal: Mutex::new(input),
// }
// }

// pub(crate) fn concensus_encode(&self) -> Vec<u8> {
// 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,
}
Expand Down
17 changes: 10 additions & 7 deletions bdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ pub(crate) struct TxBuilder {
pub(crate) drain_to: Option<BdkScript>,
pub(crate) rbf: Option<RbfValue>,
pub(crate) data: Vec<u8>,
pub(crate) foreign_utxos: Vec<(OutPoint, Input, u64)>,
pub(crate) foreign_utxos: Vec<(OutPoint, Arc<Input>, u64)>,
}

impl TxBuilder {
Expand Down Expand Up @@ -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<Input>,
satisfaction_weight: u64,
) -> Arc<Self> {
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<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 {
foreign_utxos: foreign_utxos,
foreign_utxos: current_foreign_utxos,
..self.clone()
})
}
Expand Down

0 comments on commit ad6f50d

Please sign in to comment.