tapyrus 0.2.7 → 0.2.8

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 +37 -0
  3. data/.prettierignore +3 -0
  4. data/.prettierrc.yaml +3 -0
  5. data/CODE_OF_CONDUCT.md +7 -7
  6. data/README.md +14 -17
  7. data/Rakefile +3 -3
  8. data/lib/openassets.rb +0 -2
  9. data/lib/openassets/marker_output.rb +0 -4
  10. data/lib/openassets/payload.rb +4 -10
  11. data/lib/schnorr.rb +2 -3
  12. data/lib/schnorr/signature.rb +3 -6
  13. data/lib/tapyrus.rb +6 -22
  14. data/lib/tapyrus/base58.rb +7 -6
  15. data/lib/tapyrus/block.rb +1 -2
  16. data/lib/tapyrus/block_header.rb +15 -9
  17. data/lib/tapyrus/bloom_filter.rb +5 -3
  18. data/lib/tapyrus/chain_params.rb +1 -4
  19. data/lib/tapyrus/chainparams/dev.yml +3 -2
  20. data/lib/tapyrus/chainparams/prod.yml +3 -2
  21. data/lib/tapyrus/constants.rb +29 -23
  22. data/lib/tapyrus/errors.rb +1 -3
  23. data/lib/tapyrus/ext.rb +1 -1
  24. data/lib/tapyrus/ext/ecdsa.rb +4 -4
  25. data/lib/tapyrus/ext/json_parser.rb +1 -4
  26. data/lib/tapyrus/ext_key.rb +38 -34
  27. data/lib/tapyrus/key.rb +31 -35
  28. data/lib/tapyrus/key_path.rb +15 -12
  29. data/lib/tapyrus/logger.rb +20 -16
  30. data/lib/tapyrus/merkle_tree.rb +19 -20
  31. data/lib/tapyrus/message.rb +14 -16
  32. data/lib/tapyrus/message/addr.rb +1 -7
  33. data/lib/tapyrus/message/base.rb +0 -3
  34. data/lib/tapyrus/message/block.rb +2 -9
  35. data/lib/tapyrus/message/block_transaction_request.rb +3 -6
  36. data/lib/tapyrus/message/block_transactions.rb +2 -6
  37. data/lib/tapyrus/message/block_txn.rb +0 -4
  38. data/lib/tapyrus/message/cmpct_block.rb +1 -7
  39. data/lib/tapyrus/message/error.rb +1 -4
  40. data/lib/tapyrus/message/fee_filter.rb +1 -4
  41. data/lib/tapyrus/message/filter_add.rb +0 -4
  42. data/lib/tapyrus/message/filter_clear.rb +0 -4
  43. data/lib/tapyrus/message/filter_load.rb +2 -5
  44. data/lib/tapyrus/message/get_addr.rb +0 -4
  45. data/lib/tapyrus/message/get_block_txn.rb +0 -4
  46. data/lib/tapyrus/message/get_blocks.rb +0 -3
  47. data/lib/tapyrus/message/get_data.rb +1 -4
  48. data/lib/tapyrus/message/get_headers.rb +1 -3
  49. data/lib/tapyrus/message/header_and_short_ids.rb +3 -9
  50. data/lib/tapyrus/message/headers.rb +0 -4
  51. data/lib/tapyrus/message/headers_parser.rb +3 -8
  52. data/lib/tapyrus/message/inv.rb +1 -4
  53. data/lib/tapyrus/message/inventories_parser.rb +2 -7
  54. data/lib/tapyrus/message/inventory.rb +12 -5
  55. data/lib/tapyrus/message/mem_pool.rb +0 -4
  56. data/lib/tapyrus/message/merkle_block.rb +4 -9
  57. data/lib/tapyrus/message/network_addr.rb +7 -6
  58. data/lib/tapyrus/message/not_found.rb +0 -3
  59. data/lib/tapyrus/message/ping.rb +0 -3
  60. data/lib/tapyrus/message/pong.rb +0 -3
  61. data/lib/tapyrus/message/prefilled_tx.rb +0 -4
  62. data/lib/tapyrus/message/reject.rb +0 -3
  63. data/lib/tapyrus/message/send_cmpct.rb +1 -3
  64. data/lib/tapyrus/message/send_headers.rb +0 -3
  65. data/lib/tapyrus/message/tx.rb +0 -4
  66. data/lib/tapyrus/message/ver_ack.rb +1 -5
  67. data/lib/tapyrus/message/version.rb +2 -5
  68. data/lib/tapyrus/mnemonic.rb +17 -15
  69. data/lib/tapyrus/network.rb +0 -2
  70. data/lib/tapyrus/network/connection.rb +0 -3
  71. data/lib/tapyrus/network/message_handler.rb +61 -60
  72. data/lib/tapyrus/network/peer.rb +13 -12
  73. data/lib/tapyrus/network/peer_discovery.rb +3 -5
  74. data/lib/tapyrus/network/pool.rb +12 -12
  75. data/lib/tapyrus/node.rb +1 -1
  76. data/lib/tapyrus/node/cli.rb +12 -14
  77. data/lib/tapyrus/node/configuration.rb +1 -3
  78. data/lib/tapyrus/node/spv.rb +2 -3
  79. data/lib/tapyrus/opcodes.rb +9 -7
  80. data/lib/tapyrus/out_point.rb +5 -5
  81. data/lib/tapyrus/rpc/http_server.rb +21 -22
  82. data/lib/tapyrus/rpc/request_handler.rb +42 -44
  83. data/lib/tapyrus/rpc/tapyrus_core_client.rb +53 -25
  84. data/lib/tapyrus/script/color.rb +10 -0
  85. data/lib/tapyrus/script/multisig.rb +13 -12
  86. data/lib/tapyrus/script/script.rb +72 -71
  87. data/lib/tapyrus/script/script_error.rb +1 -4
  88. data/lib/tapyrus/script/script_interpreter.rb +439 -399
  89. data/lib/tapyrus/script/tx_checker.rb +20 -10
  90. data/lib/tapyrus/secp256k1.rb +0 -4
  91. data/lib/tapyrus/secp256k1/native.rb +14 -15
  92. data/lib/tapyrus/secp256k1/rfc6979.rb +7 -4
  93. data/lib/tapyrus/secp256k1/ruby.rb +10 -12
  94. data/lib/tapyrus/slip39.rb +20 -5
  95. data/lib/tapyrus/slip39/share.rb +41 -29
  96. data/lib/tapyrus/slip39/sss.rb +101 -57
  97. data/lib/tapyrus/store.rb +1 -3
  98. data/lib/tapyrus/store/chain_entry.rb +0 -4
  99. data/lib/tapyrus/store/db.rb +0 -2
  100. data/lib/tapyrus/store/db/level_db.rb +5 -9
  101. data/lib/tapyrus/store/spv_chain.rb +11 -17
  102. data/lib/tapyrus/tx.rb +45 -37
  103. data/lib/tapyrus/tx_builder.rb +158 -0
  104. data/lib/tapyrus/tx_in.rb +1 -6
  105. data/lib/tapyrus/tx_out.rb +2 -7
  106. data/lib/tapyrus/util.rb +7 -9
  107. data/lib/tapyrus/validation.rb +12 -11
  108. data/lib/tapyrus/version.rb +1 -1
  109. data/lib/tapyrus/wallet/account.rb +22 -18
  110. data/lib/tapyrus/wallet/base.rb +12 -9
  111. data/lib/tapyrus/wallet/db.rb +6 -9
  112. data/lib/tapyrus/wallet/master_key.rb +2 -4
  113. data/tapyrusrb.gemspec +13 -14
  114. metadata +21 -4
  115. data/.travis.yml +0 -14
