feat: add input method on transaction type

This commit is contained in:
thunderbiscuit 2024-05-16 14:03:28 -04:00
parent ca8a3d0471
commit ecdd7c239b
No known key found for this signature in database
GPG Key ID: 88253696EB836462
3 changed files with 39 additions and 2 deletions

View File

@ -582,6 +582,8 @@ interface Transaction {
sequence<u8> serialize(); sequence<u8> serialize();
u64 weight(); u64 weight();
sequence<TxIn> input();
}; };
interface Psbt { interface Psbt {
@ -624,3 +626,10 @@ interface FeeRate {
u64 to_sat_per_kwu(); u64 to_sat_per_kwu();
}; };
dictionary TxIn {
OutPoint previous_output;
Script script_sig;
u32 sequence;
sequence<sequence<u8>> witness;
};

View File

@ -13,13 +13,14 @@ use bdk::bitcoin::OutPoint as BdkOutPoint;
use bdk::bitcoin::Psbt as BdkPsbt; use bdk::bitcoin::Psbt as BdkPsbt;
use bdk::bitcoin::Transaction as BdkTransaction; use bdk::bitcoin::Transaction as BdkTransaction;
use bdk::bitcoin::Txid; use bdk::bitcoin::Txid;
use bdk::bitcoin::TxIn as BdkTxIn;
use bdk::bitcoin::amount::ParseAmountError;
use bdk::bitcoin::Amount as BdkAmount;
use std::io::Cursor; use std::io::Cursor;
use std::str::FromStr; use std::str::FromStr;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use bdk::bitcoin::amount::ParseAmountError;
use bdk::bitcoin::Amount as BdkAmount;
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub struct Amount(pub(crate) BdkAmount); pub struct Amount(pub(crate) BdkAmount);
@ -169,6 +170,10 @@ impl Transaction {
pub fn serialize(&self) -> Vec<u8> { pub fn serialize(&self) -> Vec<u8> {
serialize(&self.0) serialize(&self.0)
} }
pub fn input(&self) -> Vec<TxIn> {
self.0.input.iter().map(|tx_in| tx_in.into()).collect()
}
} }
impl From<BdkTransaction> for Transaction { impl From<BdkTransaction> for Transaction {
@ -239,6 +244,28 @@ impl From<&BdkOutPoint> for OutPoint {
} }
} }
#[derive(Debug, Clone)]
pub struct TxIn {
pub previous_output: OutPoint,
pub script_sig: Arc<Script>,
pub sequence: u32,
pub witness: Vec<Vec<u8>>,
}
impl From<&BdkTxIn> for TxIn {
fn from(tx_in: &BdkTxIn) -> Self {
TxIn {
previous_output: OutPoint {
txid: tx_in.previous_output.txid.to_string(),
vout: tx_in.previous_output.vout,
},
script_sig: Arc::new(Script(tx_in.script_sig.clone())),
sequence: tx_in.sequence.0,
witness: tx_in.witness.to_vec(),
}
}
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct TxOut { pub struct TxOut {
pub value: u64, pub value: u64,

View File

@ -53,6 +53,7 @@ use crate::wallet::BumpFeeTxBuilder;
use crate::wallet::SentAndReceivedValues; use crate::wallet::SentAndReceivedValues;
use crate::wallet::TxBuilder; use crate::wallet::TxBuilder;
use crate::wallet::Update; use crate::wallet::Update;
use crate::bitcoin::TxIn;
use crate::wallet::Wallet; use crate::wallet::Wallet;
use bdk::bitcoin::Network; use bdk::bitcoin::Network;