Sha256: 0b8bb0174d61adaa2f81e93ec69737856b4383b7e32b211fdbe863c94dbb8dbb

Contents?: true

Size: 1.02 KB

Versions: 17

Compression:

Stored size: 1.02 KB

Contents

module Bitcoin
  module Message

    # filterload message
    # https://bitcoin.org/en/developer-reference#filterload
    class FilterLoad < Base

      COMMAND = 'filterload'

      BLOOM_UPDATE_NONE = 0
      BLOOM_UPDATE_ALL = 1
      BLOOM_UPDATE_P2PUBKEY_ONLY = 2

      attr_accessor :filter
      attr_accessor :flag

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

      def self.parse_from_payload(payload)
        buf = StringIO.new(payload)
        filter_count = Bitcoin.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(Bitcoin::BloomFilter.new(filter, func_count, tweak), flag)
      end

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

    end

  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
bitcoinrb-0.5.0 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.4.0 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.3.2 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.3.1 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.3.0 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.2.9 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.2.8 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.2.7 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.2.6 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.2.5 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.2.4 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.2.2 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.2.1 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.2.0 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.1.9 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.1.8 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.1.7 lib/bitcoin/message/filter_load.rb