Class: Bitcoin::Message::CFHeaders

Inherits:
Base
  • Object
show all
Defined in:
lib/bitcoin/message/cfheaders.rb

Overview

Constant Summary collapse

COMMAND =
'cfheaders'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

from_pkt, #to_pkt

Methods included from Util

#byte_to_bit, #calc_checksum, #decode_base58_address, #double_sha256, #encode_base58_address, #hash160, #hkdf_sha256, #hmac_sha256, #pack_boolean, #pack_var_int, #pack_var_string, #padding_zero, #sha256, #tagged_hash, #unpack_boolean, #unpack_var_int, #unpack_var_int_from_io, #unpack_var_string, #valid_address?

Methods included from HexConverter

#to_hex

Constructor Details

#initialize(filter_type, stop_hash, prev_filter_header, filter_hashes) ⇒ CFHeaders

Returns a new instance of CFHeaders.



15
16
17
18
19
20
# File 'lib/bitcoin/message/cfheaders.rb', line 15

def initialize(filter_type, stop_hash, prev_filter_header, filter_hashes)
  @filter_type = filter_type
  @stop_hash = stop_hash
  @prev_filter_header = prev_filter_header
  @filter_hashes = filter_hashes
end

Instance Attribute Details

#filter_hashesObject

little endian



13
14
15
# File 'lib/bitcoin/message/cfheaders.rb', line 13

def filter_hashes
  @filter_hashes
end

#filter_typeObject

Returns the value of attribute filter_type.



10
11
12
# File 'lib/bitcoin/message/cfheaders.rb', line 10

def filter_type
  @filter_type
end

#prev_filter_headerObject

little endian



12
13
14
# File 'lib/bitcoin/message/cfheaders.rb', line 12

def prev_filter_header
  @prev_filter_header
end

#stop_hashObject

little endian



11
12
13
# File 'lib/bitcoin/message/cfheaders.rb', line 11

def stop_hash
  @stop_hash
end

Class Method Details

.parse_from_payload(payload) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/bitcoin/message/cfheaders.rb', line 22

def self.parse_from_payload(payload)
  buf = StringIO.new(payload)
  type = buf.read(1).unpack1("C")
  hash = buf.read(32).bth
  header = buf.read(32).bth
  count = Bitcoin.unpack_var_int_from_io(buf)
  hashes = count.times.map{buf.read(32).bth}
  self.new(type, hash, header, hashes)
end

Instance Method Details

#to_payloadObject



32
33
34
35
# File 'lib/bitcoin/message/cfheaders.rb', line 32

def to_payload
  [filter_type].pack('C') + stop_hash.htb + prev_filter_header.htb +
      Bitcoin.pack_var_int(filter_hashes.size) + filter_hashes.map(&:htb).join
end