lib/bitcoin/protocol/txin.rb in bitcoin-ruby-0.0.10 vs lib/bitcoin/protocol/txin.rb in bitcoin-ruby-0.0.11
- old
+ new
@@ -18,10 +18,13 @@
# signature hash and the address of the key that needs to sign it
# (used when dealing with unsigned or partly signed tx)
attr_accessor :sig_hash, :sig_address
+ # segregated witness
+ attr_accessor :script_witness
+
alias :script :script_sig
alias :script_length :script_sig_length
# sequence
attr_accessor :sequence
@@ -34,10 +37,11 @@
@prev_out_hash, @prev_out_index, @script_sig_length,
@script_sig, @sequence = *args
@script_sig_length ||= 0
@script_sig ||= ''
@sequence ||= DEFAULT_SEQUENCE
+ @script_witness = ScriptWitness.new
end
# compare to another txout
def ==(other)
@prev_out_hash == other.prev_out_hash &&
@@ -85,10 +89,11 @@
t['coinbase'] = @script_sig.unpack("H*")[0]
else # coinbase tx
t['scriptSig'] = Bitcoin::Script.new(@script_sig).to_string
end
t['sequence'] = @sequence.unpack("V")[0] unless @sequence == "\xff\xff\xff\xff"
+ t['witness'] = @script_witness.stack.map{|s|s.bth} unless @script_witness.empty?
t
end
def self.from_hash(input)
previous_hash = input['previous_transaction_hash'] || input['prev_out']['hash']
@@ -96,9 +101,12 @@
txin = TxIn.new([ previous_hash ].pack('H*').reverse, previous_output_index)
if input['coinbase']
txin.script_sig = [ input['coinbase'] ].pack("H*")
else
txin.script_sig = Script.binary_from_string(input['scriptSig'] || input['script'])
+ end
+ if input['witness']
+ input['witness'].each {|w| txin.script_witness.stack << w.htb}
end
txin.sequence = [ input['sequence'] || 0xffffffff ].pack("V")
txin
end