bitcoinrb 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/.travis.yml +1 -0
  4. data/README.md +3 -2
  5. data/bitcoinrb.gemspec +2 -2
  6. data/exe/bitcoinrbd +5 -0
  7. data/lib/bitcoin.rb +10 -1
  8. data/lib/bitcoin/bip85_entropy.rb +111 -0
  9. data/lib/bitcoin/block_header.rb +2 -0
  10. data/lib/bitcoin/ext.rb +5 -0
  11. data/lib/bitcoin/ext/json_parser.rb +46 -0
  12. data/lib/bitcoin/ext_key.rb +7 -3
  13. data/lib/bitcoin/key_path.rb +12 -5
  14. data/lib/bitcoin/message.rb +7 -0
  15. data/lib/bitcoin/message/base.rb +1 -0
  16. data/lib/bitcoin/message/cf_parser.rb +16 -0
  17. data/lib/bitcoin/message/cfcheckpt.rb +36 -0
  18. data/lib/bitcoin/message/cfheaders.rb +40 -0
  19. data/lib/bitcoin/message/cfilter.rb +35 -0
  20. data/lib/bitcoin/message/get_cfcheckpt.rb +29 -0
  21. data/lib/bitcoin/message/get_cfheaders.rb +24 -0
  22. data/lib/bitcoin/message/get_cfilters.rb +25 -0
  23. data/lib/bitcoin/message/version.rb +7 -0
  24. data/lib/bitcoin/mnemonic.rb +5 -5
  25. data/lib/bitcoin/network/peer.rb +9 -4
  26. data/lib/bitcoin/network/peer_discovery.rb +3 -1
  27. data/lib/bitcoin/node/cli.rb +14 -10
  28. data/lib/bitcoin/node/spv.rb +1 -1
  29. data/lib/bitcoin/out_point.rb +2 -0
  30. data/lib/bitcoin/payment_code.rb +92 -0
  31. data/lib/bitcoin/psbt/input.rb +5 -14
  32. data/lib/bitcoin/psbt/tx.rb +7 -12
  33. data/lib/bitcoin/rpc/bitcoin_core_client.rb +22 -12
  34. data/lib/bitcoin/rpc/request_handler.rb +1 -1
  35. data/lib/bitcoin/script/script.rb +5 -9
  36. data/lib/bitcoin/script/script_interpreter.rb +2 -3
  37. data/lib/bitcoin/secp256k1.rb +1 -0
  38. data/lib/bitcoin/secp256k1/rfc6979.rb +43 -0
  39. data/lib/bitcoin/secp256k1/ruby.rb +4 -35
  40. data/lib/bitcoin/store.rb +1 -0
  41. data/lib/bitcoin/store/chain_entry.rb +1 -0
  42. data/lib/bitcoin/store/utxo_db.rb +226 -0
  43. data/lib/bitcoin/tx.rb +3 -7
  44. data/lib/bitcoin/tx_in.rb +3 -4
  45. data/lib/bitcoin/util.rb +7 -0
  46. data/lib/bitcoin/version.rb +1 -1
  47. data/lib/bitcoin/wallet.rb +1 -0
  48. data/lib/bitcoin/wallet/account.rb +1 -0
  49. data/lib/bitcoin/wallet/base.rb +2 -2
  50. data/lib/bitcoin/wallet/master_key.rb +1 -0
  51. data/lib/bitcoin/wallet/utxo.rb +37 -0
  52. metadata +34 -20
@@ -6,6 +6,8 @@ module Bitcoin
6
6
  # Transaction class
7
7
  class Tx
8
8
 
9
+ include Bitcoin::HexConverter
10
+
9
11
  MAX_STANDARD_VERSION = 2
10
12
 
11
13
  # The maximum weight for transactions we're willing to relay/mine
@@ -70,7 +72,7 @@ module Bitcoin
70
72
  end
71
73
 
72
74
  def hash
73
- to_payload.bth.to_i(16)
75
+ to_hex.to_i(16)
74
76
  end
75
77
 
76
78
  def tx_hash
@@ -104,12 +106,6 @@ module Bitcoin
104
106
  witness? ? serialize_witness_format : serialize_old_format
105
107
  end
106
108
 
107
- # convert tx to hex format.
108
- # @return [String] tx with hex format.
109
- def to_hex
110
- to_payload.bth
111
- end
112
-
113
109
  def coinbase_tx?
114
110
  inputs.length == 1 && inputs.first.coinbase?
115
111
  end
@@ -37,11 +37,10 @@ module Bitcoin
37
37
  hash, index = buf.read(36).unpack('a32V')
38
38
  i.out_point = OutPoint.new(hash.bth, index)
39
39
  sig_length = Bitcoin.unpack_var_int_from_io(buf)
40
- sig = buf.read(sig_length)
41
- if i.coinbase?
42
- i.script_sig.chunks[0] = sig
40
+ if sig_length == 0
41
+ i.script_sig = Bitcoin::Script.new
43
42
  else
