Skip to content

Latest commit

 

History

History
130 lines (77 loc) · 3.66 KB

transaction_output.md

File metadata and controls

130 lines (77 loc) · 3.66 KB

Index

BTC::TransactionOutput

Transaction Output (aka "txout") is a part of a bitcoin transaction that specifies destination of the bitcoins being transferred.

Every output has value (in satoshis) and script (that typically corresponds to an address).

This class is frequently used to specify unspent outputs (aka "unspents"). Unspent outputs typically have optional attributes transaction_hash and index to allow creating a corresponding input.

Initializers

new(data: String)

Returns a new transaction output initialized with a binary string in wire format. Raises ArgumentError if transaction output is incomplete or incorrectly encoded.

new(stream: IO)

Returns a new transaction output initialized with data in wire format read from a given stream. Raises ArgumentError if transaction output is incomplete or incorrectly encoded.

new(attributes)

Returns a new transaction output with named attributes. All attributes are optional and have appropriate default values.

TransactionOutput.new(
  value: 42 * BTC::COIN,
  script: Address.parse("1CBtcGivXmHQ8ZqdPgeMfcpQNJrqTrSAcG").script,
  ...
)

Attributes

value

Amount in satoshis to be locked in this output.

script

An instance of BTC::Script that specifies conditions that allow spending bitcoins.

Typically corresponds to a recipient address:

Address.parse("1CBtcGivXmHQ8ZqdPgeMfcpQNJrqTrSAcG").script

Optional Attributes

These are not derived from transaction outputs’s binary data, but set from some other source.

transaction

Reference to the owning transaction. It is set on tx.add_output and reset to nil in tx.remove_all_outputs. Default value is nil.

transaction_hash

Binary hash of the containing transaction. Default value is nil.

transaction_id

Hex big-endian hash of the containing transaction. See Hash↔ID Conversion.

index

Index of this output in the containing transaction. Default value is nil.

block_hash

Binary hash of the block at which containing transaction was included. If not confirmed or not available, equals nil.

block_id

Hex big-endian hash corresponding to block_hash. See Hash↔ID Conversion.

block_height

Height of the block at which containing transaction was included. If not confirmed equals -1.

Note: block_height might not be provided by some APIs while confirmations may be. Default value is derived from transaction if possible or equals nil.

block_time

Time of the block at which containing transaction was included (Time instance or nil). Default value is derived from transaction if possible or equals nil.

confirmations

Number of confirmations. Default value is derived from transaction if possible or equals nil.

spent

If available, returns whether this output is spent (true or false). Default is nil. See also spent_confirmations.

spent_confirmations

If the containing transaction is spent, contains number of confirmations of the spending transaction.

Returns nil if not available or output is not spent.

Returns 0 if spending transaction is not confirmed.

Instance Methods

data

Binary representation of the transaction output in wire format (aka payload).

dictionary

Dictionary representation of transaction output ready to be encoded in JSON, PropertyList etc.