pub struct TransactionInput {
pub source_txid: [u8; 32],
pub source_tx_out_index: u32,
pub sequence_number: u32,
pub unlocking_script: Option<Script>,
pub source_transaction: Option<Box<Transaction>>,
/* private fields */
}Expand description
A single input in a BSV transaction.
Each input references an output from a previous transaction by its
transaction ID (source_txid) and output index (source_tx_out_index).
The unlocking_script (scriptSig) supplies the data required to satisfy
the referenced output’s locking script.
Source output information can be provided either via source_transaction
(full previous tx) or set_source_output (just the relevant output).
The direct source output takes priority when both are present.
§Wire format (standard)
| Field | Size |
|---|---|
| source_txid | 32 bytes (LE) |
| source_tx_out_index | 4 bytes (LE) |
| script length | VarInt |
| unlocking_script | variable |
| sequence_number | 4 bytes (LE) |
Fields§
§source_txid: [u8; 32]The 32-byte transaction ID of the output being spent, in internal (little-endian) byte order.
source_tx_out_index: u32Index of the output within the source transaction.
sequence_number: u32Sequence number. Defaults to 0xFFFFFFFF (finalized).
unlocking_script: Option<Script>The unlocking script (scriptSig) that proves authorization.
None when the input has not yet been signed.
source_transaction: Option<Box<Transaction>>Optional reference to the full source transaction. Used during signing to look up the previous output’s locking script and satoshi value.
Implementations§
Source§impl TransactionInput
impl TransactionInput
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new TransactionInput with default values.
The source txid is zeroed, output index is 0, sequence is finalized, and no unlocking script or source transaction is set.
§Returns
A default TransactionInput.
Sourcepub fn read_from(reader: &mut BsvReader<'_>) -> Result<Self, TransactionError>
pub fn read_from(reader: &mut BsvReader<'_>) -> Result<Self, TransactionError>
Deserialize a TransactionInput from a BsvReader.
Reads the standard wire format: 32-byte txid, 4-byte output index, varint-prefixed unlocking script, and 4-byte sequence number.
§Arguments
reader- The reader positioned at the start of an encoded input.
§Returns
Ok(TransactionInput) on success, or a TransactionError if the
data is truncated or malformed.
Sourcepub fn write_to(&self, writer: &mut BsvWriter)
pub fn write_to(&self, writer: &mut BsvWriter)
Serialize this TransactionInput into a BsvWriter.
Writes the standard wire format: txid, output index, varint script length, script bytes, and sequence number.
§Arguments
writer- The writer to append serialized bytes to.
Sourcepub fn set_source_output(&mut self, output: Option<TransactionOutput>)
pub fn set_source_output(&mut self, output: Option<TransactionOutput>)
Set a direct source output on this input.
This provides the satoshi value and locking script of the output
being spent, without needing the full source transaction.
Takes priority over source_transaction for lookups.
§Arguments
output- The source output, orNoneto clear.
Sourcepub fn source_tx_output(&self) -> Option<&TransactionOutput>
pub fn source_tx_output(&self) -> Option<&TransactionOutput>
Look up the source transaction output, if available.
First checks the direct source_output field, then falls back
to looking up the output by index in source_transaction.
§Returns
Some(&TransactionOutput) if source info is available, otherwise None.
Sourcepub fn source_tx_satoshis(&self) -> Option<u64>
pub fn source_tx_satoshis(&self) -> Option<u64>
Return the satoshi value of the source output, if available.
§Returns
Some(satoshis) if the source output info is available,
otherwise None.
Sourcepub fn source_tx_script(&self) -> Option<&Script>
pub fn source_tx_script(&self) -> Option<&Script>
Return the locking script of the source output, if available.
§Returns
Some(&Script) if the source output info is available,
otherwise None.
Trait Implementations§
Source§impl Clone for TransactionInput
impl Clone for TransactionInput
Source§fn clone(&self) -> TransactionInput
fn clone(&self) -> TransactionInput
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more