class Bitcoin::Message::MerkleBlock

merckleblock message bitcoin.org/en/developer-reference#merkleblock

Constants

COMMAND

Attributes

flags[RW]
hashes[RW]
header[RW]
tx_count[RW]

Public Class Methods

new() click to toggle source
# File lib/bitcoin/message/merkle_block.rb, line 15
def initialize
  @hashes = []
end
parse_from_payload(payload) click to toggle source
# File lib/bitcoin/message/merkle_block.rb, line 19
def self.parse_from_payload(payload)
  m = new
  buf = StringIO.new(payload)
  m.header = Bitcoin::BlockHeader.parse_from_payload(buf.read(80))
  m.tx_count = buf.read(4).unpack1('V')
  hash_count = Bitcoin.unpack_var_int_from_io(buf)
  hash_count.times do
    m.hashes << buf.read(32).bth
  end
  flag_count = Bitcoin.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

Public Instance Methods

to_payload() click to toggle source
# File lib/bitcoin/message/merkle_block.rb, line 34
def to_payload
  header.to_payload << [tx_count].pack('V') << Bitcoin.pack_var_int(hashes.size) <<
      hashes.map(&:htb).join << Bitcoin.pack_var_int(flags.htb.bytesize) << flags.htb
end