tapyrus 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/{.prettierrc.yaml → .prettierrc.yml} +0 -1
  4. data/.ruby-version +1 -1
  5. data/Gemfile +2 -2
  6. data/README.md +1 -1
  7. data/Rakefile +2 -2
  8. data/exe/tapyrus-script-debugger +5 -5
  9. data/exe/tapyrusrb-cli +1 -1
  10. data/exe/tapyrusrbd +18 -17
  11. data/lib/openassets/payload.rb +2 -2
  12. data/lib/openassets/util.rb +2 -2
  13. data/lib/openassets.rb +4 -4
  14. data/lib/schnorr/sign_to_contract.rb +4 -4
  15. data/lib/schnorr/signature.rb +5 -5
  16. data/lib/schnorr.rb +14 -14
  17. data/lib/tapyrus/base58.rb +8 -8
  18. data/lib/tapyrus/bip175.rb +5 -5
  19. data/lib/tapyrus/block_header.rb +2 -2
  20. data/lib/tapyrus/bloom_filter.rb +1 -1
  21. data/lib/tapyrus/chain_params.rb +5 -5
  22. data/lib/tapyrus/constants.rb +1 -1
  23. data/lib/tapyrus/errors.rb +9 -9
  24. data/lib/tapyrus/ext/ecdsa.rb +4 -4
  25. data/lib/tapyrus/ext/json_parser.rb +1 -1
  26. data/lib/tapyrus/ext.rb +3 -3
  27. data/lib/tapyrus/ext_key.rb +21 -21
  28. data/lib/tapyrus/jws.rb +76 -0
  29. data/lib/tapyrus/key.rb +48 -20
  30. data/lib/tapyrus/key_path.rb +3 -3
  31. data/lib/tapyrus/logger.rb +4 -11
  32. data/lib/tapyrus/merkle_tree.rb +1 -1
  33. data/lib/tapyrus/message/addr.rb +2 -2
  34. data/lib/tapyrus/message/base.rb +2 -2
  35. data/lib/tapyrus/message/block.rb +1 -1
  36. data/lib/tapyrus/message/block_txn.rb +1 -1
  37. data/lib/tapyrus/message/cmpct_block.rb +1 -1
  38. data/lib/tapyrus/message/fee_filter.rb +3 -3
  39. data/lib/tapyrus/message/filter_add.rb +1 -1
  40. data/lib/tapyrus/message/filter_clear.rb +2 -2
  41. data/lib/tapyrus/message/filter_load.rb +7 -7
  42. data/lib/tapyrus/message/get_addr.rb +2 -2
  43. data/lib/tapyrus/message/get_block_txn.rb +1 -1
  44. data/lib/tapyrus/message/get_blocks.rb +1 -1
  45. data/lib/tapyrus/message/get_data.rb +1 -1
  46. data/lib/tapyrus/message/get_headers.rb +1 -1
  47. data/lib/tapyrus/message/header_and_short_ids.rb +6 -6
  48. data/lib/tapyrus/message/headers.rb +1 -1
  49. data/lib/tapyrus/message/headers_parser.rb +2 -2
  50. data/lib/tapyrus/message/inv.rb +1 -1
  51. data/lib/tapyrus/message/inventory.rb +3 -3
  52. data/lib/tapyrus/message/mem_pool.rb +2 -2
  53. data/lib/tapyrus/message/merkle_block.rb +3 -3
  54. data/lib/tapyrus/message/network_addr.rb +9 -9
  55. data/lib/tapyrus/message/not_found.rb +1 -1
  56. data/lib/tapyrus/message/ping.rb +3 -3
  57. data/lib/tapyrus/message/pong.rb +3 -3
  58. data/lib/tapyrus/message/reject.rb +6 -6
  59. data/lib/tapyrus/message/send_cmpct.rb +4 -4
  60. data/lib/tapyrus/message/send_headers.rb +2 -2
  61. data/lib/tapyrus/message/tx.rb +1 -1
  62. data/lib/tapyrus/message/ver_ack.rb +2 -2
  63. data/lib/tapyrus/message/version.rb +7 -7
  64. data/lib/tapyrus/message.rb +37 -37
  65. data/lib/tapyrus/mnemonic.rb +18 -16
  66. data/lib/tapyrus/network/connection.rb +2 -2
  67. data/lib/tapyrus/network/message_handler.rb +11 -11
  68. data/lib/tapyrus/network/peer.rb +1 -1
  69. data/lib/tapyrus/network/peer_discovery.rb +1 -1
  70. data/lib/tapyrus/network/pool.rb +4 -4
  71. data/lib/tapyrus/network.rb +6 -6
  72. data/lib/tapyrus/node/cli.rb +34 -34
  73. data/lib/tapyrus/node/configuration.rb +3 -3
  74. data/lib/tapyrus/node/spv.rb +2 -2
  75. data/lib/tapyrus/node.rb +3 -3
  76. data/lib/tapyrus/opcodes.rb +7 -7
  77. data/lib/tapyrus/out_point.rb +2 -2
  78. data/lib/tapyrus/rpc/http_server.rb +6 -6
  79. data/lib/tapyrus/rpc/request_handler.rb +5 -5
  80. data/lib/tapyrus/rpc/tapyrus_core_client.rb +10 -10
  81. data/lib/tapyrus/rpc.rb +4 -4
  82. data/lib/tapyrus/script/color.rb +3 -3
  83. data/lib/tapyrus/script/debugger.rb +9 -9
  84. data/lib/tapyrus/script/multisig.rb +2 -2
  85. data/lib/tapyrus/script/script.rb +28 -28
  86. data/lib/tapyrus/script/script_error.rb +42 -42
  87. data/lib/tapyrus/script/script_interpreter.rb +9 -9
  88. data/lib/tapyrus/script/tx_checker.rb +2 -2
  89. data/lib/tapyrus/secp256k1/native.rb +23 -23
  90. data/lib/tapyrus/secp256k1/rfc6979.rb +7 -7
  91. data/lib/tapyrus/secp256k1/ruby.rb +2 -2
  92. data/lib/tapyrus/secp256k1.rb +3 -3
  93. data/lib/tapyrus/slip39/share.rb +7 -7
  94. data/lib/tapyrus/slip39/sss.rb +24 -24
  95. data/lib/tapyrus/slip39.rb +514 -37
  96. data/lib/tapyrus/store/db/level_db.rb +2 -2
  97. data/lib/tapyrus/store/db.rb +1 -1
  98. data/lib/tapyrus/store/spv_chain.rb +7 -7
  99. data/lib/tapyrus/store.rb +3 -3
  100. data/lib/tapyrus/tip0137.rb +201 -0
  101. data/lib/tapyrus/tx.rb +12 -12
  102. data/lib/tapyrus/tx_builder.rb +3 -3
  103. data/lib/tapyrus/tx_in.rb +3 -3
  104. data/lib/tapyrus/tx_out.rb +3 -3
  105. data/lib/tapyrus/util.rb +21 -21
  106. data/lib/tapyrus/validation.rb +9 -9
  107. data/lib/tapyrus/version.rb +1 -1
  108. data/lib/tapyrus/wallet/account.rb +12 -12
  109. data/lib/tapyrus/wallet/base.rb +9 -8
  110. data/lib/tapyrus/wallet/db.rb +11 -11
  111. data/lib/tapyrus/wallet/master_key.rb +13 -13
  112. data/lib/tapyrus/wallet.rb +4 -4
  113. data/lib/tapyrus.rb +62 -59
  114. data/tapyrusrb.gemspec +33 -31
  115. metadata +30 -14
