lib/bitcoin/protocol/txout.rb in bitcoin-ruby-0.0.14 vs lib/bitcoin/protocol/txout.rb in bitcoin-ruby-0.0.15

- old
+ new

@@ -7,11 +7,11 @@ # output value (in base units; "satoshi") attr_accessor :value # pk_script output Script - attr_accessor :pk_script, :pk_script_length + attr_reader :pk_script, :pk_script_length # p2sh redeem script (optional, not included in the serialized binary format) attr_accessor :redeem_script def initialize *args @@ -37,10 +37,11 @@ txout = new; txout.parse_data_from_io(buf); txout end # parse raw binary data for transaction output def parse_data_from_io(buf) + clear_parsed_script_cache @value = buf.read(8).unpack("Q")[0] @pk_script_length = Protocol.unpack_var_int_from_io(buf) @pk_script = buf.read(@pk_script_length) end @@ -48,10 +49,14 @@ def parsed_script @parsed_script ||= Bitcoin::Script.new(pk_script) end + def clear_parsed_script_cache + remove_instance_variable(:@parsed_script) if defined?(@parsed_script) + end + def to_payload [@value].pack("Q") << Protocol.pack_var_int(@pk_script_length) << @pk_script end def to_null_payload @@ -71,9 +76,10 @@ new(amount, script) end # set pk_script and pk_script_length def pk_script=(pk_script) + clear_parsed_script_cache @pk_script_length, @pk_script = pk_script.bytesize, pk_script end alias :amount :value alias :amount= :value=