@@ -1,6 +1,5 @@
1
1
  module Tapyrus
2
2
  module Message
3
-
4
3
  # notfound message
5
4
  # https://bitcoin.org/en/developer-reference#notfound
6
5
  class NotFound < Base
@@ -14,8 +13,6 @@ module Tapyrus
14
13
  def initialize(inventories = [])
15
14
  @inventories = inventories
16
15
  end
17
-
18
16
  end
19
17
  end
20
-
21
18
  end
@@ -1,10 +1,8 @@
1
1
  module Tapyrus
2
2
  module Message
3
-
4
3
  # ping message class
5
4
  # https://bitcoin.org/en/developer-reference#ping
6
5
  class Ping < Base
7
-
8
6
  COMMAND = 'ping'
9
7
 
10
8
  attr_accessor :nonce
@@ -24,7 +22,6 @@ module Tapyrus
24
22
  def to_response
25
23
  Pong.new(nonce)
26
24
  end
27
-
28
25
  end
29
26
  end
30
27
  end
@@ -1,10 +1,8 @@
1
1
  module Tapyrus
2
2
  module Message
3
-
4
3
  # pong message
5
4
  # https://bitcoin.org/en/developer-reference#pong
6
5
  class Pong < Base
7
-
8
6
  COMMAND = 'pong'