@@ -1,4 +1,4 @@
1
- require 'siphash'
1
+ require "siphash"
2
2
  module Tapyrus
3
3
  module Message
4
4
  # BIP-152 Compact Block's data format.
@@ -15,13 +15,13 @@ module Tapyrus
15
15
  @nonce = nonce
16
16
  @short_ids = short_ids
17
17
  @prefilled_txn = prefilled_txn
18
- @siphash_key = Tapyrus.sha256(header.to_payload << [nonce].pack('q*'))[0...16]
18
+ @siphash_key = Tapyrus.sha256(header.to_payload << [nonce].pack("q*"))[0...16]
19
19
  end
20
20
 
21
21
  def self.parse_from_payload(payload)
22
22
  buf = StringIO.new(payload)
23
23
  header = Tapyrus::BlockHeader.parse_from_payload(buf)
24
- nonce = buf.read(8).unpack('q*').first
24
+ nonce = buf.read(8).unpack("q*").first
25
25
  short_ids_len = Tapyrus.unpack_var_int_from_io(buf)
26
26
  short_ids = short_ids_len.times.map { buf.read(6).reverse.bth.to_i(16) }
27
27
  prefilled_txn_len = Tapyrus.unpack_var_int_from_io(buf)
@@ -31,9 +31,9 @@ module Tapyrus
31
31
 
