lib/bitcoin/protocol/txout.rb in bitcoin-ruby-0.0.4 vs lib/bitcoin/protocol/txout.rb in bitcoin-ruby-0.0.5
- old
+ new
@@ -41,19 +41,23 @@
@pk_script = buf.read(@pk_script_length)
end
alias :parse_payload :parse_data
+ def get_script
+ @script_cache || Bitcoin::Script.new(@pk_script)
+ end
+
def to_payload
[@value].pack("Q") << Protocol.pack_var_int(@pk_script_length) << @pk_script
end
def to_null_payload
self.class.new(-1, '').to_payload
end
def to_hash(options = {})
- script = Bitcoin::Script.new(@pk_script)
+ script = get_script
h = { 'value' => "%.8f" % (@value / 100000000.0),
'scriptPubKey' => script.to_string }
h["address"] = script.get_address if script.is_hash160? && options[:with_address]
h
end