Class: Bitcoin::TxIn
Overview
transaction input
Constant Summary collapse
- SEQUENCE_FINAL =
Setting nSequence to this value for every input in a transaction disables nLockTime.
0xffffffff
- SEQUENCE_LOCKTIME_DISABLE_FLAG =
If this flag set, TxIn#sequence is NOT interpreted as a relative lock-time.
(1 << 31)
- SEQUENCE_LOCKTIME_TYPE_FLAG =
If TxIn#sequence encodes a relative lock-time and this flag is set, the relative lock-time has units of 512 seconds, otherwise it specifies blocks with a granularity of 1.
(1 << 22)
- SEQUENCE_LOCKTIME_MASK =
If TxIn#sequence encodes a relative lock-time, this mask is applied to extract that lock-time from the sequence field.
0x0000ffff
Instance Attribute Summary collapse
-
#out_point ⇒ Object
Returns the value of attribute out_point.
-
#script_sig ⇒ Object
Returns the value of attribute script_sig.
-
#script_witness ⇒ Object
Returns the value of attribute script_witness.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #coinbase? ⇒ Boolean
- #has_witness? ⇒ Boolean
-
#initialize(out_point: nil, script_sig: Bitcoin::Script.new, script_witness: ScriptWitness.new, sequence: SEQUENCE_FINAL) ⇒ TxIn
constructor
A new instance of TxIn.
-
#prev_hash ⇒ Object
return previous output hash (not txid).
- #to_h ⇒ Object
- #to_payload(script_sig = @script_sig, sequence = @sequence) ⇒ Object
Constructor Details
#initialize(out_point: nil, script_sig: Bitcoin::Script.new, script_witness: ScriptWitness.new, sequence: SEQUENCE_FINAL) ⇒ TxIn
Returns a new instance of TxIn.
27 28 29 30 31 32 |
# File 'lib/bitcoin/tx_in.rb', line 27 def initialize(out_point: nil, script_sig: Bitcoin::Script.new, script_witness: ScriptWitness.new, sequence: SEQUENCE_FINAL) @out_point = out_point @script_sig = script_sig @script_witness = script_witness @sequence = sequence end |
Instance Attribute Details
#out_point ⇒ Object
Returns the value of attribute out_point.
9 10 11 |
# File 'lib/bitcoin/tx_in.rb', line 9 def out_point @out_point end |
#script_sig ⇒ Object
Returns the value of attribute script_sig.
10 11 12 |
# File 'lib/bitcoin/tx_in.rb', line 10 def script_sig @script_sig end |
#script_witness ⇒ Object
Returns the value of attribute script_witness.
12 13 14 |
# File 'lib/bitcoin/tx_in.rb', line 12 def script_witness @script_witness end |
#sequence ⇒ Object
Returns the value of attribute sequence.
11 12 13 |
# File 'lib/bitcoin/tx_in.rb', line 11 def sequence @sequence end |
Class Method Details
.parse_from_payload(payload) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/bitcoin/tx_in.rb', line 34 def self.parse_from_payload(payload) buf = payload.is_a?(String) ? StringIO.new(payload) : payload i = new hash, index = buf.read(36).unpack('a32V') i.out_point = OutPoint.new(hash.bth, index) sig_length = Bitcoin.unpack_var_int_from_io(buf) sig = buf.read(sig_length) if i.coinbase? i.script_sig.chunks[0] = sig else i.script_sig = Script.parse_from_payload(sig) end i.sequence = buf.read(4).unpack('V').first i end |
Instance Method Details
#==(other) ⇒ Object
74 75 76 |
# File 'lib/bitcoin/tx_in.rb', line 74 def ==(other) to_payload == other.to_payload end |
#coinbase? ⇒ Boolean
50 51 52 |
# File 'lib/bitcoin/tx_in.rb', line 50 def coinbase? out_point.coinbase? end |
#has_witness? ⇒ Boolean
61 62 63 |
# File 'lib/bitcoin/tx_in.rb', line 61 def has_witness? !script_witness.empty? end |
#prev_hash ⇒ Object
return previous output hash (not txid)
79 80 81 82 |
# File 'lib/bitcoin/tx_in.rb', line 79 def prev_hash return nil unless out_point out_point.hash end |
#to_h ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/bitcoin/tx_in.rb', line 65 def to_h sig = script_sig.to_h sig.delete(:type) h = {txid: out_point.txid, vout: out_point.index, script_sig: sig } h[:txinwitness] = script_witness.stack.map(&:bth) if has_witness? h[:sequence] = sequence h end |
#to_payload(script_sig = @script_sig, sequence = @sequence) ⇒ Object
54 55 56 57 58 59 |
# File 'lib/bitcoin/tx_in.rb', line 54 def to_payload(script_sig = @script_sig, sequence = @sequence) p = out_point.to_payload p << Bitcoin.pack_var_int(script_sig.to_payload.bytesize) p << script_sig.to_payload << [sequence].pack('V') p end |