Class: BSV::Transaction::TransactionOutput
- Inherits:
-
Object
- Object
- BSV::Transaction::TransactionOutput
- Defined in:
- lib/bsv/transaction/transaction_output.rb
Overview
A transaction output specifying an amount and spending conditions.
Each output locks a number of satoshis behind a locking script. Outputs are consumed by transaction inputs that provide matching unlocking scripts.
Instance Attribute Summary collapse
-
#change ⇒ Boolean
Whether this output receives change.
-
#locking_script ⇒ Script::Script
The locking script (spending conditions).
-
#satoshis ⇒ Integer
The output value in satoshis.
Class Method Summary collapse
-
.from_binary(data, offset = 0) ⇒ Array(TransactionOutput, Integer)
Deserialise a transaction output from binary data.
Instance Method Summary collapse
-
#initialize(satoshis:, locking_script:, change: false) ⇒ TransactionOutput
constructor
A new instance of TransactionOutput.
-
#to_binary ⇒ String
Serialise the output to its binary wire format.
Constructor Details
#initialize(satoshis:, locking_script:, change: false) ⇒ TransactionOutput
Returns a new instance of TransactionOutput.
23 24 25 26 27 |
# File 'lib/bsv/transaction/transaction_output.rb', line 23 def initialize(satoshis:, locking_script:, change: false) @satoshis = satoshis @locking_script = locking_script @change = change end |
Instance Attribute Details
#change ⇒ Boolean
Returns whether this output receives change.
18 19 20 |
# File 'lib/bsv/transaction/transaction_output.rb', line 18 def change @change end |
#locking_script ⇒ Script::Script
Returns the locking script (spending conditions).
15 16 17 |
# File 'lib/bsv/transaction/transaction_output.rb', line 15 def locking_script @locking_script end |
#satoshis ⇒ Integer
Returns the output value in satoshis.
12 13 14 |
# File 'lib/bsv/transaction/transaction_output.rb', line 12 def satoshis @satoshis end |
Class Method Details
.from_binary(data, offset = 0) ⇒ Array(TransactionOutput, Integer)
Deserialise a transaction output from binary data.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/bsv/transaction/transaction_output.rb', line 42 def self.from_binary(data, offset = 0) if data.bytesize < offset + 8 raise ArgumentError, "truncated output: need 8 bytes for satoshis at offset #{offset}, got #{data.bytesize - offset}" end satoshis = data.byteslice(offset, 8).unpack1('Q<') offset += 8 script_len, vi_size = VarInt.decode(data, offset) offset += vi_size if data.bytesize < offset + script_len raise ArgumentError, "truncated output: need #{script_len} bytes for script at offset #{offset}, got #{data.bytesize - offset}" end script_bytes = data.byteslice(offset, script_len) locking_script = BSV::Script::Script.from_binary(script_bytes) [new(satoshis: satoshis, locking_script: locking_script), 8 + vi_size + script_len] end |