9
7
 
10
8
  attr_reader :nonce
@@ -21,6 +19,5 @@ module Tapyrus
21
19
  [nonce].pack('Q')
22
20
  end
23
21
  end
24
-
25
22
  end
26
23
  end
@@ -1,10 +1,8 @@
1
1
  module Tapyrus
2
2
  module Message
3
-
4
3
  # A PrefilledTransaction structure is used in HeaderAndShortIDs to provide a list of a few transactions explicitly.
5
4
  # https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki
6
5
  class PrefilledTx
7
-
8
6
  attr_accessor :index
9
7
  attr_accessor :tx
10
8
 
@@ -22,8 +20,6 @@ module Tapyrus
22
20
  def to_payload
23
21
  Tapyrus.pack_var_int(index) << tx.to_payload
24
22
  end
25
-
26
23
  end
27
-
28
24
  end
29
25
  end
@@ -1,10 +1,8 @@
1
1
  module Tapyrus
2
2
  module Message
3
-
4
3
  # reject message
5
4
  # https://bitcoin.org/en/developer-reference#reject
6
5
  class Reject < Base
7
-
8
6
  attr_accessor :message
9
7
  attr_accessor :code
10
8
  attr_accessor :reason
@@ -40,7 +38,6 @@ module Tapyrus
40
38
  e = ['tx', 'block'].include?(message) ? extra.htb : extra
41
39
  Tapyrus.pack_var_string(message) << [code].pack('C') << Tapyrus.pack_var_string(reason) << e
42
40
  end
43
-
44
41
  end
45
42
  end
46
43
  end
@@ -1,10 +1,8 @@
1
1
  module Tapyrus
2
2
  module Message
3
-
4
3
  # sendcmpct message
5
4
  # https://github.com/bitcoin/bips/blob/master/bip-0152.mediawiki
6
5
  class SendCmpct < Base
7
-
8
6
  COMMAND = 'sendcmpct'
9
7
 
10
8
  MODE_HIGH = 1
@@ -12,6 +10,7 @@ module Tapyrus
12
10
 
13
11
  attr_accessor :mode
14
12
  attr_accessor :version
13
+
15
14
  # TODO support version 2
16
15
 
17
16
  def initialize(mode = MODE_HIGH, version = 1)
@@ -38,6 +37,5 @@ module Tapyrus
38
37
  mode.zero?
39
38
  end
40
39
  end
41
-
42
40
  end
43
41
  end
@@ -1,16 +1,13 @@
1
1
  module Tapyrus
2
2
  module Message