32
32
  def to_payload
33
33
  p = header.to_payload
34
- p << [nonce].pack('q*')
34
+ p << [nonce].pack("q*")
35
35
  p << Tapyrus.pack_var_int(short_ids.size)
36
- p << short_ids.map { |id| sprintf('%12x', id).htb.reverse }.join
36
+ p << short_ids.map { |id| sprintf("%12x", id).htb.reverse }.join
37
37
  p << Tapyrus.pack_var_int(prefilled_txn.size)
38
38
  p << prefilled_txn.map(&:to_payload).join
39
39
  p
@@ -44,7 +44,7 @@ module Tapyrus
44
44
  # @return [Integer] 6 bytes short transaction id.
45
45
  def short_id(txid)
46
46
  hash = SipHash.digest(siphash_key, txid.htb.reverse).to_even_length_hex
47
- [hash].pack('H*')[2...8].bth.to_i(16)
47
+ [hash].pack("H*")[2...8].bth.to_i(16)
48
48
  end
49
49
  end
50
50
  end
@@ -3,7 +3,7 @@ module Tapyrus
3
3
  # headers message
4
4
  # https://bitcoin.org/en/developer-reference#headers
5
5
  class Headers < Base
6
- COMMAND = 'headers'
6
+ COMMAND = "headers"
7
7
 
8
8
  # Array[Tapyrus::BlockHeader]
9
9
  attr_accessor :headers
@@ -3,7 +3,7 @@ module Tapyrus
3
3
  # Common message parser which handle multiple block headers as a payload.
4
4
  module HeadersParser
5
5
  def parse_from_payload(payload)
6
- ver, payload = payload.unpack('Va*')
6
+ ver, payload = payload.unpack("Va*")
7
7
  size, payload = Tapyrus.unpack_var_int(payload)
8
8
  hashes = []
9
9
  buf = StringIO.new(payload)
@@ -12,7 +12,7 @@ module Tapyrus
12
12
  end
13
13
 
14
14
  def to_payload
15
- [version].pack('V') << Tapyrus.pack_var_int(hashes.length) << hashes.map { |h| h.htb }.join << stop_hash.htb
15
+ [version].pack("V") << Tapyrus.pack_var_int(hashes.length) << hashes.map { |h| h.htb }.join << stop_hash.htb
16
16
  end
17
17
  end
18
18
  end
@@ -6,7 +6,7 @@ module Tapyrus
6
6
  include InventoriesParser
7
7
  extend InventoriesParser
8
8
 
9
- COMMAND = 'inv'
9
+ COMMAND = "inv"
10
10
 
11
11
  attr_reader :inventories
12
12
 
@@ -26,14 +26,14 @@ module Tapyrus
26
26
 
27
27
  # parse inventory payload
28
28
  def self.parse_from_payload(payload)
29
- raise Error, 'invalid inventory size.' if payload.bytesize != 36
30
- identifier = payload[0..4].unpack('V').first
29
+ raise Error, "invalid inventory size." if payload.bytesize != 36
30
+ identifier = payload[0..4].unpack("V").first
31
31
  hash = payload[4..-1].bth # internal byte order
32
32
  new(identifier, hash)
33
33
  end
34
34
 
35
35
  def to_payload
36
- [identifier].pack('V') << hash.htb
36
+ [identifier].pack("V") << hash.htb
37
37
  end
38
38
 
39
39
  def block?
@@ -3,10 +3,10 @@ module Tapyrus
3
3
  # mempool message
4
4
  # https://bitcoin.org/en/developer-reference#mempool
5
5
  class MemPool < Base
6
- COMMAND = 'mempool'
6
+ COMMAND = "mempool"
7
7
 
8
8
  def to_payload
9
- ''
9
+ ""
10
10
  end
11
11
  end
12
12
  end
@@ -3,7 +3,7 @@ module Tapyrus
3
3
  # merckleblock message
4
4
  # https://bitcoin.org/en/developer-reference#merkleblock
5
5
  class MerkleBlock < Base
6
- COMMAND = 'merkleblock'
6
+ COMMAND = "merkleblock"
7
7
 
8
8
  attr_accessor :header
