lib/bitcoin/psbt/output.rb in bitcoinrb-0.2.6 vs lib/bitcoin/psbt/output.rb in bitcoinrb-0.2.7
- old
+ new
@@ -17,13 +17,17 @@
# parse PSBT output data form buffer.
# @param [StringIO] buf psbt buffer.
# @return [Bitcoin::PSBTOutput] psbt output.
def self.parse_from_buf(buf)
output = self.new
+ found_sep = false
until buf.eof?
key_len = Bitcoin.unpack_var_int_from_io(buf)
- break if key_len == 0
+ if key_len == 0
+ found_sep = true
+ break
+ end
key_type = buf.read(1).unpack('C').first
key = buf.read(key_len - 1)
value = buf.read(Bitcoin.unpack_var_int_from_io(buf))
case key_type
when PSBT_OUT_TYPES[:redeem_script]
@@ -41,9 +45,10 @@
unknown_key = ([key_type].pack('C') + key).bth
raise ArgumentError, 'Duplicate Key, key for unknown value already provided' if output.unknowns[unknown_key]
output.unknowns[unknown_key] = value
end
end
+ raise ArgumentError, 'Separator is missing at the end of an output map.' unless found_sep
output
end
def to_payload
payload = ''
\ No newline at end of file