Skip to content

Commit

Permalink
Temp 2
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Jun 7, 2023
1 parent 44ca644 commit e7433e4
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
2 changes: 2 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ interface PartiallySignedTransaction {
FeeRate? fee_rate();

string json_serialize();

sequence<Input> inputs();
};

interface Input {
Expand Down
40 changes: 39 additions & 1 deletion bdk-ffi/src/psbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<Input> {
let psbt = self.internal.lock().unwrap();
psbt.inputs().iter().map(|i| i.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
Expand Down
4 changes: 2 additions & 2 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, Input, u64)>,
}

impl TxBuilder {
Expand Down Expand Up @@ -369,7 +369,7 @@ impl TxBuilder {
&mut self,
outpoint: OutPoint,
psbt_input: Input,
satisfaction_weight: u64
satisfaction_weight: u64,
) -> Arc<Self> {
let mut foreign_utxos = self.foreign_utxos.to_vec();
foreign_utxos.append((outpoint, psbt_input, satisfaction_weight));
Expand Down

0 comments on commit e7433e4

Please sign in to comment.