tapyrus 0.2.4 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) 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 +14 -9
  12. data/lib/schnorr/sign_to_contract.rb +51 -0
  13. data/lib/schnorr/signature.rb +3 -6
  14. data/lib/tapyrus.rb +8 -30
  15. data/lib/tapyrus/base58.rb +7 -6
  16. data/lib/tapyrus/bip175.rb +67 -0
  17. data/lib/tapyrus/block.rb +1 -2
  18. data/lib/tapyrus/block_header.rb +15 -9
  19. data/lib/tapyrus/bloom_filter.rb +5 -3
  20. data/lib/tapyrus/chain_params.rb +1 -4
  21. data/lib/tapyrus/chainparams/dev.yml +3 -2
  22. data/lib/tapyrus/chainparams/prod.yml +3 -2
  23. data/lib/tapyrus/constants.rb +29 -23
  24. data/lib/tapyrus/errors.rb +1 -3
  25. data/lib/tapyrus/ext.rb +1 -1
  26. data/lib/tapyrus/ext/ecdsa.rb +4 -4
  27. data/lib/tapyrus/ext/json_parser.rb +1 -4
  28. data/lib/tapyrus/ext_key.rb +44 -32
  29. data/lib/tapyrus/key.rb +31 -35
  30. data/lib/tapyrus/key_path.rb +15 -12
  31. data/lib/tapyrus/logger.rb +20 -16
  32. data/lib/tapyrus/merkle_tree.rb +19 -20
  33. data/lib/tapyrus/message.rb +14 -16
  34. data/lib/tapyrus/message/addr.rb +1 -7
  35. data/lib/tapyrus/message/base.rb +0 -3
  36. data/lib/tapyrus/message/block.rb +2 -9
  37. data/lib/tapyrus/message/block_transaction_request.rb +3 -6
  38. data/lib/tapyrus/message/block_transactions.rb +2 -6
  39. data/lib/tapyrus/message/block_txn.rb +0 -4
  40. data/lib/tapyrus/message/cmpct_block.rb +1 -7
  41. data/lib/tapyrus/message/error.rb +1 -4
  42. data/lib/tapyrus/message/fee_filter.rb +1 -4
  43. data/lib/tapyrus/message/filter_add.rb +0 -4
  44. data/lib/tapyrus/message/filter_clear.rb +0 -4
  45. data/lib/tapyrus/message/filter_load.rb +2 -5
  46. data/lib/tapyrus/message/get_addr.rb +0 -4
  47. data/lib/tapyrus/message/get_block_txn.rb +0 -4
  48. data/lib/tapyrus/message/get_blocks.rb +0 -3
  49. data/lib/tapyrus/message/get_data.rb +1 -4
  50. data/lib/tapyrus/message/get_headers.rb +1 -3
  51. data/lib/tapyrus/message/header_and_short_ids.rb +3 -9
  52. data/lib/tapyrus/message/headers.rb +0 -4
  53. data/lib/tapyrus/message/headers_parser.rb +3 -8
  54. data/lib/tapyrus/message/inv.rb +1 -4
  55. data/lib/tapyrus/message/inventories_parser.rb +2 -7
  56. data/lib/tapyrus/message/inventory.rb +12 -5
  57. data/lib/tapyrus/message/mem_pool.rb +0 -4
  58. data/lib/tapyrus/message/merkle_block.rb +4 -9
  59. data/lib/tapyrus/message/network_addr.rb +7 -6
  60. data/lib/tapyrus/message/not_found.rb +0 -3
  61. data/lib/tapyrus/message/ping.rb +0 -3
  62. data/lib/tapyrus/message/pong.rb +0 -3
  63. data/lib/tapyrus/message/prefilled_tx.rb +0 -4
  64. data/lib/tapyrus/message/reject.rb +0 -3
  65. data/lib/tapyrus/message/send_cmpct.rb +1 -3
  66. data/lib/tapyrus/message/send_headers.rb +0 -3
  67. data/lib/tapyrus/message/tx.rb +0 -4
  68. data/lib/tapyrus/message/ver_ack.rb +1 -5
  69. data/lib/tapyrus/message/version.rb +2 -5
  70. data/lib/tapyrus/mnemonic.rb +17 -15
  71. data/lib/tapyrus/network.rb +0 -2
  72. data/lib/tapyrus/network/connection.rb +0 -3
  73. data/lib/tapyrus/network/message_handler.rb +61 -60
  74. data/lib/tapyrus/network/peer.rb +13 -12
  75. data/lib/tapyrus/network/peer_discovery.rb +3 -5
  76. data/lib/tapyrus/network/pool.rb +12 -12
  77. data/lib/tapyrus/node.rb +1 -1
  78. data/lib/tapyrus/node/cli.rb +12 -14
  79. data/lib/tapyrus/node/configuration.rb +1 -3
  80. data/lib/tapyrus/node/spv.rb +2 -3
  81. data/lib/tapyrus/opcodes.rb +9 -7
  82. data/lib/tapyrus/out_point.rb +5 -5
  83. data/lib/tapyrus/rpc.rb +1 -0
  84. data/lib/tapyrus/rpc/http_server.rb +21 -22
  85. data/lib/tapyrus/rpc/request_handler.rb +42 -44
  86. data/lib/tapyrus/rpc/tapyrus_core_client.rb +67 -25
  87. data/lib/tapyrus/script/color.rb +20 -2
  88. data/lib/tapyrus/script/multisig.rb +13 -12
  89. data/lib/tapyrus/script/script.rb +104 -67
  90. data/lib/tapyrus/script/script_error.rb +1 -4
  91. data/lib/tapyrus/script/script_interpreter.rb +439 -399
  92. data/lib/tapyrus/script/tx_checker.rb +20 -10
  93. data/lib/tapyrus/secp256k1.rb +0 -4
  94. data/lib/tapyrus/secp256k1/native.rb +14 -15
  95. data/lib/tapyrus/secp256k1/rfc6979.rb +7 -4
  96. data/lib/tapyrus/secp256k1/ruby.rb +10 -12
  97. data/lib/tapyrus/slip39.rb +20 -5
  98. data/lib/tapyrus/slip39/share.rb +41 -29
  99. data/lib/tapyrus/slip39/sss.rb +101 -57
  100. data/lib/tapyrus/store.rb +1 -3
  101. data/lib/tapyrus/store/chain_entry.rb +0 -4
  102. data/lib/tapyrus/store/db.rb +0 -2
  103. data/lib/tapyrus/store/db/level_db.rb +5 -9
  104. data/lib/tapyrus/store/spv_chain.rb +11 -17
  105. data/lib/tapyrus/tx.rb +45 -37
  106. data/lib/tapyrus/tx_builder.rb +158 -0
  107. data/lib/tapyrus/tx_in.rb +1 -6
  108. data/lib/tapyrus/tx_out.rb +2 -7
  109. data/lib/tapyrus/util.rb +20 -7
  110. data/lib/tapyrus/validation.rb +12 -11
  111. data/lib/tapyrus/version.rb +1 -1
  112. data/lib/tapyrus/wallet/account.rb +22 -18
  113. data/lib/tapyrus/wallet/base.rb +12 -9
  114. data/lib/tapyrus/wallet/db.rb +6 -9
  115. data/lib/tapyrus/wallet/master_key.rb +2 -4
  116. data/tapyrusrb.gemspec +13 -16
  117. metadata +22 -31
  118. data/.travis.yml +0 -12
