# Class BSV::Transaction::TransactionInput <a id="class-BSV-Transaction-TransactionInput"></a>

**Inherits:** `Object`

A transaction input referencing a previous output to spend.

Inputs identify the output being spent by its transaction ID and output index
(the "outpoint"), and provide an unlocking script to satisfy the locking
script conditions.

## Attributes
### `prev_tx_out_index` [R] <a id="attribute-i-prev_tx_out_index"></a> <a id="prev_tx_out_index-instance_method"></a>
- **@return** [Integer] index of the output within the previous transaction

### `prev_wtxid` [R] <a id="attribute-i-prev_wtxid"></a> <a id="prev_wtxid-instance_method"></a>
- **@return** [String] 32-byte wire-order transaction ID of the output being spent

### `sequence` [RW] <a id="attribute-i-sequence"></a> <a id="sequence-instance_method"></a>
Returns the value of attribute sequence.

### `source_locking_script` [RW] <a id="attribute-i-source_locking_script"></a> <a id="source_locking_script-instance_method"></a>
- **@note** Enters the BIP-143 preimage as scriptCode (step 5) when no
subscript override is supplied. Same caveat as {#source_satoshis}:
no current cache layer depends on this field, but a future preimage
cache would need a setter override here. See
{file:docs/reference/sighash-cache.md}.
- **@return** [Script::Script, nil] locking script of the source output (needed for sighash)

### `source_satoshis` [RW] <a id="attribute-i-source_satoshis"></a> <a id="source_satoshis-instance_method"></a>
- **@note** Enters the BIP-143 preimage at step 6 but no current cache layer
memoises the per-input preimage, so no invalidator is required. If a
future change adds preimage or per-input digest memoisation, add a
setter override here that invalidates the relevant cache slice. See
{file:docs/reference/sighash-cache.md}.
- **@return** [Integer, nil] satoshi value of the source output (needed for sighash)

### `source_transaction` [RW] <a id="attribute-i-source_transaction"></a> <a id="source_transaction-instance_method"></a>
- **@note** Source data is lazily resolved from this Tx during {Tx#verify}
and {Tx#sighash_preimage}. Mutation of this field after resolution
has occurred has no effect on caches because no current cache layer
depends on resolved source data.
- **@return** [Transaction::Tx, nil] the full source transaction (for BEEF wiring)

### `unlocking_script` [RW] <a id="attribute-i-unlocking_script"></a> <a id="unlocking_script-instance_method"></a>
Returns the value of attribute unlocking_script.

### `unlocking_script_template` [RW] <a id="attribute-i-unlocking_script_template"></a> <a id="unlocking_script_template-instance_method"></a>
- **@return** [UnlockingScriptTemplate, nil] template for deferred signing

## Public Class Methods
### `from_binary(data, offset = 0)` <a id="method-c-from_binary"></a> <a id="from_binary-class_method"></a>
Deserialise a transaction input from binary data.
- **@param** `data` [String] binary data
- **@param** `offset` [Integer] byte offset to start reading from
- **@return** [Array(TransactionInput, Integer)] the input and bytes consumed

### `wtxid_from_hex(hex)` <a id="method-c-wtxid_from_hex"></a> <a id="wtxid_from_hex-class_method"></a>
Convert a display-order hex transaction ID to wire-order bytes.
- **@param** `hex` [String] hex-encoded transaction ID (display order)
- **@return** [String] 32-byte transaction ID in wire byte order

## Public Instance Methods
### `dtxid_hex()` <a id="method-i-dtxid_hex"></a> <a id="dtxid_hex-instance_method"></a>
The previous transaction ID in display-order hex.
- **@return** [String] hex-encoded transaction ID (display order)

### `initialize(prev_wtxid:, prev_tx_out_index:, unlocking_script: = nil, sequence: = 0xFFFFFFFF)` <a id="method-i-initialize"></a> <a id="initialize-instance_method"></a>
- **@param** `prev_wtxid` [String] 32-byte wire-order transaction ID
- **@param** `prev_tx_out_index` [Integer] output index in the previous transaction
- **@param** `unlocking_script` [Script::Script, nil] unlocking script (nil if unsigned)
- **@param** `sequence` [Integer] sequence number
- **@return** [TransactionInput] a new instance of TransactionInput

### `initialize_copy(other)` <a id="method-i-initialize_copy"></a> <a id="initialize_copy-instance_method"></a>
Called by <code>#dup</code> and <code>#clone</code>. Clears the owning-Tx
backref so that the cloned input does not belong to any transaction until it
is explicitly added via +Tx#add_input+.

### `outpoint_binary()` <a id="method-i-outpoint_binary"></a> <a id="outpoint_binary-instance_method"></a>
Serialise the outpoint (prev_wtxid + output index) as binary.

Memoised: outpoint components are `attr_reader` only so the value is immutable
after construction. Returns a frozen binary string.
- **@note** Memoised; see {file:docs/reference/sighash-cache.md} for the invalidation contract.
- **@return** [String] 36-byte outpoint

### `to_binary()` <a id="method-i-to_binary"></a> <a id="to_binary-instance_method"></a>
Serialise the input to its binary wire format.
- **@note** Memoised; see {file:docs/reference/sighash-cache.md} for the invalidation contract.
- **@return** [String] binary input (outpoint + varint + script + sequence)
