From eb822265e36d1757e4ba2b99aa73d87cbcef97fc Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Mon, 5 Jun 2023 09:08:10 -0400 Subject: [PATCH] Temp 2 --- bdk-ffi/src/bdk.udl | 2 ++ bdk-ffi/src/psbt.rs | 40 +++++++++++++++++++++++++++++++++++++++- bdk-ffi/src/wallet.rs | 4 ++-- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index b1f2efb9..ae108120 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -315,6 +315,8 @@ interface PartiallySignedTransaction { FeeRate? fee_rate(); string json_serialize(); + + sequence inputs(); }; interface Input { diff --git a/bdk-ffi/src/psbt.rs b/bdk-ffi/src/psbt.rs index 6bae2583..8eea804e 100644 --- a/bdk-ffi/src/psbt.rs +++ b/bdk-ffi/src/psbt.rs @@ -4,12 +4,15 @@ 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}; +use crate::{BdkError, FeeRate, Transaction, TxOut}; #[derive(Debug)] pub(crate) struct PartiallySignedTransaction { @@ -77,6 +80,41 @@ impl PartiallySignedTransaction { let psbt = self.internal.lock().unwrap(); serde_json::to_string(psbt.deref()).unwrap() } + + // Return the inputs present in the PSBT. + pub(crate) fn inputs(&self) -> Vec { + let psbt = self.internal.lock().unwrap(); + psbt.inputs().iter().map(|i| i.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 diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index 02c9f625..0d832f4b 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, Input, u64)>, } impl TxBuilder { @@ -369,7 +369,7 @@ impl TxBuilder { &mut self, outpoint: OutPoint, psbt_input: Input, - satisfaction_weight: u64 + satisfaction_weight: u64, ) -> Arc { let mut foreign_utxos = self.foreign_utxos.to_vec(); foreign_utxos.append((outpoint, psbt_input, satisfaction_weight));