lib/tapyrus/tx_in.rb in tapyrus-0.1.0 vs lib/tapyrus/tx_in.rb in tapyrus-0.2.0
- old
+ new
@@ -7,11 +7,10 @@
class TxIn
attr_accessor :out_point
attr_accessor :script_sig
attr_accessor :sequence
- attr_accessor :script_witness
# Setting nSequence to this value for every input in a transaction disables nLockTime.
SEQUENCE_FINAL = 0xffffffff
# If this flag set, TxIn#sequence is NOT interpreted as a relative lock-time.
@@ -22,28 +21,26 @@
SEQUENCE_LOCKTIME_TYPE_FLAG = (1 << 22)
# If TxIn#sequence encodes a relative lock-time, this mask is applied to extract that lock-time from the sequence field.
SEQUENCE_LOCKTIME_MASK = 0x0000ffff
- def initialize(out_point: nil, script_sig: Tapyrus::Script.new, script_witness: ScriptWitness.new, sequence: SEQUENCE_FINAL)
+ def initialize(out_point: nil, script_sig: Tapyrus::Script.new, sequence: SEQUENCE_FINAL)
@out_point = out_point
@script_sig = script_sig
- @script_witness = script_witness
@sequence = sequence
end
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)
- sig = buf.read(sig_length)
- if i.coinbase?
- i.script_sig.chunks[0] = sig
+ if sig_length == 0
+ i.script_sig = Script.new
else
- i.script_sig = Script.parse_from_payload(sig)
+ i.script_sig = Script.parse_from_payload(buf.read(sig_length))
end
i.sequence = buf.read(4).unpack('V').first
i
end
@@ -59,18 +56,14 @@
end
p << [sequence].pack('V')
p
end
- def has_witness?
- !script_witness.empty?
- end
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
def ==(other)