@@ -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}")
@@ -1,9 +1,7 @@
1
1
  module Tapyrus
2
2
  module Network
3
-
4
3
  # remote peer class.
5
4
  class Peer
6
-
7
5
  # Interval for pinging peers.
8
6
  PING_INTERVAL = 2 * 60
9
7
 
@@ -22,13 +20,16 @@ module Tapyrus
22
20
  attr_accessor :outbound # TODO need implements to accept inbound connection
23
21
  attr_accessor :best_hash
24
22
  attr_accessor :best_height
23
+
25
24
  # remote peer info
26
25
  attr_reader :host
27
26
  attr_reader :port
27
+
28
28
  # remote peer connection
29
29
  attr_accessor :conn
30
30
  attr_accessor :connected
31
31
  attr_accessor :primary
32
+
32
33
  # parent pool
33
34
  attr_reader :pool
34
35
  attr_reader :chain
@@ -51,7 +52,8 @@ module Tapyrus
51
52
  @relay = configuration.conf[:relay]
52
53
  current_height = @chain.latest_block.height
53
54
  remote_addr = Tapyrus::Message::NetworkAddr.new(ip: host, port: port, time: nil)
54
- @local_version = Tapyrus::Message::Version.new(remote_addr: remote_addr, start_height: current_height, relay: @relay)
55
+ @local_version =
56
+ Tapyrus::Message::Version.new(remote_addr: remote_addr, start_height: current_height, relay: @relay)
55
57
  end