9
9
  attr_accessor :tx_count
@@ -18,7 +18,7 @@ module Tapyrus
18
18
  m = new
19
19
  buf = StringIO.new(payload)
20
20
  m.header = Tapyrus::BlockHeader.parse_from_payload(buf)
21
- m.tx_count = buf.read(4).unpack('V').first
21
+ m.tx_count = buf.read(4).unpack("V").first
22
22
  hash_count = Tapyrus.unpack_var_int_from_io(buf)
23
23
  hash_count.times { m.hashes << buf.read(32).bth }
24
24
  flag_count = Tapyrus.unpack_var_int_from_io(buf)
@@ -29,7 +29,7 @@ module Tapyrus
29
29
  end
30
30
 
31
31
  def to_payload
32
- header.to_payload << [tx_count].pack('V') << Tapyrus.pack_var_int(hashes.size) << hashes.map(&:htb).join <<
32
+ header.to_payload << [tx_count].pack("V") << Tapyrus.pack_var_int(hashes.size) << hashes.map(&:htb).join <<
33
33
  Tapyrus.pack_var_int(flags.htb.bytesize) << flags.htb
34
34
  end
35
35
  end
@@ -1,4 +1,4 @@
1
- require 'ipaddr'
1
+ require "ipaddr"
2
2
 
3
3
  module Tapyrus
4
4
  module Message
@@ -19,7 +19,7 @@ module Tapyrus
19
19
  attr_reader :skip_time
20
20
 
