Class: Tapyrus::Message::FilterLoad

Inherits:
Base
  • Object
show all
Defined in:
lib/tapyrus/message/filter_load.rb

Overview

Constant Summary collapse

COMMAND =
"filterload"
BLOOM_UPDATE_NONE =
0
BLOOM_UPDATE_ALL =
1
BLOOM_UPDATE_P2PUBKEY_ONLY =
2

Constants included from Util

Util::DIGEST_NAME_SHA256

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#to_pkt

Methods included from Util

#byte_to_bit, #calc_checksum, #decode_base58_address, #double_sha256, #encode_base58_address, #hash160, #hmac_sha256, #pack_boolean, #pack_var_int, #pack_var_string, #padding_zero, #sha256, #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, flag = BLOOM_UPDATE_ALL) ⇒ FilterLoad

Returns a new instance of FilterLoad.



15
16
17
18
# File 'lib/tapyrus/message/filter_load.rb', line 15

def initialize(filter, flag = BLOOM_UPDATE_ALL)
  @filter = filter
  @flag = flag
end

Instance Attribute Details

#filterObject

Returns the value of attribute filter.



12
13
14
# File 'lib/tapyrus/message/filter_load.rb', line 12

def filter
  @filter
end

#flagObject

Returns the value of attribute flag.



13
14
15
# File 'lib/tapyrus/message/filter_load.rb', line 13

def flag
  @flag
end

Class Method Details

.parse_from_payload(payload) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/tapyrus/message/filter_load.rb', line 20

def self.parse_from_payload(payload)
  buf = StringIO.new(payload)
  filter_count = Tapyrus.unpack_var_int_from_io(buf)
  filter = buf.read(filter_count).unpack("C*")
  func_count = buf.read(4).unpack("V").first
  tweak = buf.read(4).unpack("V").first
  flag = buf.read(1).unpack("C").first
  FilterLoad.new(Tapyrus::BloomFilter.new(filter, func_count, tweak), flag)
end

Instance Method Details

#to_payloadObject



30
31
32
33
# File 'lib/tapyrus/message/filter_load.rb', line 30

def to_payload
  Tapyrus.pack_var_int(filter.filter.size) << filter.filter.pack("C*") <<
    [filter.hash_funcs, filter.tweak, flag].pack("VVC")
end