Sha256: 2d13f0a42451b56daa98d1061a439cd0a22155864cbdd4a123c8cac4641dbc5c
Contents?: true
Size: 1.09 KB
Versions: 10
Compression:
Stored size: 1.09 KB
Contents
module Tapyrus module Message # merckleblock message # https://bitcoin.org/en/developer-reference#merkleblock class MerkleBlock < Base COMMAND = 'merkleblock' attr_accessor :header attr_accessor :tx_count attr_accessor :hashes attr_accessor :flags def initialize @hashes = [] end def self.parse_from_payload(payload) m = new buf = StringIO.new(payload) m.header = Tapyrus::BlockHeader.parse_from_payload(buf) m.tx_count = buf.read(4).unpack('V').first hash_count = Tapyrus.unpack_var_int_from_io(buf) hash_count.times { m.hashes << buf.read(32).bth } flag_count = Tapyrus.unpack_var_int_from_io(buf) # A sequence of bits packed eight in a byte with the least significant bit first. m.flags = buf.read(flag_count).bth m end def to_payload header.to_payload << [tx_count].pack('V') << Tapyrus.pack_var_int(hashes.size) << hashes.map(&:htb).join << Tapyrus.pack_var_int(flags.htb.bytesize) << flags.htb end end end end
Version data entries
10 entries across 10 versions & 1 rubygems