21
21
  def initialize(
22
- ip: '127.0.0.1',
22
+ ip: "127.0.0.1",
23
23
  port: Tapyrus.chain_params.default_port,
24
24
  services: DEFAULT_SERVICE_FLAGS,
25
25
  time: Time.now.to_i
@@ -34,16 +34,16 @@ module Tapyrus
34
34
  buf = payload.is_a?(String) ? StringIO.new(payload) : payload
35
35
  has_time = buf.size > 26
36
36
  addr = new(time: nil)
37
- addr.time = buf.read(4).unpack('V').first if has_time
38
- addr.services = buf.read(8).unpack('Q').first
37
+ addr.time = buf.read(4).unpack("V").first if has_time
38
+ addr.services = buf.read(8).unpack("Q").first
39
39
  addr.ip_addr = IPAddr.new_ntoh(buf.read(16))
40
- addr.port = buf.read(2).unpack('n').first
40
+ addr.port = buf.read(2).unpack("n").first
41
41
  addr
42
42
  end
43
43
 
44
44
  def self.local_addr
45
45
  addr = new
46
- addr.ip_addr = IPAddr.new('127.0.0.1')
46
+ addr.ip_addr = IPAddr.new("127.0.0.1")
47
47
  addr.port = Tapyrus.chain_params.default_port
48
48
  addr.services = DEFAULT_SERVICE_FLAGS
49
49
  addr
@@ -54,10 +54,10 @@ module Tapyrus
54
54
  end
55
55
 
56
56
  def to_payload(skip_time = false)
57
- p = ''
58
- p << [time].pack('V') unless skip_time
57
+ p = ""
58
+ p << [time].pack("V") unless skip_time
59
59
  addr = ip_addr.ipv4? ? ip_addr.ipv4_mapped : ip_addr
60
- p << [services].pack('Q') << addr.hton << [port].pack('n')
60
+ p << [services].pack("Q") << addr.hton << [port].pack("n")
61
61
  end
62
62
  end
63
63
  end
@@ -8,7 +8,7 @@ module Tapyrus
8
8
 
9
9
  attr_reader :inventories
10
10
 
11
- COMMAND = 'notfound'
11
+ COMMAND = "notfound"
12
12
 
13
13
  def initialize(inventories = [])
14
14
  @inventories = inventories
@@ -3,7 +3,7 @@ module Tapyrus
3
3
  # ping message class
4
4
  # https://bitcoin.org/en/developer-reference#ping
5
5
  class Ping < Base
6
- COMMAND = 'ping'
6
+ COMMAND = "ping"
7
7
 
8
8
  attr_accessor :nonce
9
9
 
@@ -12,11 +12,11 @@ module Tapyrus
12
12
  end
13
13
 
14
14
  def self.parse_from_payload(payload)
15
- new(payload.unpack('Q').first)
15
+ new(payload.unpack("Q").first)
16
16
  end
17
17
 
18
18
  def to_payload
19
- [nonce].pack('Q')
19
+ [nonce].pack("Q")
20
20
  end
21
21
 
22
22
  def to_response
@@ -3,7 +3,7 @@ module Tapyrus
3
3
  # pong message
4
4
  # https://bitcoin.org/en/developer-reference#pong
5
5
  class Pong < Base
6
- COMMAND = 'pong'
6
+ COMMAND = "pong"
7
7
 
8
8
  attr_reader :nonce
9
9
 
@@ -12,11 +12,11 @@ module Tapyrus
12
12
  end
13
13
 
14
14
  def self.parse_from_payload(payload)
15
- new(payload.unpack('Q').first)
15
+ new(payload.unpack("Q").first)
16
16
  end
17
17
 
18
18
  def to_payload
19
- [nonce].pack('Q')
19
+ [nonce].pack("Q")
20
20
  end
21
21
  end
22
22
  end
@@ -8,7 +8,7 @@ module Tapyrus
8
8
  attr_accessor :reason
9
9
  attr_accessor :extra
10
10
 
11
- COMMAND = 'reject'
11
+ COMMAND = "reject"
12
12
 
13
13
  CODE_MALFORMED = 0x01
14
14
  CODE_INVALID = 0x10
@@ -19,7 +19,7 @@ module Tapyrus
19
19
  CODE_INSUFFICIENT_FEE = 0x42
20
20
  CODE_CHECKPOINT = 0x43
21
21
 
22
- def initialize(message, code, reason = '', extra = '')
22
+ def initialize(message, code, reason = "", extra = "")
23
23
  @message = message
24
24
  @code = code
25
25
  @reason = reason
@@ -28,15 +28,15 @@ module Tapyrus
28
28
 
29
29
  def self.parse_from_payload(payload)
30
30
  message, payload = Tapyrus.unpack_var_string(payload)
31
- code, payload = payload.unpack('Ca*')
31
+ code, payload = payload.unpack("Ca*")
32
32
  reason, payload = Tapyrus.unpack_var_string(payload)
33
- extra = ['tx', 'block'].include?(message) ? payload.bth : payload
33
+ extra = %w[tx block].include?(message) ? payload.bth : payload
34
34
  new(message, code, reason, extra)
35
35
  end
36
36
 
37
37
  def to_payload
38
- e = ['tx', 'block'].include?(message) ? extra.htb : extra
39
- Tapyrus.pack_var_string(message) << [code].pack('C') << Tapyrus.pack_var_string(reason) << e
38
+ e = %w[tx block].include?(message) ? extra.htb : extra
39
+ Tapyrus.pack_var_string(message) << [code].pack("C") << Tapyrus.pack_var_string(reason) << e
40
40
  end
41
41
  end
42
42
  end
@@ -3,7 +3,7 @@ module Tapyrus
3
3
  # sendcmpct message
4
4
  # https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki
5
5
  class SendCmpct < Base
6
- COMMAND = 'sendcmpct'
6
+ COMMAND = "sendcmpct"
7
7
 
8
8
  MODE_HIGH = 1
9
9
  MODE_LOW = 0
@@ -20,13 +20,13 @@ module Tapyrus
20
20
 
21
21
  def self.parse_from_payload(payload)
22
22
  buf = StringIO.new(payload)
23
- mode = buf.read(1).unpack('c').first
24
- version = buf.read(8).unpack('Q').first
23
+ mode = buf.read(1).unpack("c").first
24
+ version = buf.read(8).unpack("Q").first
25
25
  new(mode, version)
26
26
  end
27
27
 
28
28
  def to_payload
29
- [mode, version].pack('cQ')
29
+ [mode, version].pack("cQ")
30
30
  end
31
31
 
32
32
  def high?
@@ -3,10 +3,10 @@ module Tapyrus
3
3
  # sendheaders message
4
4
  # https://bitcoin.org/en/developer-reference#sendheaders
5
5
  class SendHeaders < Base
6
- COMMAND = 'sendheaders'
6
+ COMMAND = "sendheaders"
7
7
 
8
8
  def to_payload
9
- ''
9
+ ""
10
10
  end
11
11
  end
12
12
  end
@@ -3,7 +3,7 @@ module Tapyrus
3
3
  # tx message
4
4
  # https://bitcoin.org/en/developer-reference#tx
5
5
  class Tx < Base
6
- COMMAND = 'tx'
6
+ COMMAND = "tx"
7
7
 
8
8
  attr_accessor :tx
9
9
  attr_accessor :use_segwit
@@ -3,10 +3,10 @@ module Tapyrus
3
3
  # verack message
4
4
  # https://bitcoin.org/en/developer-reference#verack
5
5
  class VerAck < Base
6
- COMMAND = 'verack'
6
+ COMMAND = "verack"
7
7
 
8
8
  def to_payload
9
- ''
9
+ ""
10
10
  end
11
11
  end
12
12
  end
@@ -1,10 +1,10 @@
1
1
  # encoding: ascii-8bit
2
- require 'ipaddr'
2
+ require "ipaddr"
3
3
  module Tapyrus
4
4
  module Message
5
5
  # https://bitcoin.org/en/developer-reference#version
6
6
  class Version < Base
7
- COMMAND = 'version'
7
+ COMMAND = "version"
8
8
 
9
9
  attr_accessor :version
10
10
  attr_accessor :services
@@ -30,7 +30,7 @@ module Tapyrus
30
30
  end
31
31
 
32
32
  def self.parse_from_payload(payload)
33
- version, services, timestamp, local_addr, remote_addr, nonce, rest = payload.unpack('VQQa26a26Qa*')
33
+ version, services, timestamp, local_addr, remote_addr, nonce, rest = payload.unpack("VQQa26a26Qa*")
34
34
  v = new
35
35
  v.version = version
36
36
  v.services = services
@@ -39,7 +39,7 @@ module Tapyrus
39
39
  v.remote_addr = NetworkAddr.parse_from_payload(remote_addr)
40
40
  v.nonce = nonce
41
41
  user_agent, rest = unpack_var_string(rest)
42
- start_height, rest = rest.unpack('Va*')
42
+ start_height, rest = rest.unpack("Va*")
43
43
  v.user_agent = user_agent
44
44
  v.start_height = start_height
45
45
  v.relay = v.unpack_relay_field(rest).first
@@ -48,12 +48,12 @@ module Tapyrus
48
48
 
49
49
  def to_payload
50
50
  [
51
- [version, services, timestamp].pack('VQQ'),
51
+ [version, services, timestamp].pack("VQQ"),
52
52
  local_addr.to_payload(true),
53
53
  remote_addr.to_payload(true),
54
- [nonce].pack('Q'),
54
+ [nonce].pack("Q"),
55
55
  pack_var_string(user_agent),
56
- [start_height].pack('V'),
56
+ [start_height].pack("V"),
57
57
  pack_boolean(relay)
58
58
  ].join
59
59
  end
@@ -1,41 +1,41 @@
1
1
  module Tapyrus
2
2
  module Message
3
- autoload :Base, 'tapyrus/message/base'
4
- autoload :Inventory, 'tapyrus/message/inventory'
5
- autoload :InventoriesParser, 'tapyrus/message/inventories_parser'
6
- autoload :HeadersParser, 'tapyrus/message/headers_parser'
7
- autoload :Version, 'tapyrus/message/version'
8
- autoload :VerAck, 'tapyrus/message/ver_ack'
9
- autoload :Addr, 'tapyrus/message/addr'
10
- autoload :NetworkAddr, 'tapyrus/message/network_addr'
11
- autoload :Block, 'tapyrus/message/block'
12
- autoload :FilterLoad, 'tapyrus/message/filter_load'
13
- autoload :FilterAdd, 'tapyrus/message/filter_add'
14
- autoload :FilterClear, 'tapyrus/message/filter_clear'
15
- autoload :MerkleBlock, 'tapyrus/message/merkle_block'
16
- autoload :Tx, 'tapyrus/message/tx'
17
- autoload :Ping, 'tapyrus/message/ping'
18
- autoload :Pong, 'tapyrus/message/pong'
19
- autoload :Inv, 'tapyrus/message/inv'
20
- autoload :GetBlocks, 'tapyrus/message/get_blocks'
21
- autoload :GetHeaders, 'tapyrus/message/get_headers'
22
- autoload :Headers, 'tapyrus/message/headers'
23
- autoload :GetAddr, 'tapyrus/message/get_addr'
24
- autoload :GetData, 'tapyrus/message/get_data'
25
- autoload :SendHeaders, 'tapyrus/message/send_headers'
26
- autoload :FeeFilter, 'tapyrus/message/fee_filter'
27
- autoload :MemPool, 'tapyrus/message/mem_pool'
28
- autoload :NotFound, 'tapyrus/message/not_found'
29
- autoload :Error, 'tapyrus/message/error'
30
- autoload :Reject, 'tapyrus/message/reject'
31
- autoload :SendCmpct, 'tapyrus/message/send_cmpct'
32
- autoload :CmpctBlock, 'tapyrus/message/cmpct_block'
33
- autoload :HeaderAndShortIDs, 'tapyrus/message/header_and_short_ids'
34
- autoload :PrefilledTx, 'tapyrus/message/prefilled_tx'
35
- autoload :GetBlockTxn, 'tapyrus/message/get_block_txn'
36
- autoload :BlockTransactionRequest, 'tapyrus/message/block_transaction_request'
37
- autoload :BlockTxn, 'tapyrus/message/block_txn'
38
- autoload :BlockTransactions, 'tapyrus/message/block_transactions'
3
+ autoload :Base, "tapyrus/message/base"
4
+ autoload :Inventory, "tapyrus/message/inventory"
5
+ autoload :InventoriesParser, "tapyrus/message/inventories_parser"
6
+ autoload :HeadersParser, "tapyrus/message/headers_parser"
7
+ autoload :Version, "tapyrus/message/version"
8
+ autoload :VerAck, "tapyrus/message/ver_ack"
9
+ autoload :Addr, "tapyrus/message/addr"
10
+ autoload :NetworkAddr, "tapyrus/message/network_addr"
11
+ autoload :Block, "tapyrus/message/block"
12
+ autoload :FilterLoad, "tapyrus/message/filter_load"
13
+ autoload :FilterAdd, "tapyrus/message/filter_add"
14
+ autoload :FilterClear, "tapyrus/message/filter_clear"
15
+ autoload :MerkleBlock, "tapyrus/message/merkle_block"
16
+ autoload :Tx, "tapyrus/message/tx"
17
+ autoload :Ping, "tapyrus/message/ping"
18
+ autoload :Pong, "tapyrus/message/pong"
19
+ autoload :Inv, "tapyrus/message/inv"
20
+ autoload :GetBlocks, "tapyrus/message/get_blocks"
21
+ autoload :GetHeaders, "tapyrus/message/get_headers"
22
+ autoload :Headers, "tapyrus/message/headers"
23
+ autoload :GetAddr, "tapyrus/message/get_addr"
24
+ autoload :GetData, "tapyrus/message/get_data"
25
+ autoload :SendHeaders, "tapyrus/message/send_headers"
26
+ autoload :FeeFilter, "tapyrus/message/fee_filter"
27
+ autoload :MemPool, "tapyrus/message/mem_pool"
28
+ autoload :NotFound, "tapyrus/message/not_found"
29
+ autoload :Error, "tapyrus/message/error"
30
+ autoload :Reject, "tapyrus/message/reject"
31
+ autoload :SendCmpct, "tapyrus/message/send_cmpct"
32
+ autoload :CmpctBlock, "tapyrus/message/cmpct_block"
33
+ autoload :HeaderAndShortIDs, "tapyrus/message/header_and_short_ids"
34
+ autoload :PrefilledTx, "tapyrus/message/prefilled_tx"
35
+ autoload :GetBlockTxn, "tapyrus/message/get_block_txn"
36
+ autoload :BlockTransactionRequest, "tapyrus/message/block_transaction_request"
37
+ autoload :BlockTxn, "tapyrus/message/block_txn"
38
+ autoload :BlockTransactions, "tapyrus/message/block_transactions"
39
39
 
40
40
  USER_AGENT = "/tapyrusrb:#{Tapyrus::VERSION}/"
41
41
 
@@ -52,7 +52,7 @@ module Tapyrus
52
52
 
53
53
  DEFAULT_SERVICE_FLAGS = SERVICE_FLAGS[:none]
54
54
 
55
- DEFAULT_STOP_HASH = '00' * 32
55
+ DEFAULT_STOP_HASH = "00" * 32
56
56
 
57
57
  # the protocol version.
58
58
  VERSION = {
@@ -7,13 +7,13 @@ module Tapyrus
7
7
  attr_reader :word_list
8
8
 
9
9
  def initialize(word_list)
10
- raise ArgumentError, 'specified language is not supported.' unless Mnemonic.word_lists.include?(word_list)
10
+ raise ArgumentError, "specified language is not supported." unless Mnemonic.word_lists.include?(word_list)
11
11
  @word_list = word_list
12
12
  end
13
13
 
14
14
  # get support language list
15
15
  def self.word_lists
16
- Dir.glob("#{WORD_DIR}/**.txt").map { |f| f.gsub("#{WORD_DIR}/", '').gsub('.txt', '') }
16
+ Dir.glob("#{WORD_DIR}/**.txt").map { |f| f.gsub("#{WORD_DIR}/", "").gsub(".txt", "") }
17
17
  end
18
18
 
19
19
  # generate entropy from mnemonic word
@@ -22,23 +22,25 @@ module Tapyrus
22
22
  def to_entropy(words)
23
23
  word_master = load_words
24
24
  mnemonic =
25
- words.map do |w|
26
- index = word_master.index(w.downcase)
27
- raise IndexError, 'word not found in words list.' unless index
28
- index.to_s(2).rjust(11, '0')
29
- end.join
25
+ words
26
+ .map do |w|
27
+ index = word_master.index(w.downcase)
28
+ raise IndexError, "word not found in words list." unless index
29
+ index.to_s(2).rjust(11, "0")
30
+ end
31
+ .join
30
32
  entropy = mnemonic.slice(0, (mnemonic.length * 32) / 33)
31
- checksum = mnemonic.gsub(entropy, '')
32
- raise SecurityError, 'checksum mismatch.' unless checksum == checksum(entropy)
33
- [entropy].pack('B*').bth
33
+ checksum = mnemonic.gsub(entropy, "")
34
+ raise SecurityError, "checksum mismatch." unless checksum == checksum(entropy)
35
+ [entropy].pack("B*").bth
34
36
  end
35
37
 
36
38
  # generate mnemonic words from entropy.
37
39
  # @param [String] entropy an entropy with hex format.
38
40
  # @return [Array] the array of mnemonic word.
39
41
  def to_mnemonic(entropy)
40
- raise ArgumentError, 'entropy is empty.' if entropy.nil? || entropy.empty?
41
- e = entropy.htb.unpack('B*').first
42
+ raise ArgumentError, "entropy is empty." if entropy.nil? || entropy.empty?
43
+ e = entropy.htb.unpack("B*").first
42
44
  seed = e + checksum(e)
43
45
  mnemonic_index = seed.chars.each_slice(11).map { |i| i.join.to_i(2) }
44
46
  word_master = load_words
@@ -50,11 +52,11 @@ module Tapyrus
50
52
  # @param [Array] mnemonic a array of mnemonic word.
51
53
  # @param [String] passphrase a passphrase which protects mnemonic. the default value is an empty string.
52
54
  # @return [String] seed
53
- def to_seed(mnemonic, passphrase: '')
55
+ def to_seed(mnemonic, passphrase: "")
54
56
  to_entropy(mnemonic)
55
57
  OpenSSL::PKCS5.pbkdf2_hmac(
56
- mnemonic.join(' ').downcase,
57
- 'mnemonic' + passphrase,
58
+ mnemonic.join(" ").downcase,
59
+ "mnemonic" + passphrase,
58
60
  2048,
59
61
  64,
60
62
  OpenSSL::Digest::SHA512.new
@@ -65,7 +67,7 @@ module Tapyrus
65
67
  # @param [String] entropy an entropy with bit string format
66
68
  # @return [String] an entropy checksum with bit string format
67
69
  def checksum(entropy)
68
- b = Tapyrus.sha256([entropy].pack('B*')).unpack('B*').first
70
+ b = Tapyrus.sha256([entropy].pack("B*")).unpack("B*").first
69
71
  b.slice(0, (entropy.length / 32))
70
72
  end
71
73
 
@@ -20,7 +20,7 @@ module Tapyrus
20
20
  @logger = peer.logger
21
21
  @sendheaders = false
22
22
  @attr_accessor = 0
23
- @message = ''
23
+ @message = ""
24
24
  self.pending_connect_timeout = 5.0
25
25
  end
26
26
 
@@ -44,7 +44,7 @@ module Tapyrus
44
44
  end
45
45
 
46
46
  # close network connection.
47
- def close(msg = '')
47
+ def close(msg = "")
48
48
  logger.info "close connection with #{addr}. #{msg}"
49
49
  close_connection_after_writing
50
50
  end