44
- i.script_sig = Script.parse_from_payload(sig)
43
+ i.script_sig = Script.parse_from_payload(buf.read(sig_length))
45
44
  end
46
45
  i.sequence = buf.read(4).unpack('V').first
47
46
  i
@@ -142,4 +142,11 @@ module Bitcoin
142
142
 
143
143
  end
144
144
 
145
+ module HexConverter
146
+
147
+ def to_hex
148
+ to_payload.bth
149
+ end
150
+
151
+ end
145
152
  end
@@ -1,3 +1,3 @@
1
1
  module Bitcoin
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -4,5 +4,6 @@ module Bitcoin
4
4
  autoload :Account, 'bitcoin/wallet/account'
5
5
  autoload :DB, 'bitcoin/wallet/db'
6
6
  autoload :MasterKey, 'bitcoin/wallet/master_key'
7
+ autoload :Utxo, 'bitcoin/wallet/utxo'
7
8
  end
8
9
  end
@@ -3,6 +3,7 @@ module Bitcoin
3
3
 
4
4
  # the account in BIP-44
5
5
  class Account
6
+ include Bitcoin::HexConverter
6
7
 
7
8
  PURPOSE_TYPE = {legacy: 44, nested_witness: 49, native_segwit: 84}
8
9
 
@@ -20,14 +20,14 @@ module Bitcoin
20
20
  # @param [String] wallet_id new wallet id.
21
21
  # @param [String] path_prefix wallet file path prefix.
22
22
  # @return [Bitcoin::Wallet::Base] the wallet
23
- def self.create(wallet_id = 1, path_prefix = default_path_prefix)
23
+ def self.create(wallet_id = 1, path_prefix = default_path_prefix, purpose = Account::PURPOSE_TYPE[:native_segwit])
24
24
  raise ArgumentError, "wallet_id : #{wallet_id} already exist." if self.exist?(wallet_id, path_prefix)
25
25
  w = self.new(wallet_id, path_prefix)
26
26
  # generate seed
27
27
  raise RuntimeError, 'the seed already exist.' if w.db.registered_master?
28
28
  master = Bitcoin::Wallet::MasterKey.generate
29
29
  w.db.register_master_key(master)
30
- w.create_account('Default')
30
+ w.create_account(purpose, 'Default')
31
31
  w
32
32
  end
33
33
 
@@ -3,6 +3,7 @@ module Bitcoin
3
3
 
4
4
  # HD Wallet master seed
5
5
  class MasterKey
6
+ include Bitcoin::HexConverter
6
7
  extend Bitcoin::Util
7
8
  include Bitcoin::Util
8
9
  include Bitcoin::KeyPath
@@ -0,0 +1,37 @@
1
+ module Bitcoin
2
+ module Wallet
3
+ class Utxo
4
+ attr_reader :tx_hash
5
+ attr_reader :index
6
+ attr_reader :block_height
7
+ attr_reader :value
8
+ attr_reader :script_pubkey
9
+
10
+ def initialize(tx_hash, index, value, script_pubkey, block_height = nil)
11
+ @tx_hash = tx_hash
12
+ @index = index
13
+ @block_height = block_height
14
+ @value = value
15
+ @script_pubkey = script_pubkey
16
+ end
17
+
18
+ def self.parse_from_payload(payload)
19
+ return nil if payload.nil?
20
+
21
+ tx_hash, index, block_height, value, payload = payload.unpack('H64VVQa*')
22
+
23
+ buf = StringIO.new(payload)
24
+ script_size = Bitcoin.unpack_var_int_from_io(buf)
25
+ script_pubkey = Bitcoin::Script.parse_from_payload(buf.read(script_size));
26
+ new(tx_hash, index, value, script_pubkey, block_height == 0 ? nil : block_height )
27
+ end
28
+
29
+ def to_payload
30
+ payload = [tx_hash, index, block_height.nil? ? 0 : block_height, value].pack('H64VVQ')
31
+ s = script_pubkey.to_payload
32
+ payload << Bitcoin.pack_var_int(s.length) << s
33
+ payload
34
+ end
35
+ end
36
+ end
37
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitcoinrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-27 00:00:00.000000000 Z
11
+ date: 2020-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ecdsa
@@ -136,20 +136,6 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- - !ruby/object:Gem::Dependency
140
- name: rest-client
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :runtime
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: iniparse
155
141
  requirement: !ruby/object:Gem::Requirement
@@ -206,6 +192,20 @@ dependencies:
206
192
  - - ">="
207
193
  - !ruby/object:Gem::Version
208
194
  version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: json_pure
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: 2.3.1
202
+ type: :runtime
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: 2.3.1
209
209
  - !ruby/object:Gem::Dependency
210
210
  name: leveldb-native
211
211
  requirement: !ruby/object:Gem::Requirement