3
-
4
3
  # sendheaders message
5
4
  # https://bitcoin.org/en/developer-reference#sendheaders
6
5
  class SendHeaders < Base
7
-
8
6
  COMMAND = 'sendheaders'
9
7
 
10
8
  def to_payload
11
9
  ''
12
10
  end
13
11
  end
14
-
15
12
  end
16
13
  end
@@ -1,10 +1,8 @@
1
1
  module Tapyrus
2
2
  module Message
3
-
4
3
  # tx message
5
4
  # https://bitcoin.org/en/developer-reference#tx
6
5
  class Tx < Base
7
-
8
6
  COMMAND = 'tx'
9
7
 
10
8
  attr_accessor :tx
@@ -23,8 +21,6 @@ module Tapyrus
23
21
  def to_payload
24
22
  tx.to_payload
25
23
  end
26
-
27
24
  end
28
-
29
25
  end
30
26
  end
@@ -1,17 +1,13 @@
1
1
  module Tapyrus
2
2
  module Message
3
-
4
3
  # verack message
5
4
  # https://bitcoin.org/en/developer-reference#verack
6
5
  class VerAck < Base
7
-
8
6
  COMMAND = 'verack'
9
7
 
10
8
  def to_payload
11
9
  ''
12
10
  end
13
-
14
11
  end
15
-
16
12
  end
17
- end
13
+ end
@@ -2,10 +2,8 @@
2
2
  require 'ipaddr'
3
3
  module Tapyrus
4
4
  module Message
5
-
6
5
  # https://bitcoin.org/en/developer-reference#version
7
6
  class Version < Base
8
-
9
7
  COMMAND = 'version'
10
8
 
11
9
  attr_accessor :version
@@ -61,9 +59,8 @@ module Tapyrus
61
59
  end
62
60
 
63
61
  def unpack_relay_field(payload)
64
- ( version >= 70001 && payload ) ? unpack_boolean(payload) : [ true, nil ]
62
+ (version >= 70_001 && payload) ? unpack_boolean(payload) : [true, nil]
65
63
  end
66
-
67
64
  end
68
65
  end
69
- end
66
+ end
@@ -1,9 +1,7 @@
1
1
  module Tapyrus
2
-
3
2
  # Mnemonic code for generating deterministic keys
4
3
  # https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki
5
4
  class Mnemonic
6
-
7
5
  WORD_DIR = "#{__dir__}/mnemonic/wordlist"
8
6
 
9
7
  attr_reader :word_list
@@ -15,7 +13,7 @@ module Tapyrus
15
13
 
16
14
  # get support language list
17
15
  def self.word_lists
18
- 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', '') }
19
17
  end
20
18
 
21
19
  # generate entropy from mnemonic word
@@ -23,11 +21,12 @@ module Tapyrus
23
21
  # @return [String] an entropy with hex format.
24
22
  def to_entropy(words)
25
23
  word_master = load_words
26
- mnemonic = words.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.join
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
31
30
  entropy = mnemonic.slice(0, (mnemonic.length * 32) / 33)
32
31
  checksum = mnemonic.gsub(entropy, '')
33
32
  raise SecurityError, 'checksum mismatch.' unless checksum == checksum(entropy)
@@ -41,9 +40,9 @@ module Tapyrus
41
40
  raise ArgumentError, 'entropy is empty.' if entropy.nil? || entropy.empty?
42
41
  e = entropy.htb.unpack('B*').first
43
42
  seed = e + checksum(e)
44
- mnemonic_index = seed.chars.each_slice(11).map{|i|i.join.to_i(2)}
43
+ mnemonic_index = seed.chars.each_slice(11).map { |i| i.join.to_i(2) }
45
44
  word_master = load_words
46
- mnemonic_index.map{|i|word_master[i]}
45
+ mnemonic_index.map { |i| word_master[i] }
47
46
  end
48
47
 
49
48
  # generate seed from mnemonic
