Skip to main content

TransactionInput

Struct TransactionInput 

Source
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)

FieldSize
source_txid32 bytes (LE)
source_tx_out_index4 bytes (LE)
script lengthVarInt
unlocking_scriptvariable
sequence_number4 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: u32

Index of the output within the source transaction.

§sequence_number: u32

Sequence 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

Source

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.

Source

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.

Source

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.
Source

pub fn to_bytes_cleared(&self, clear: bool) -> Vec<u8>

Serialize this input to a byte vector.

If clear is true, the unlocking script is omitted (written as zero-length). This is used when constructing signature preimages.

§Arguments
  • clear - If true, omit the unlocking script from the output.
§Returns

A Vec<u8> containing the serialized input.

Source

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, or None to clear.
Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> TransactionInput

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TransactionInput

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for TransactionInput

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V