forked from MetaMask/bdk-wasm
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinput.rs
More file actions
85 lines (72 loc) · 2.27 KB
/
Copy pathinput.rs
File metadata and controls
85 lines (72 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use std::ops::Deref;
use wasm_bindgen::prelude::wasm_bindgen;
use bdk_wallet::bitcoin::TxIn as BdkTxIn;
use crate::types::{OutPoint, ScriptBuf};
/// Bitcoin transaction input.
///
/// It contains the location of the previous transaction's output,
/// that it spends and set of scripts that satisfy its spending
/// conditions.
#[wasm_bindgen]
#[derive(Clone)]
pub struct TxIn(BdkTxIn);
impl Deref for TxIn {
type Target = BdkTxIn;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[wasm_bindgen]
impl TxIn {
/// The reference to the previous output that is being used as an input.
#[wasm_bindgen(getter)]
pub fn previous_output(&self) -> OutPoint {
self.0.previous_output.into()
}
/// The script which pushes values on the stack which will cause
/// the referenced output's script to be accepted.
#[wasm_bindgen(getter)]
pub fn script_sig(&self) -> ScriptBuf {
self.0.script_sig.clone().into()
}
/// Returns the base size of this input.
///
/// Base size excludes the witness data.
#[wasm_bindgen(getter)]
pub fn base_size(&self) -> usize {
self.0.base_size()
}
/// Returns the total number of bytes that this input contributes to a transaction.
///
/// Total size includes the witness data.
#[wasm_bindgen(getter)]
pub fn total_size(&self) -> usize {
self.0.total_size()
}
/// Returns true if this input enables the [`absolute::LockTime`] (aka `nLockTime`) of its
/// [`Transaction`].
///
/// `nLockTime` is enabled if *any* input enables it. See [`Transaction::is_lock_time_enabled`]
/// to check the overall state. If none of the inputs enables it, the lock time value is simply
/// ignored. If this returns false and OP_CHECKLOCKTIMEVERIFY is used in the redeem script with
/// this input then the script execution will fail [BIP-0065].
#[wasm_bindgen(getter)]
pub fn enables_lock_time(&self) -> bool {
self.0.enables_lock_time()
}
}
impl From<BdkTxIn> for TxIn {
fn from(inner: BdkTxIn) -> Self {
TxIn(inner)
}
}
impl From<&BdkTxIn> for TxIn {
fn from(inner: &BdkTxIn) -> Self {
TxIn(inner.clone())
}
}
impl From<TxIn> for BdkTxIn {
fn from(txin: TxIn) -> Self {
txin.0
}
}