@@ -53,8 +52,13 @@ module Tapyrus
53
52
  # @return [String] seed
54
53
  def to_seed(mnemonic, passphrase: '')
55
54
  to_entropy(mnemonic)
56
- OpenSSL::PKCS5.pbkdf2_hmac(mnemonic.join(' ').downcase,
57
- 'mnemonic' + passphrase, 2048, 64, OpenSSL::Digest::SHA512.new).bth
55
+ OpenSSL::PKCS5.pbkdf2_hmac(
56
+ mnemonic.join(' ').downcase,
57
+ 'mnemonic' + passphrase,
58
+ 2048,
59
+ 64,
60
+ OpenSSL::Digest::SHA512.new
61
+ ).bth
58
62
  end
59
63
 
60
64
  # calculate entropy checksum
@@ -62,7 +66,7 @@ module Tapyrus
62
66
  # @return [String] an entropy checksum with bit string format
63
67
  def checksum(entropy)
64
68
  b = Tapyrus.sha256([entropy].pack('B*')).unpack('B*').first
65
- b.slice(0, (entropy.length/32))
69
+ b.slice(0, (entropy.length / 32))
66
70
  end
67
71
 
68
72
  private
@@ -71,7 +75,5 @@ module Tapyrus
71
75
  def load_words
72
76
  File.readlines("#{WORD_DIR}/#{word_list}.txt").map(&:strip)
73
77
  end
74
-
75
78
  end
76
-
77
79
  end
@@ -2,12 +2,10 @@ require 'eventmachine'
2
2
 
3
3
  module Tapyrus
4
4
  module Network
5
-
6
5
  autoload :MessageHandler, 'tapyrus/network/message_handler'
7
6
  autoload :Connection, 'tapyrus/network/connection'
8
7
  autoload :Pool, 'tapyrus/network/pool'
9
8
  autoload :Peer, 'tapyrus/network/peer'
10
9
  autoload :PeerDiscovery, 'tapyrus/network/peer_discovery'
11
-
12
10
  end
13
11
  end
@@ -1,10 +1,7 @@
1
1
  module Tapyrus
2
-
3
2
  module Network
4
-
5
3
  # Basic Bitcoin P2P connection class
6
4
  class Connection < EM::Connection
7
-
8
5
  include MessageHandler
9
6
 
10
7
  attr_reader :peer, :logger
@@ -1,9 +1,7 @@
1
1
  module Tapyrus
2
2
  module Network
3
-
4
3
  # P2P message handler used by peer connection class.
5
4
  module MessageHandler
6
-
7
5
  # handle p2p message.
8
6
  def handle(message)
9
7
  peer.last_recv = Time.now.to_i
@@ -22,7 +20,7 @@ module Tapyrus
22
20
  return unless command
23
21
 
24
22
  defer_handle_command(command, payload)
25
- @message = ""
23
+ @message = ''
26
24
  parse(rest) if rest && rest.bytesize > 0
27
25
  end
28
26
 
@@ -35,7 +33,9 @@ module Tapyrus
35
33
 
36
34
  payload = @message[MESSAGE_HEADER_SIZE...(MESSAGE_HEADER_SIZE + length)]
37
35
  return if payload.size < length
38
- raise Tapyrus::Message::Error, "header checksum mismatch. #{checksum.bth}" unless Tapyrus.double_sha256(payload)[0...4] == checksum
36
+ unless Tapyrus.double_sha256(payload)[0...4] == checksum
37
+ raise Tapyrus::Message::Error, "header checksum mismatch. #{checksum.bth}"
38
+ end
39
39
 
40
40
  rest = @message[(MESSAGE_HEADER_SIZE + length)..-1]
41
41
  [command, payload, rest]
@@ -43,62 +43,63 @@ module Tapyrus
43
43
 
44
44
  # handle command with EM#defer
45
45
  def defer_handle_command(command, payload)