@@ -238,16 +238,16 @@ dependencies:
238
238
  name: rake
239
239
  requirement: !ruby/object:Gem::Requirement
240
240
  requirements:
241
- - - "~>"
241
+ - - ">="
242
242
  - !ruby/object:Gem::Version
243
- version: '10.0'
243
+ version: 12.3.3
244
244
  type: :development
245
245
  prerelease: false
246
246
  version_requirements: !ruby/object:Gem::Requirement
247
247
  requirements:
248
- - - "~>"
248
+ - - ">="
249
249
  - !ruby/object:Gem::Version
250
- version: '10.0'
250
+ version: 12.3.3
251
251
  - !ruby/object:Gem::Dependency
252
252
  name: rspec
253
253
  requirement: !ruby/object:Gem::Requirement
@@ -317,6 +317,7 @@ files:
317
317
  - exe/bitcoinrbd
318
318
  - lib/bitcoin.rb
319
319
  - lib/bitcoin/base58.rb
320
+ - lib/bitcoin/bip85_entropy.rb
320
321
  - lib/bitcoin/bit_stream.rb
321
322
  - lib/bitcoin/block.rb
322
323
  - lib/bitcoin/block_filter.rb
@@ -328,6 +329,8 @@ files:
328
329
  - lib/bitcoin/chainparams/testnet.yml
329
330
  - lib/bitcoin/constants.rb
330
331
  - lib/bitcoin/descriptor.rb
332
+ - lib/bitcoin/ext.rb
333
+ - lib/bitcoin/ext/json_parser.rb
331
334
  - lib/bitcoin/ext_key.rb
332
335
  - lib/bitcoin/gcs_filter.rb
333
336
  - lib/bitcoin/key.rb
@@ -341,6 +344,10 @@ files:
341
344
  - lib/bitcoin/message/block_transaction_request.rb
342
345
  - lib/bitcoin/message/block_transactions.rb
343
346
  - lib/bitcoin/message/block_txn.rb
347
+ - lib/bitcoin/message/cf_parser.rb
348
+ - lib/bitcoin/message/cfcheckpt.rb
349
+ - lib/bitcoin/message/cfheaders.rb
350
+ - lib/bitcoin/message/cfilter.rb
344
351
  - lib/bitcoin/message/cmpct_block.rb
345
352
  - lib/bitcoin/message/error.rb
346
353
  - lib/bitcoin/message/fee_filter.rb
@@ -350,6 +357,9 @@ files:
350
357
  - lib/bitcoin/message/get_addr.rb
351
358
  - lib/bitcoin/message/get_block_txn.rb
352
359
  - lib/bitcoin/message/get_blocks.rb
360
+ - lib/bitcoin/message/get_cfcheckpt.rb
361
+ - lib/bitcoin/message/get_cfheaders.rb
362
+ - lib/bitcoin/message/get_cfilters.rb
353
363
  - lib/bitcoin/message/get_data.rb
354
364
  - lib/bitcoin/message/get_headers.rb
355
365
  - lib/bitcoin/message/header_and_short_ids.rb
@@ -391,6 +401,7 @@ files:
391
401
  - lib/bitcoin/node/spv.rb
392
402
  - lib/bitcoin/opcodes.rb
393
403
  - lib/bitcoin/out_point.rb
404
+ - lib/bitcoin/payment_code.rb
394
405
  - lib/bitcoin/payments.rb
395
406
  - lib/bitcoin/payments/output.pb.rb
396
407
  - lib/bitcoin/payments/payment.pb.rb
@@ -416,6 +427,7 @@ files:
416
427
  - lib/bitcoin/script_witness.rb
417
428
  - lib/bitcoin/secp256k1.rb
418
429
  - lib/bitcoin/secp256k1/native.rb
430
+ - lib/bitcoin/secp256k1/rfc6979.rb
419
431
  - lib/bitcoin/secp256k1/ruby.rb
420
432
  - lib/bitcoin/slip39.rb
421
433
  - lib/bitcoin/slip39/share.rb
@@ -426,6 +438,7 @@ files:
426
438
  - lib/bitcoin/store/db.rb
427
439
  - lib/bitcoin/store/db/level_db.rb
428
440
  - lib/bitcoin/store/spv_chain.rb
441
+ - lib/bitcoin/store/utxo_db.rb
429
442
  - lib/bitcoin/tx.rb
430
443
  - lib/bitcoin/tx_in.rb
431
444
  - lib/bitcoin/tx_out.rb
@@ -437,6 +450,7 @@ files:
437
450
  - lib/bitcoin/wallet/base.rb
438
451
  - lib/bitcoin/wallet/db.rb
439
452
  - lib/bitcoin/wallet/master_key.rb
453
+ - lib/bitcoin/wallet/utxo.rb
440
454
  - lib/openassets.rb
441
455
  - lib/openassets/marker_output.rb
442
456
  - lib/openassets/payload.rb