Method: OpenAssets::Payload.parse_from_payload
- Defined in:
- lib/openassets/payload.rb
.parse_from_payload(payload) ⇒ Payload
parse open assets payload
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/openassets/payload.rb', line 21 def self.parse_from_payload(payload) buf = StringIO.new(payload) marker = buf.read(2) version = buf.read(2) return nil if marker != MARKER || version != VERSION count = Bitcoin.unpack_var_int_from_io(buf) return nil unless count quantities = [] count.times do quantities << LEB128.decode_unsigned(buf, buf.pos) end = Bitcoin.unpack_var_int_from_io(buf) return nil if .nil? || buf.length < + buf.pos = buf.read().each_byte.map(&:chr).join new(quantities, ) rescue # LEB128#decode_unsigned raise 'undefined method `unpack' for nil:NilClass' # for invalid format such as "018f8f" (the most significant bit of the last byte should be 0) nil end |