Class: Bitcoin::BlockFilter
- Inherits:
-
Object
- Object
- Bitcoin::BlockFilter
- Defined in:
- lib/bitcoin/block_filter.rb
Overview
Compact Block Filter github.com/bitcoin/bips/blob/master/bip-0158.mediawiki This implementation ported the implementation of Bitcoin Core’s blockfilter.cpp. github.com/bitcoin/bitcoin/blob/master/src/blockfilter.cpp
Constant Summary collapse
- TYPE =
{basic: 0}
- BASIC_FILTER_P =
basic filter params
19
- BASIC_FILTER_M =
784931
Instance Attribute Summary collapse
-
#block_hash ⇒ Object
Returns the value of attribute block_hash.
-
#filter ⇒ Object
Returns the value of attribute filter.
-
#filter_type ⇒ Object
Returns the value of attribute filter_type.
Class Method Summary collapse
-
.build_from_block(filter_type, block, prev_out_scripts) ⇒ Bitcoin::BlockFilter
Build BlockFilter from the block data.
-
.decode(filter_type, block_hash, encoded) ⇒ Bitcoin::BlockFilter
Decode Block Filter from encoded filter.
Instance Method Summary collapse
-
#encoded_filter ⇒ Object
get encoded filter.
-
#filter_hash ⇒ String
calculate filter hash.
-
#header(prev_header) ⇒ String
calculate filter header which calculates from previous filter header and current filter hash.
-
#initialize(filter_type, filter, block_hash) ⇒ Bitcoin::BlockFilter
constructor
Constructor.
Constructor Details
#initialize(filter_type, filter, block_hash) ⇒ Bitcoin::BlockFilter
Constructor
24 25 26 27 28 |
# File 'lib/bitcoin/block_filter.rb', line 24 def initialize(filter_type, filter, block_hash) @filter_type = filter_type @filter = filter @block_hash = block_hash end |
Instance Attribute Details
#block_hash ⇒ Object
Returns the value of attribute block_hash.
17 18 19 |
# File 'lib/bitcoin/block_filter.rb', line 17 def block_hash @block_hash end |
#filter ⇒ Object
Returns the value of attribute filter.
16 17 18 |
# File 'lib/bitcoin/block_filter.rb', line 16 def filter @filter end |
#filter_type ⇒ Object
Returns the value of attribute filter_type.
15 16 17 |
# File 'lib/bitcoin/block_filter.rb', line 15 def filter_type @filter_type end |
Class Method Details
.build_from_block(filter_type, block, prev_out_scripts) ⇒ Bitcoin::BlockFilter
Build BlockFilter from the block data.
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/bitcoin/block_filter.rb', line 35 def self.build_from_block(filter_type, block, prev_out_scripts) block_hash = block.block_hash.htb[0...16] filter = case filter_type when TYPE[:basic] GCSFilter.new(block_hash, BASIC_FILTER_P, BASIC_FILTER_M, elements: build_basic_filter_elements(block, prev_out_scripts)) else raise "unknown filter type: #{filter_type}." end BlockFilter.new(filter_type, filter, block.block_hash) end |
.decode(filter_type, block_hash, encoded) ⇒ Bitcoin::BlockFilter
Decode Block Filter from encoded filter
51 52 53 54 55 56 57 58 59 |
# File 'lib/bitcoin/block_filter.rb', line 51 def self.decode(filter_type, block_hash, encoded) filter = case filter_type when TYPE[:basic] GCSFilter.new(block_hash.htb[0...16], BASIC_FILTER_P, BASIC_FILTER_M, encoded_filter: encoded) else raise "unknown filter type: #{filter_type}." end BlockFilter.new(filter_type, filter, block_hash) end |
Instance Method Details
#encoded_filter ⇒ Object
get encoded filter.
75 76 77 |
# File 'lib/bitcoin/block_filter.rb', line 75 def encoded_filter filter.encoded end |
#filter_hash ⇒ String
calculate filter hash.
63 64 65 |
# File 'lib/bitcoin/block_filter.rb', line 63 def filter_hash Bitcoin.double_sha256(encoded_filter.htb).bth end |
#header(prev_header) ⇒ String
calculate filter header which calculates from previous filter header and current filter hash.
70 71 72 |
# File 'lib/bitcoin/block_filter.rb', line 70 def header(prev_header) Bitcoin.double_sha256(filter_hash.htb + prev_header.htb).bth end |