Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: add TxIn #10

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/bitcoin.udl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ dictionary OutPoint {
u32 vout;
};

dictionary TxIn {
OutPoint previous_output;
Script script_sig;
u32 sequence;
sequence<sequence<u8>> witness;
};

[NonExhaustive]
enum Network {
"Bitcoin",
Expand Down
32 changes: 32 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use bitcoin::Address as BitcoinAddress;
use bitcoin::Amount as BitcoinAmount;
use bitcoin::FeeRate as BitcoinFeeRate;
use bitcoin::ScriptBuf as BitcoinScriptBuf;
use bitcoin::TxIn as BitcoinTxIn;
use bitcoin::TxOut as BitcoinTxOut;
use bitcoin::Sequence;

pub use bitcoin::BlockHash;
pub use bitcoin::OutPoint;
Expand Down Expand Up @@ -174,6 +176,36 @@ impl Amount {
impl_from_core_type!(Amount, BitcoinAmount);
impl_from_ffi_type!(Amount, BitcoinAmount);

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TxIn {
pub previous_output: OutPoint,
pub script_sig: Arc<Script>,
pub sequence: u32,
pub witness: Vec<Vec<u8>>,
}

impl From<BitcoinTxIn> for TxIn {
fn from(value: BitcoinTxIn) -> Self {
Self {
previous_output: value.previous_output,
script_sig: Arc::new(value.script_sig.into()),
sequence: value.sequence.0,
witness: value.witness.to_vec(),
}
}
}

impl From<TxIn> for BitcoinTxIn {
fn from(value: TxIn) -> Self {
Self {
previous_output: value.previous_output,
script_sig: value.script_sig.0.clone(),
sequence: Sequence(value.sequence),
witness: value.witness.into(),
}
}
}

impl_string_custom_typedef!(BlockHash);
impl_string_custom_typedef!(Txid);

Expand Down