46
- operation = proc {handle_command(command, payload)}
47
- callback = proc{|result|}
48
- errback = proc{|e|
49
- logger.error("error occurred. #{e.message}")
50
- logger.error(e.backtrace)
51
- peer.handle_error(e)
52
- }
46
+ operation = proc { handle_command(command, payload) }
47
+ callback = proc { |result| }
48
+ errback =
49
+ proc do |e|
50
+ logger.error("error occurred. #{e.message}")
51
+ logger.error(e.backtrace)
52
+ peer.handle_error(e)
53
+ end
53
54
  EM.defer(operation, callback, errback)
54
55
  end
55
56
 
56
57
  def handle_command(command, payload)
57
58
  logger.info("[#{addr}] process command #{command}.")
58
59
  case command
59
- when Tapyrus::Message::Version::COMMAND
60
- on_version(Tapyrus::Message::Version.parse_from_payload(payload))
61
- when Tapyrus::Message::VerAck::COMMAND
62
- on_ver_ack
63
- when Tapyrus::Message::GetAddr::COMMAND
64
- on_get_addr
65
- when Tapyrus::Message::Addr::COMMAND
66
- on_addr(Tapyrus::Message::Addr.parse_from_payload(payload))
67
- when Tapyrus::Message::SendHeaders::COMMAND
68
- on_send_headers
69
- when Tapyrus::Message::FeeFilter::COMMAND
70
- on_fee_filter(Tapyrus::Message::FeeFilter.parse_from_payload(payload))
71
- when Tapyrus::Message::Ping::COMMAND
72
- on_ping(Tapyrus::Message::Ping.parse_from_payload(payload))
73
- when Tapyrus::Message::Pong::COMMAND
74
- on_pong(Tapyrus::Message::Pong.parse_from_payload(payload))
75
- when Tapyrus::Message::GetHeaders::COMMAND
76
- on_get_headers(Tapyrus::Message::GetHeaders.parse_from_payload(payload))
77
- when Tapyrus::Message::Headers::COMMAND
78
- on_headers(Tapyrus::Message::Headers.parse_from_payload(payload))
79
- when Tapyrus::Message::Block::COMMAND
80
- on_block(Tapyrus::Message::Block.parse_from_payload(payload))
81
- when Tapyrus::Message::Tx::COMMAND
82
- on_tx(Tapyrus::Message::Tx.parse_from_payload(payload))
83
- when Tapyrus::Message::NotFound::COMMAND
84
- on_not_found(Tapyrus::Message::NotFound.parse_from_payload(payload))
85
- when Tapyrus::Message::MemPool::COMMAND
86
- on_mem_pool
87
- when Tapyrus::Message::Reject::COMMAND
88
- on_reject(Tapyrus::Message::Reject.parse_from_payload(payload))
89
- when Tapyrus::Message::SendCmpct::COMMAND
90
- on_send_cmpct(Tapyrus::Message::SendCmpct.parse_from_payload(payload))
91
- when Tapyrus::Message::Inv::COMMAND
92
- on_inv(Tapyrus::Message::Inv.parse_from_payload(payload))
93
- when Tapyrus::Message::MerkleBlock::COMMAND
94
- on_merkle_block(Tapyrus::Message::MerkleBlock.parse_from_payload(payload))
95
- when Tapyrus::Message::CmpctBlock::COMMAND
96
- on_cmpct_block(Tapyrus::Message::CmpctBlock.parse_from_payload(payload))
97
- when Tapyrus::Message::GetData::COMMAND
98
- on_get_data(Tapyrus::Message::GetData.parse_from_payload(payload))
99
- else
100
- logger.warn("unsupported command received. command: #{command}, payload: #{payload.bth}")
101
- close("with command #{command}")
60
+ when Tapyrus::Message::Version::COMMAND
61
+ on_version(Tapyrus::Message::Version.parse_from_payload(payload))
62
+ when Tapyrus::Message::VerAck::COMMAND
63
+ on_ver_ack
64
+ when Tapyrus::Message::GetAddr::COMMAND
65
+ on_get_addr
66
+ when Tapyrus::Message::Addr::COMMAND
67
+ on_addr(Tapyrus::Message::Addr.parse_from_payload(payload))
68
+ when Tapyrus::Message::SendHeaders::COMMAND
69
+ on_send_headers
70
+ when Tapyrus::Message::FeeFilter::COMMAND
71
+ on_fee_filter(Tapyrus::Message::FeeFilter.parse_from_payload(payload))
72
+ when Tapyrus::Message::Ping::COMMAND
73
+ on_ping(Tapyrus::Message::Ping.parse_from_payload(payload))
74
+ when Tapyrus::Message::Pong::COMMAND
75
+ on_pong(Tapyrus::Message::Pong.parse_from_payload(payload))
76
+ when Tapyrus::Message::GetHeaders::COMMAND
77
+ on_get_headers(Tapyrus::Message::GetHeaders.parse_from_payload(payload))
78
+ when Tapyrus::Message::Headers::COMMAND
79
+ on_headers(Tapyrus::Message::Headers.parse_from_payload(payload))
80
+ when Tapyrus::Message::Block::COMMAND
81
+ on_block(Tapyrus::Message::Block.parse_from_payload(payload))
82
+ when Tapyrus::Message::Tx::COMMAND
83
+ on_tx(Tapyrus::Message::Tx.parse_from_payload(payload))
84
+ when Tapyrus::Message::NotFound::COMMAND
85
+ on_not_found(Tapyrus::Message::NotFound.parse_from_payload(payload))
86
+ when Tapyrus::Message::MemPool::COMMAND
87
+ on_mem_pool
88
+ when Tapyrus::Message::Reject::COMMAND
89
+ on_reject(Tapyrus::Message::Reject.parse_from_payload(payload))
90
+ when Tapyrus::Message::SendCmpct::COMMAND
91
+ on_send_cmpct(Tapyrus::Message::SendCmpct.parse_from_payload(payload))
92
+ when Tapyrus::Message::Inv::COMMAND
93
+ on_inv(Tapyrus::Message::Inv.parse_from_payload(payload))
94
+ when Tapyrus::Message::MerkleBlock::COMMAND
95
+ on_merkle_block(Tapyrus::Message::MerkleBlock.parse_from_payload(payload))
96
+ when Tapyrus::Message::CmpctBlock::COMMAND
97
+ on_cmpct_block(Tapyrus::Message::CmpctBlock.parse_from_payload(payload))
98
+ when Tapyrus::Message::GetData::COMMAND
99
+ on_get_data(Tapyrus::Message::GetData.parse_from_payload(payload))
100
+ else
101
+ logger.warn("unsupported command received. command: #{command}, payload: #{payload.bth}")
102
+ close("with command #{command}")
102
103
  end
103
104
  end
104
105
 
@@ -212,12 +213,12 @@ module Tapyrus
212
213
  txs = []
213
214
  inv.inventories.each do |i|
214
215
  case i.identifier
215
- when Tapyrus::Message::Inventory::MSG_TX
216
- txs << i.hash
217
- when Tapyrus::Message::Inventory::MSG_BLOCK
218
- blocks << i.hash
219
- else
220
- logger.warn("[#{addr}] peer sent unknown inv type: #{i.identifier}")
216
+ when Tapyrus::Message::Inventory::MSG_TX
217
+ txs << i.hash
218
+ when Tapyrus::Message::Inventory::MSG_BLOCK
219
+ blocks << i.hash
220
+ else
221
+ logger.warn("[#{addr}] peer sent unknown inv type: #{i.identifier}")
221
222
  end
222
223
  end
223
224
  logger.info("receive block= #{blocks.size}, txs: #{txs.size}")