Class: Bitcoin::Message::CFHeaders
- Defined in:
- lib/bitcoin/message/cfheaders.rb
Overview
cfheaders message for BIP-157 github.com/bitcoin/bips/blob/master/bip-0157.mediawiki#cfheaders
Constant Summary collapse
- COMMAND =
'cfheaders'
Instance Attribute Summary collapse
-
#filter_hashes ⇒ Object
little endian.
-
#filter_type ⇒ Object
Returns the value of attribute filter_type.
-
#prev_filter_header ⇒ Object
little endian.
-
#stop_hash ⇒ Object
little endian.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(filter_type, stop_hash, prev_filter_header, filter_hashes) ⇒ CFHeaders
constructor
A new instance of CFHeaders.
- #to_payload ⇒ Object
Methods inherited from Base
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
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_hashes ⇒ Object
little endian
13 14 15 |
# File 'lib/bitcoin/message/cfheaders.rb', line 13 def filter_hashes @filter_hashes end |
#filter_type ⇒ Object
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_header ⇒ Object
little endian
12 13 14 |
# File 'lib/bitcoin/message/cfheaders.rb', line 12 def prev_filter_header @prev_filter_header end |
#stop_hash ⇒ Object
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_payload ⇒ Object
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 |