bitcoinrb 0.3.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +6 -3
  4. data/README.md +17 -6
  5. data/bitcoinrb.gemspec +9 -8
  6. data/exe/bitcoinrbd +5 -0
  7. data/lib/bitcoin.rb +35 -19
  8. data/lib/bitcoin/bip85_entropy.rb +111 -0
  9. data/lib/bitcoin/block_filter.rb +14 -0
  10. data/lib/bitcoin/block_header.rb +2 -0
  11. data/lib/bitcoin/chain_params.rb +9 -8
  12. data/lib/bitcoin/chainparams/regtest.yml +1 -1
  13. data/lib/bitcoin/chainparams/signet.yml +39 -0
  14. data/lib/bitcoin/chainparams/testnet.yml +1 -1
  15. data/lib/bitcoin/constants.rb +45 -12
  16. data/lib/bitcoin/descriptor.rb +1 -1
  17. data/lib/bitcoin/errors.rb +19 -0
  18. data/lib/bitcoin/ext.rb +5 -0
  19. data/lib/bitcoin/ext/ecdsa.rb +31 -0
  20. data/lib/bitcoin/ext/json_parser.rb +46 -0
  21. data/lib/bitcoin/ext_key.rb +50 -19
  22. data/lib/bitcoin/key.rb +46 -29
  23. data/lib/bitcoin/key_path.rb +12 -5
  24. data/lib/bitcoin/message.rb +79 -0
  25. data/lib/bitcoin/message/addr_v2.rb +34 -0
  26. data/lib/bitcoin/message/base.rb +17 -0
  27. data/lib/bitcoin/message/cf_parser.rb +16 -0
  28. data/lib/bitcoin/message/cfcheckpt.rb +36 -0
  29. data/lib/bitcoin/message/cfheaders.rb +40 -0
  30. data/lib/bitcoin/message/cfilter.rb +35 -0
  31. data/lib/bitcoin/message/fee_filter.rb +1 -1
  32. data/lib/bitcoin/message/filter_load.rb +3 -3
  33. data/lib/bitcoin/message/get_cfcheckpt.rb +29 -0
  34. data/lib/bitcoin/message/get_cfheaders.rb +24 -0
  35. data/lib/bitcoin/message/get_cfilters.rb +25 -0
  36. data/lib/bitcoin/message/header_and_short_ids.rb +1 -1
  37. data/lib/bitcoin/message/inventory.rb +1 -1
  38. data/lib/bitcoin/message/merkle_block.rb +1 -1
  39. data/lib/bitcoin/message/network_addr.rb +141 -18
  40. data/lib/bitcoin/message/ping.rb +1 -1
  41. data/lib/bitcoin/message/pong.rb +1 -1
  42. data/lib/bitcoin/message/send_addr_v2.rb +13 -0
  43. data/lib/bitcoin/message/send_cmpct.rb +2 -2
  44. data/lib/bitcoin/message/version.rb +7 -0
  45. data/lib/bitcoin/mnemonic.rb +7 -7
  46. data/lib/bitcoin/network/peer.rb +9 -4
  47. data/lib/bitcoin/network/peer_discovery.rb +1 -1
  48. data/lib/bitcoin/node/cli.rb +14 -10
  49. data/lib/bitcoin/node/configuration.rb +3 -1
  50. data/lib/bitcoin/node/spv.rb +9 -1
  51. data/lib/bitcoin/opcodes.rb +14 -1
  52. data/lib/bitcoin/out_point.rb +7 -0
  53. data/lib/bitcoin/payment_code.rb +92 -0
  54. data/lib/bitcoin/psbt/hd_key_path.rb +1 -1
  55. data/lib/bitcoin/psbt/input.rb +8 -17
  56. data/lib/bitcoin/psbt/output.rb +1 -1
  57. data/lib/bitcoin/psbt/tx.rb +11 -16
  58. data/lib/bitcoin/rpc/bitcoin_core_client.rb +22 -12
  59. data/lib/bitcoin/rpc/request_handler.rb +3 -3
  60. data/lib/bitcoin/script/script.rb +68 -28
  61. data/lib/bitcoin/script/script_error.rb +27 -1
  62. data/lib/bitcoin/script/script_interpreter.rb +164 -67
  63. data/lib/bitcoin/script/tx_checker.rb +64 -14
  64. data/lib/bitcoin/secp256k1.rb +1 -0
  65. data/lib/bitcoin/secp256k1/native.rb +138 -25
  66. data/lib/bitcoin/secp256k1/rfc6979.rb +43 -0
  67. data/lib/bitcoin/secp256k1/ruby.rb +82 -54
  68. data/lib/bitcoin/sighash_generator.rb +156 -0
  69. data/lib/bitcoin/store.rb +2 -1
  70. data/lib/bitcoin/store/chain_entry.rb +1 -0
  71. data/lib/bitcoin/store/db/level_db.rb +2 -2
  72. data/lib/bitcoin/store/utxo_db.rb +226 -0
  73. data/lib/bitcoin/tx.rb +17 -88
  74. data/lib/bitcoin/tx_in.rb +4 -5
  75. data/lib/bitcoin/tx_out.rb +2 -3
  76. data/lib/bitcoin/util.rb +34 -6
  77. data/lib/bitcoin/version.rb +1 -1
  78. data/lib/bitcoin/wallet.rb +1 -0
  79. data/lib/bitcoin/wallet/account.rb +2 -1
  80. data/lib/bitcoin/wallet/base.rb +3 -3
  81. data/lib/bitcoin/wallet/db.rb +1 -1
  82. data/lib/bitcoin/wallet/master_key.rb +1 -0
  83. data/lib/bitcoin/wallet/utxo.rb +37 -0
  84. metadata +66 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4890635391be36111da08563b43a42f02aeb51088c87a71431ed6b6f22cbe45b
