Module: Bitcoin::Message::HeadersParser

Included in:
GetBlocks, GetBlocks, GetHeaders, GetHeaders
Defined in:
lib/bitcoin/message/headers_parser.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#parse_from_payload(payload) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# 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_payloadObject



18
19
20
# 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