class Tapyrus::Message::Headers

headers message bitcoin.org/en/developer-reference#headers

Constants

COMMAND

Attributes

headers[RW]

Public Class Methods

new(headers = []) click to toggle source
# File lib/tapyrus/message/headers.rb, line 11
def initialize(headers = [])
  @headers = headers
end
parse_from_payload(payload) click to toggle source
# File lib/tapyrus/message/headers.rb, line 15
def self.parse_from_payload(payload)
  buf = StringIO.new(payload)
  header_count = Tapyrus.unpack_var_int_from_io(buf)
  h = new
  header_count.times do
    h.headers << Tapyrus::BlockHeader.parse_from_payload(buf)
    buf.read(1) # read tx count 0x00 (headers message doesn't include any tx.)
  end
  h
end

Public Instance Methods

to_payload() click to toggle source
# File lib/tapyrus/message/headers.rb, line 26
def to_payload
  Tapyrus.pack_var_int(headers.size) << headers.map { |h| h.to_payload << 0x00 }.join
end