module Bitcoin::Message::HeadersParser

Common message parser which handle multiple block headers as a payload.

Public Instance Methods

parse_from_payload(payload) click to toggle source
# File lib/bitcoin/message/headers_parser.rb, line 7
def parse_from_payload(payload)
  ver, payload = payload.unpack('Va*')
  size, payload = Bitcoin.unpack_var_int(payload)
  hashes = []
  buf = StringIO.new(payload)
  size.times do
    hashes << buf.read(32).bth
  end
  new(ver, hashes, buf.read(32).bth)
end
to_payload() click to toggle source
# File lib/bitcoin/message/headers_parser.rb, line 18
def to_payload
  [version].pack('V') << Bitcoin.pack_var_int(hashes.length) << hashes.map{|h|h.htb}.join << stop_hash.htb
end