56
58
 
57
59
  def connect
@@ -84,16 +86,17 @@ module Tapyrus
84
86
  def post_handshake
85
87
  @connected = true
86
88
  pool.handle_new_peer(self)
89
+
87
90
  # require remote peer to use headers message instead fo inv message.
88
91
  conn.send_message(Tapyrus::Message::SendHeaders.new)
89
- EM.add_periodic_timer(PING_INTERVAL) {send_ping}
92
+ EM.add_periodic_timer(PING_INTERVAL) { send_ping }
90
93
  end
91
94
 
92
95
  # start block header download
93
96
  def start_block_header_download
94
97
  logger.info("[#{addr}] start block header download.")
95
- get_headers = Tapyrus::Message::GetHeaders.new(
96
- Tapyrus.chain_params.protocol_version, [chain.latest_block.block_hash])
98
+ get_headers =
99
+ Tapyrus::Message::GetHeaders.new(Tapyrus.chain_params.protocol_version, [chain.latest_block.block_hash])
97
100
  conn.send_message(get_headers)
98
101
  end
99
102
 
@@ -129,7 +132,7 @@ module Tapyrus
129
132
  @best_height = entry.height
130
133
  end
131
134
  pool.changed
132
- pool.notify_observers(:header, {hash: @best_hash, height: @best_height})
135
+ pool.notify_observers(:header, { hash: @best_hash, height: @best_height })
133
136
  start_block_header_download if headers.headers.size > 0 # next header download
134
137
  end
135
138
 
@@ -156,14 +159,13 @@ module Tapyrus
156
159
 
157
160
  # send +addr+ message to remote peer
158
161
  def send_addrs
159
- addrs = pool.peers.select{|p|p != self}.map(&:to_network_addr)
162
+ addrs = pool.peers.select { |p| p != self }.map(&:to_network_addr)
160
163
  conn.send_message(Tapyrus::Message::Addr.new(addrs))
161
164
  end
162
165
 
163
166
  # handle block inv message.
164
167
  def handle_block_inv(hashes)
165
- getdata = Tapyrus::Message::GetData.new(
166
- hashes.map{|h|Tapyrus::Message::Inventory.new(block_type, h)})
168
+ getdata = Tapyrus::Message::GetData.new(hashes.map { |h| Tapyrus::Message::Inventory.new(block_type, h) })
167
169
  conn.send_message(getdata)
168
170
  end
169
171
 
@@ -188,8 +190,7 @@ module Tapyrus
188
190
 
189
191
  # send filterload message.
190
192
  def send_filter_load(bloom)
191
- filter_load = Tapyrus::Message::FilterLoad.new(
192
- bloom, Tapyrus::Message::FilterLoad::BLOOM_UPDATE_ALL)
193
+ filter_load = Tapyrus::Message::FilterLoad.new(bloom, Tapyrus::Message::FilterLoad::BLOOM_UPDATE_ALL)
193
194
  conn.send_message(filter_load)
194
195
  end
195
196
 
@@ -1,8 +1,6 @@
1
1
  module Tapyrus
2
2
  module Network
3
-
4
3
  class PeerDiscovery
5
-
6
4
  attr_reader :logger, :configuration
7
5
 
8
6
  def initialize(configuration)
@@ -28,14 +26,14 @@ module Tapyrus
28
26
 