4
- data.tar.gz: 75bbbc13e4244fdd40b1f8aef63a3759ff685d184abeb0867549fe6dbeab3248
3
+ metadata.gz: 5026fc4446c5a88954149551d7168d8022e5aa41cd45cbf86b44ce62fdb308a5
4
+ data.tar.gz: a6a3708940e5eca7d8eba4ac71ca941e98ba5af7e09f516ea6e7583b38299c80
5
5
  SHA512:
6
- metadata.gz: d33ec224e5dd0fa03dd9adcd7e2caa78dd1c7021fc121e9431cb49e331e8176dfdae02420af3a6b6921018b9e17582eec225c26afde6ed733649b47c95340a68
7
- data.tar.gz: 76ac351103ff577d6e4acb07c35a0f00af1e3bb00a4eeac3035fb7471ce51d3df64d2ae2411d2cf34d775bea7b50181f7bc4086dfa61979b4926eb4bd4ab8b78
6
+ metadata.gz: 0f3ce5cc15d9de9c0fbb578ec179a81148228bb7f12c9937f6a3fe6f73585d09f6d62798abe1255e95e5d415c0a0e7fdeeb51457245b16565c8908b76d2d0249
7
+ data.tar.gz: fc3f64635b4330c15152b9a38b49a2ec7b324d3a7940cd7a51c64a601d6f9e89a6731014a9f7d2c86cef8a0453b18beb39c5ecec288b8a77c24d73d615c2aebf
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.6.3
1
+ ruby-3.0.0
data/.travis.yml CHANGED
@@ -1,8 +1,11 @@
1
+ dist: bionic
1
2
  language: ruby
2
3
  rvm:
3
- - 2.4.6
4
- - 2.5.5
5
- - 2.6.3
4
+ - 2.4.10
5
+ - 2.5.8
6
+ - 2.6.6
7
+ - 2.7.2
8
+ - 3.0.0
6
9
  addons:
7
10
  apt:
8
11
  packages:
data/README.md CHANGED
@@ -9,14 +9,17 @@ NOTE: Bitcoinrb work in progress, and there is a possibility of incompatible cha
9
9
 
10
10
  Bitcoinrb supports following feature:
11
11
 
