Class: Tapyrus::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.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #coinbase? ⇒ Boolean
-
#initialize(out_point: nil, script_sig: Tapyrus::Script.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, use_malfix: false) ⇒ Object
Constructor Details
#initialize(out_point: nil, script_sig: Tapyrus::Script.new, sequence: SEQUENCE_FINAL) ⇒ TxIn
Returns a new instance of TxIn.
26 27 28 29 30 |
# File 'lib/tapyrus/tx_in.rb', line 26 def initialize(out_point: nil, script_sig: Tapyrus::Script.new, sequence: SEQUENCE_FINAL) @out_point = out_point @script_sig = script_sig @sequence = sequence end |
Instance Attribute Details
#out_point ⇒ Object
Returns the value of attribute out_point.
9 10 11 |
# File 'lib/tapyrus/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/tapyrus/tx_in.rb', line 10 def script_sig @script_sig end |
#sequence ⇒ Object
Returns the value of attribute sequence.
11 12 13 |
# File 'lib/tapyrus/tx_in.rb', line 11 def sequence @sequence end |
Class Method Details
.parse_from_payload(payload) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/tapyrus/tx_in.rb', line 32 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 = Tapyrus.unpack_var_int_from_io(buf) if sig_length == 0 i.script_sig = Script.new else i.script_sig = Script.parse_from_payload(buf.read(sig_length)) end i.sequence = buf.read(4).unpack('V').first i end |
Instance Method Details
#==(other) ⇒ Object
70 71 72 |
# File 'lib/tapyrus/tx_in.rb', line 70 def ==(other) to_payload == other.to_payload end |
#coinbase? ⇒ Boolean
47 48 49 |
# File 'lib/tapyrus/tx_in.rb', line 47 def coinbase? out_point.coinbase? end |
#prev_hash ⇒ Object
return previous output hash (not txid)
75 76 77 78 |
# File 'lib/tapyrus/tx_in.rb', line 75 def prev_hash return nil unless out_point out_point.tx_hash end |
#to_h ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/tapyrus/tx_in.rb', line 62 def to_h sig = script_sig.to_h sig.delete(:type) h = {txid: out_point.txid, vout: out_point.index, script_sig: sig } h[:sequence] = sequence h end |
#to_payload(script_sig = @script_sig, sequence = @sequence, use_malfix: false) ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/tapyrus/tx_in.rb', line 51 def to_payload(script_sig = @script_sig, sequence = @sequence, use_malfix: false) p = out_point.to_payload unless use_malfix p << Tapyrus.pack_var_int(script_sig.to_payload.bytesize) p << script_sig.to_payload end p << [sequence].pack('V') p end |