29
27
  def find_from_dns_seeds
30
28
  logger.debug 'discover peer address from DNS seeds.'
31
- dns_seeds.map { |seed|
29
+ dns_seeds.map do |seed|
32
30
  begin
33
- Socket.getaddrinfo(seed, Tapyrus.chain_params.default_port).map{|a|a[2]}.uniq
31
+ Socket.getaddrinfo(seed, Tapyrus.chain_params.default_port).map { |a| a[2] }.uniq
34
32
  rescue SocketError => e
35
33
  logger.error "SocketError occurred when load DNS seed: #{seed}, error: #{e.message}"
36
34
  nil
37
35
  end
38
- }.flatten.compact
36
+ end.flatten.compact
39
37
  end
40
38
  end
41
39
  end
@@ -1,11 +1,11 @@
1
1
  module Tapyrus
2
-
3
2
  module Network
4
-
5
3
  # Time between pings automatically sent out for latency probing and keepalive (in seconds).
6
4
  PING_INTERVAL = 2 * 60
5
+
7
6
  # Time after which to disconnect, after waiting for a ping response (or inactivity).
8
7
  TIMEOUT_INTERVAL = 20 * 60
8
+
9
9
  # Maximum number of automatic outgoing nodes
10
10
  MAX_OUTBOUND_CONNECTIONS = 4
11
11
 
@@ -112,23 +112,23 @@ module Tapyrus
112
112
  # allocate new peer id
113
113
  def allocate_peer_id
114
114
  id = 0
115
- until peers.empty? || peers.find{|p|p.id == id}.nil?
116
- id += 1
117
- end
115
+ id += 1 until peers.empty? || peers.find { |p| p.id == id }.nil?
118
116
  id
119
117
  end
120
118
 
121
119
  def connect(addr_list)
122
120
  port = Tapyrus.chain_params.default_port
123
121
 
124
- EM::Iterator.new(addr_list, Tapyrus::PARALLEL_THREAD).each do |ip, iter|
125
- if pending_peers.size + peers.size < MAX_OUTBOUND_CONNECTIONS
126
- peer = Peer.new(ip, port, self, @configuration)
127
- pending_peers << peer
128
- peer.connect
129
- iter.next
122
+ EM::Iterator
123
+ .new(addr_list, Tapyrus::PARALLEL_THREAD)
124
+ .each do |ip, iter|
125
+ if pending_peers.size + peers.size < MAX_OUTBOUND_CONNECTIONS
126
+ peer = Peer.new(ip, port, self, @configuration)
127
+ pending_peers << peer
128
+ peer.connect
129
+ iter.next
130
+ end
130
131
  end
131
- end
132
132
  end
133
133
  end
134
134
  end
data/lib/tapyrus/node.rb CHANGED
@@ -4,4 +4,4 @@ module Tapyrus
4
4
  autoload :CLI, 'tapyrus/node/cli'
5
5
  autoload :Configuration, 'tapyrus/node/configuration'
6
6
  end
7
- end
7
+ end
@@ -4,9 +4,7 @@ require 'json'
4
4
 
5
5
  module Tapyrus
6
6
  module Node
7
-
8
7
  class CLI < Thor
9
-
10
8
  class_option :network, aliases: '-n', default: :prod
11
9
 
12
10
  desc 'getblockchaininfo', 'Returns an object containing various state info regarding blockchain processing.'
@@ -19,7 +17,8 @@ module Tapyrus
19
17
  request('stop')
20
18
  end
21
19
 
22
- desc 'getblockheader "hash" ( verbose )', 'If verbose is false, returns a string that is serialized, hex-encoded data for blockheader "hash". If verbose is true, returns an Object with information about blockheader <hash>.'
20
+ desc 'getblockheader "hash" ( verbose )',
21
+ 'If verbose is false, returns a string that is serialized, hex-encoded data for blockheader "hash". If verbose is true, returns an Object with information about blockheader <hash>.'
23
22
  def getblockheader(hash, verbose = true)
24
23
  verbose = verbose.is_a?(String) ? (verbose == 'true') : verbose
