Sha256: 6f883cd8e9a09a125055a5ee8ed8a290f894a238e8e65f53c5fb39e90ee237f1

Contents?: true

Size: 1.1 KB

Versions: 7

Compression:

Stored size: 1.1 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 # bin format
      attr_accessor :func_count
      attr_accessor :tweak
      attr_accessor :flag

      def initialize(filter, func_count, tweak = 0, flag = BLOOM_UPDATE_ALL)
        @filter = filter
        @func_count = func_count
        @tweak = tweak
        @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
        new(filter, func_count, tweak, flag)
      end

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

    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
bitcoinrb-0.1.6 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.1.5 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.1.4 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.1.3 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.1.2 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.1.1 lib/bitcoin/message/filter_load.rb
bitcoinrb-0.0.1 lib/bitcoin/message/filter_load.rb