12
- * Bitcoin script interpreter(including [BIP-65](https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki), [BIP-68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki), [BIP-112](https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki))
13
- * De/serialization of Bitcoin protocol network messages
14
- * De/serialization of blocks and transactions
12
+ * [Bitcoin script interpreter](https://github.com/chaintope/bitcoinrb/wiki/Script)(including [BIP-65](https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki), [BIP-68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki), [BIP-112](https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki))
13
+ * [De/serialization of Bitcoin protocol network messages](https://github.com/chaintope/bitcoinrb/wiki/P2P-Message)
14
+ * De/serialization of blocks and [transactions](https://github.com/chaintope/bitcoinrb/wiki/Transaction)
15
15
  * Key generation and verification for ECDSA, including [BIP-32](https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki) and [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) supports.
16
16
  * ECDSA signature(RFC6979 -Deterministic ECDSA, LOW-S, LOW-R support)
17
17
  * Segwit support (parsing segwit payload, Bech32 address, sign for segwit tx, [BIP-141](https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki), [BIP-143](https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki), [BIP-144](https://github.com/bitcoin/bips/blob/master/bip-0144.mediawiki))
18
18
  * [BIP-173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki) Bech32 address support
19
19
  * [BIP-174](https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki) PSBT(Partially Signed Bitcoin Transaction) support
20
+ * [BIP-85](https://github.com/bitcoin/bips/blob/master/bip-0085.mediawiki) Deterministic Entropy From BIP32 Keychains support by `Bitcoin::BIP85Entropy` class.
21
+ * Schnorr signature([BIP-340](https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki))
22
+ * Taproot consensus([BIP-341](https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki) and [BIP-342](https://github.com/bitcoin/bips/blob/master/bip-0342.mediawiki))
20
23
  * [WIP] SPV node
21
24
  * [WIP] 0ff-chain protocol
22
25
 
@@ -36,10 +39,10 @@ If you use node features, please install level DB as follows.
36
39
 
37
40
  $ brew install leveldb
38
41
 
39
- and put `leveldb-ruby` in your Gemfile and run bundle install.
42
+ and put `leveldb-native` in your Gemfile and run bundle install.
40
43
 
41
- ```
42
- gem leveldb-ruby
44
+ ```ruby
45
+ gem 'leveldb-native'
43
46
  ```
44
47
 
45
48
  ## Installation
@@ -92,6 +95,14 @@ Bitcoin.chain_params = :regtest
92
95
 
93
96
  This parameter is described in https://github.com/chaintope/bitcoinrb/blob/master/lib/bitcoin/chainparams/regtest.yml.
94
97
 
98
+ * default signet
99
+
100
+ ```ruby
101
+ Bitcoin.chain_params = :signet
102
+ ```
103
+
104
+ This parameter is described in https://github.com/chaintope/bitcoinrb/blob/master/lib/bitcoin/chainparams/signet.yml.
105
+
95
106
  ## Contributing
96
107
 
97
108
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bitcoinrb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
data/bitcoinrb.gemspec CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.authors = ["azuchi"]
11
11
  spec.email = ["azuchi@chaintope.com"]
12
12
 
13
- spec.summary = %q{[WIP]The implementation of Bitcoin Protocol for Ruby.}
14
- spec.description = %q{[WIP]The implementation of Bitcoin Protocol for Ruby.}
13
+ spec.summary = %q{The implementation of Bitcoin Protocol for Ruby.}
14
+ spec.description = %q{The implementation of Bitcoin Protocol for Ruby.}
15
15
  spec.homepage = 'https://github.com/chaintope/bitcoinrb'
16
16
  spec.license = "MIT"
17
17
 
@@ -23,25 +23,26 @@ Gem::Specification.new do |spec|
23
23
  spec.add_runtime_dependency 'ecdsa'
24
24
  spec.add_runtime_dependency 'eventmachine'
25
25
  spec.add_runtime_dependency 'murmurhash3'
26
- spec.add_runtime_dependency 'bech32', '~> 1.0.3'
26
+ spec.add_runtime_dependency 'bech32', '~> 1.1.0'
27
27
  spec.add_runtime_dependency 'daemon-spawn'
28
28
  spec.add_runtime_dependency 'thor'
29
29
  spec.add_runtime_dependency 'ffi'
30
30
  spec.add_runtime_dependency 'leb128', '~> 1.0.0'
31
31
  spec.add_runtime_dependency 'eventmachine_httpserver'
32
- spec.add_runtime_dependency 'rest-client'
33
32
  spec.add_runtime_dependency 'iniparse'
34
33
  spec.add_runtime_dependency 'siphash'
35
34
  spec.add_runtime_dependency 'protobuf', '3.8.5'
36
- spec.add_runtime_dependency 'scrypt'
37
- spec.add_runtime_dependency 'activesupport', '~> 5.2.3'
35
+ spec.add_runtime_dependency 'json_pure', '>= 2.3.1'
36
+ spec.add_runtime_dependency 'bip-schnorr', '>= 0.3.2'
37
+ spec.add_runtime_dependency 'base32', '>= 0.3.4'
38
38
 
39
39
  # for options
40
- spec.add_development_dependency 'leveldb-ruby'
40
+ spec.add_development_dependency 'leveldb-native'
41
41
 
42
42
  spec.add_development_dependency 'bundler'
43
- spec.add_development_dependency 'rake', '~> 10.0'
43
+ spec.add_development_dependency 'rake', '>= 12.3.3'
44
44
  spec.add_development_dependency 'rspec', '~> 3.0'
45
45
  spec.add_development_dependency 'timecop'
46
+ spec.add_development_dependency 'webmock', '>= 3.11.1'
46
47
 
47
48
  end
data/exe/bitcoinrbd CHANGED
@@ -12,6 +12,11 @@ class BitcoinDaemon < DaemonSpawn::Base
12
12
  node.run
13
13
  end
14
14
 
15
+ def stop
16
+ puts "Stopping Bitcoinrb daemon : #{Time.now}"
17
+ node.shutdown
18
+ end
19
+
15
20
  end
16
21
 
17
22
  class Bitcoinrbd < Thor
data/lib/bitcoin.rb CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'bitcoin/version'
5
5
  require 'eventmachine'
6
- require 'ecdsa'
6
+ require 'schnorr'
7
7
  require 'securerandom'
8
8
  require 'json'
9
9
  require 'bech32'
@@ -14,6 +14,7 @@ require_relative 'openassets'
14
14
 
15
15
  module Bitcoin
16
16
 
17
+ autoload :Ext, 'bitcoin/ext'
17
18
  autoload :Util, 'bitcoin/util'
18
19
  autoload :ChainParams, 'bitcoin/chain_params'
19
20
  autoload :Message, 'bitcoin/message'
@@ -54,8 +55,14 @@ module Bitcoin
54
55
  autoload :KeyPath, 'bitcoin/key_path'
55
56
  autoload :Descriptor, 'bitcoin/descriptor'
56
57
  autoload :SLIP39, 'bitcoin/slip39'
58
+ autoload :Aezeed, 'bitcoin/aezeed'
59
+ autoload :PaymentCode, 'bitcoin/payment_code'
60
+ autoload :BIP85Entropy, 'bitcoin/bip85_entropy'
61
+ autoload :Errors, 'bitcoin/errors'
62
+ autoload :SigHashGenerator, 'bitcoin/sighash_generator'
57
63
 
58
64
  require_relative 'bitcoin/constants'
65
+ require_relative 'bitcoin/ext/ecdsa'
59
66
 
60
67
  extend Util
61
68
 
@@ -63,7 +70,7 @@ module Bitcoin
63
70
 
64
71
  # set bitcoin network chain params
65
72
  def self.chain_params=(name)
66
- raise "chain params for #{name} is not defined." unless %i(mainnet testnet regtest).include?(name.to_sym)
73
+ raise "chain params for #{name} is not defined." unless %i(mainnet testnet regtest signet).include?(name.to_sym)
67
74
  @current_chain = nil
68
75
  @chain_param = name.to_sym
69
76
  end
@@ -78,6 +85,8 @@ module Bitcoin
78
85
  @current_chain = Bitcoin::ChainParams.testnet
79
86
  when :regtest
80
87
  @current_chain = Bitcoin::ChainParams.regtest
88
+ when :signet
89
+ @current_chain = Bitcoin::ChainParams.signet
81
90
  end
82
91
  @current_chain
83
92
  end
@@ -104,7 +113,7 @@ module Bitcoin
104
113
  class ::String
105
114
  # binary convert to hex string
106
115
  def bth
107
- unpack('H*').first
116
+ unpack1('H*')
108
117
  end
109
118
 
110
119
  # hex string convert to binary
@@ -124,14 +133,7 @@ module Bitcoin
124
133
 
125
134
  # get opcode
126
135
  def opcode
127
- case encoding
128
- when Encoding::ASCII_8BIT
129
- each_byte.next
130
- when Encoding::US_ASCII
131
- ord
132
- else
133
- to_i
134
- end
136
+ force_encoding(Encoding::ASCII_8BIT).ord
135
137
  end
136
138
 
137
139
  def opcode?
@@ -161,6 +163,27 @@ module Bitcoin
161
163
  self[offset..-1]
162
164
  end
163
165
 
166
+ def valid_pushdata_length?
167
+ buf = StringIO.new(self)
168
+ opcode = buf.read(1).ord
169
+ offset = 1
170
+ return false if buf.eof?
171
+ len = case opcode
172
+ when Bitcoin::Opcodes::OP_PUSHDATA1
173
+ offset += 1
174
+ buf.read(1).unpack1('C')
175
+ when Bitcoin::Opcodes::OP_PUSHDATA2
176
+ offset += 2
177
+ buf.read(2).unpack1('v')
178
+ when Bitcoin::Opcodes::OP_PUSHDATA4
179
+ offset += 4
180
+ buf.read(4).unpack1('V')
181
+ else
182
+ opcode
183
+ end
184
+ self.bytesize == len + offset
185
+ end
186
+
164
187
  # whether value is hex or not hex
165
188
  # @return [Boolean] return true if data is hex
166
189
  def valid_hex?
@@ -188,7 +211,7 @@ module Bitcoin
188
211
  if value.is_a?(Array)
189
212
  result.update(key => value.map{|v|v.to_h})
190
213
  else
191
- result.update(key => value)
214
+ result.update(key => value.class.to_s.start_with?("Bitcoin::") ? value.to_h : value)
192
215
  end
193
216
  end
194
217
  end
@@ -215,11 +238,4 @@ module Bitcoin
215
238
  end
216
239
  end
217
240
 
218
- class ::ECDSA::Signature
219
- # convert signature to der string.
220
- def to_der
221
- ECDSA::Format::SignatureDerString.encode(self)
222
- end
223
- end
224
-
225
241
  end
@@ -0,0 +1,111 @@
1
+ module Bitcoin
2
+
3
+ # Deterministic Entropy From BIP32 Keychains
4
+ # https://github.com/bitcoin/bips/blob/master/bip-0085.mediawiki
5
+ class BIP85Entropy
6
+
7
+ BIP85_PATH = 83696968 + HARDENED_THRESHOLD
8
+
9
+ include Bitcoin::KeyPath
10
+
11
+ attr_reader :root_key #hex format
12
+
13
+ # Import root key.
14
+ # @param [String] base58 master bip32 root key.
15
+ # @return [Bitcoin::BIP85Entropy]
16
+ def self.from_base58(base58)
17
+ key = Bitcoin::ExtKey.from_base58(base58)
18
+ self.new(key)
19
+ end
20
+
21
+ # derive entropy
22
+ # @param [String] path derive path.
23
+ # @return [Tuple(String, Object)] a tuple of entropy with hex format and results depending the application.
24
+ def derive(path)
25
+ raise ArgumentError, "Invalid BIP85 path format." unless path.start_with?("m/83696968'")
26
+ derived_key = root_key
27
+ parse_key_path(path).each{|num| derived_key = derived_key.derive(num)}
28
+ derived_key = derived_key.priv
29
+ entropy = Bitcoin.hmac_sha512("bip-entropy-from-k", derived_key.htb).bth
30
+ app_no = path.split('/')[2]
31
+ case app_no
32
+ when "39'"
33
+ bip39_entropy(path, entropy)
34
+ when "2'"
35
+ hd_seed_entropy(entropy)
36
+ when "32'"
37
+ xprv_entropy(entropy)
38
+ else
39
+ [entropy, entropy]
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def initialize(root_key)
46
+ @root_key = root_key
47
+ end
48
+
49
+ # derive BIP39 entropy.
50
+ def bip39_entropy(path, entropy)
51
+ params = path.split('/')
52
+ word_len = params[4]
53
+ language = code_to_language(params[3])
54
+ entropy = case word_len
55
+ when "12'"
56
+ entropy[0...32]
57
+ when "18'"
58
+ entropy[0...48]
59
+ when "24'"
60
+ entropy[0...64]
61
+ else
62
+ raise ArgumentError, "Word length #{word_len} does not supported."
63
+ end
64
+ mnemonic = Bitcoin::Mnemonic.new(language)
65
+ [entropy, mnemonic.to_mnemonic(entropy)]
66
+ end
67
+
68
+ # derive HD-Seed WIF entropy.
69
+ def hd_seed_entropy(entropy)
70
+ result = entropy[0...64]
71
+ [result, Bitcoin::Key.new(priv_key: result).to_wif]
72
+ end
73
+
74
+ # derive xprv entropy
75
+ def xprv_entropy(entropy)
76
+ chaincode = entropy[0...64]
77
+ private_key = Bitcoin::Key.new(priv_key: entropy[64..-1])
78
+ ext_key = Bitcoin::ExtKey.new
79
+ ext_key.key = private_key
80
+ ext_key.chain_code = chaincode.htb
81
+ ext_key.depth = 0
82
+ ext_key.number = 0
83
+ ext_key.parent_fingerprint = Bitcoin::ExtKey::MASTER_FINGERPRINT
84
+ [entropy, ext_key.to_base58]
85
+ end
86
+
87
+ # convert language code to language string.
88
+ def code_to_language(code)
89
+ case code
90
+ when "0'"
91
+ "english"
92
+ when "1'"
93
+ "japanese"
94
+ when "3'"
95
+ "spanish"
96
+ when "4'"
97
+ "chinese_simplified"
98
+ when "5'"
99
+ "chinese_traditional"
100
+ when "6'"
101
+ "french"
102
+ when "7'"
103
+ "italian"
104
+ else
105
+ raise ArgumentError, "bitcoinrb does not support language: #{code}"
106
+ end
107
+ end
108
+
109
+ end
110
+
111
+ end
@@ -43,6 +43,20 @@ module Bitcoin
43
43
  BlockFilter.new(filter_type, filter, block.block_hash)
44
44
  end
45
45
 
46
+ # Decode Block Filter from encoded filter
47
+ # @param [Integer] filter_type filter type.
48
+ # @param [String] block_hash block hash with hex format. not little endian.
49
+ # @param [String] encoded encoded_filter with hex format.
50
+ # @return [Bitcoin::BlockFilter] block filter object.
51
+ def self.decode(filter_type, block_hash, encoded)
52
+ filter = case filter_type
53
+ when TYPE[:basic]
54
+ GCSFilter.new(block_hash.htb[0...16], BASIC_FILTER_P, BASIC_FILTER_M, encoded_filter: encoded)
55
+ else
56
+ raise "unknown filter type: #{filter_type}."
57
+ end
58
+ BlockFilter.new(filter_type, filter, block_hash)
59
+ end
46
60
 
47
61
  # calculate filter hash.
48
62
  # @return [String] this filter hash with hex format.
@@ -3,6 +3,8 @@ module Bitcoin
3
3
  # Block Header
4
4
  class BlockHeader
5
5
 
6
+ include Bitcoin::HexConverter
7
+
6
8
  attr_accessor :version
7
9
  attr_accessor :prev_hash
8
10
  attr_accessor :merkle_root
@@ -36,9 +36,6 @@ module Bitcoin
36
36
 
37
37
  attr_accessor :dust_relay_fee
38
38
 
39
- # fork coin id.
40
- attr_accessor :fork_id
41
-
42
39
  # mainnet genesis
43
40
  def self.mainnet
44
41
  init('mainnet')
@@ -54,6 +51,11 @@ module Bitcoin
54
51
  init('regtest')
55
52
  end
56
53
 
54
+ # signet genesis
55
+ def self.signet
56
+ init('signet')
57
+ end
58
+
57
59
  def mainnet?
58
60
  network == 'mainnet'
59
61
  end
@@ -66,6 +68,10 @@ module Bitcoin
66
68
  network == 'regtest'
67
69
  end
68
70
 
71
+ def signet?
72
+ network == 'signet'
73
+ end
74
+
69
75
  def genesis_block
70
76
  header = Bitcoin::BlockHeader.new(
71
77
  genesis['version'], genesis['prev_hash'].rhex, genesis['merkle_root'].rhex,
@@ -73,11 +79,6 @@ module Bitcoin
73
79
  Bitcoin::Block.new(header)
74
80
  end
75
81
 
76
- # whether fork coin.
77
- def fork_chain?
78
- !fork_id.nil?
79
- end
80
-
81
82
  def self.init(name)
82
83
  i = YAML.load(File.open("#{__dir__}/chainparams/#{name}.yml"))
83
84
  i.dust_relay_fee ||= Bitcoin::DUST_RELAY_TX_FEE