25
24
  request('getblockheader', hash, verbose)
@@ -30,7 +29,8 @@ module Tapyrus
30
29
  request('getpeerinfo')
31
30
  end
32
31
 
33
- desc 'decoderawtransaction "hexstring"', 'Return a JSON object representing the serialized, hex-encoded transaction.'
32
+ desc 'decoderawtransaction "hexstring"',
33
+ 'Return a JSON object representing the serialized, hex-encoded transaction.'
34
34
  def decoderawtransaction(hexstring)
35
35
  request('decoderawtransaction', hexstring)
36
36
  end
@@ -47,12 +47,14 @@ module Tapyrus
47
47
  request('sendrawtransaction', hex_tx)
48
48
  end
49
49
 
50
- desc 'createwallet "wallet_id"', 'Create new HD wallet. It returns an error if an existing wallet_id is specified. '
50
+ desc 'createwallet "wallet_id"',
51
+ 'Create new HD wallet. It returns an error if an existing wallet_id is specified. '
51
52
  def createwallet(wallet_id)
52
53
  request('createwallet', wallet_id)
53
54
  end
54
55
 
55
- desc 'listwallets', 'Returns a list of currently loaded wallets. For full information on the wallet, use "getwalletinfo"'
56
+ desc 'listwallets',
57
+ 'Returns a list of currently loaded wallets. For full information on the wallet, use "getwalletinfo"'
56
58
  def listwallets
57
59
  request('listwallets')
58
60
  end
@@ -67,7 +69,8 @@ module Tapyrus
67
69
  request('listaccounts')
68
70
  end
69
71
 
70
- desc 'encryptwallet "passphrase"', 'Encrypts the wallet with "passphrase". This is for first time encryption.After this, any calls that interact with private keys such as sending or signing will require the passphrase to be set prior the making these calls.'
72
+ desc 'encryptwallet "passphrase"',
73
+ 'Encrypts the wallet with "passphrase". This is for first time encryption.After this, any calls that interact with private keys such as sending or signing will require the passphrase to be set prior the making these calls.'
71
74
  def encryptwallet(passhphrase)
72
75
  request('encryptwallet', passhphrase)
73
76
  end
@@ -86,15 +89,11 @@ module Tapyrus
86
89
  end
87
90
 
88
91
  def request(command, *params)
89
- data = {
90
- :method => command,
91
- :params => params,
92
- :id => 'jsonrpc'
93
- }
92
+ data = { method: command, params: params, id: 'jsonrpc' }
94
93
  begin
95
94
  uri = URI.parse(config.server_url)
96
95
  http = Net::HTTP.new(uri.hostname, uri.port)
97
- http.use_ssl = uri.scheme === "https"
96
+ http.use_ssl = uri.scheme === 'https'
98
97
  request = Net::HTTP::Post.new('/')
99
98
  request.content_type = 'application/json'
100
99
  request.body = data.to_json
@@ -110,7 +109,6 @@ module Tapyrus
110
109
  puts e.message
111
110
  end
112
111
  end
113
-
114
112
  end
115
113
  end
116
114
  end
@@ -3,7 +3,6 @@ require 'iniparse'
3
3
  module Tapyrus
4
4
  module Node
5
5
  class Configuration
6
-
7
6
  attr_reader :conf
8
7
 
9
8
  def initialize(opts = {})
@@ -14,7 +13,7 @@ module Tapyrus
14
13
 
15
14
  begin
16
15
  ini_file = IniParse.parse(File.read("#{Tapyrus.base_dir}/tapyrusrb.conf"))
17
- @conf = Hash[ ini_file.to_h['__anonymous__'].map{|k,v| [k.to_sym, v] } ]
16
+ @conf = Hash[ini_file.to_h['__anonymous__'].map { |k, v| [k.to_sym, v] }]
18
17
  rescue => e
19
18
  @conf = {}
20
19
  end
@@ -32,7 +31,6 @@ module Tapyrus
32
31
  def server_url
33
32
  "http://#{host}:#{port}"
34
33
  end
35
-
36
34
  end
37
35
  end
38
36
  end