ruby-client 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f91d1357cebee6d662eff00309fa181670968f188ae0d80b45e0212871baea1
4
- data.tar.gz: 5a3e51a481c1f925e6cde7b8755fd16a11518371a1572f6f6f6e4811b9f60c81
3
+ metadata.gz: 1e301dd0a012b1ced9e7e7191baf807c828c6bd9e44f6bf7b0fe56144498de7b
4
+ data.tar.gz: c8e778a124206a4d80da0c907d8df69d86ccaf36104a3ec69bf5f52ad30349f3
5
5
  SHA512:
6
- metadata.gz: 94936b259bd28aa4011861b39b6569a6950fb712bd0c74cee23650e8294440f79de092d973db808d071b978e1d71096118e0a67898c76261f80d8e948c5a9faa
7
- data.tar.gz: 1c117e1ca9bbd5c7ad090b0d89910ad278625513bdfd0a2998694ef3bb7a1f1f6055c77bb4fb38ae68307dbbcd8596554ffcd0c856084aa8a14c649ecfdfdf52
6
+ metadata.gz: c31e4a192bd484e9f97c90ede9a32be875e3fa2da11d750fa721c3e5520efb94c1fd778fd90724bc2b8e5b23342171fd36027eea2cf3ac4045f85cc6b72e62a5
7
+ data.tar.gz: e98e7635005ea5639ceec2e078b9eccdd38f3324e62a7c5cb48785b10c0cd2d8a4360cab8472fe0a76aa092e7c5e5162cacf4a265f3d3cbb5fae3884f9203d6e
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ require "nimiq"
4
+
5
+ require "irb"
6
+ IRB.start(__FILE__)
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -0,0 +1,317 @@
1
+ =begin
2
+ Copyright 2020 Nimiq community.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ module Api
18
+ attr_accessor :rpc
19
+
20
+ # accounts - Returns a list of addresses owned by client.
21
+ def accounts
22
+ result = @rpc.request("accounts")
23
+ return result
24
+ end
25
+
26
+ # block_number - Returns the height of most recent block.
27
+ def block_number
28
+ result = @rpc.request("blockNumber")
29
+ return result
30
+ end
31
+
32
+ # consensus - Returns information on the current consensus state.
33
+ def consensus
34
+ result = @rpc.request("consensus")
35
+ return result
36
+ end
37
+
38
+ # constant - Returns or overrides a constant value.
39
+ # When no parameter is given, it returns the value of the constant.
40
+ # When giving a value as parameter, it sets the constant to the given value.
41
+ # To reset the constant to the default value, the parameter "reset" should be used.
42
+ # - @param [String] name - The class and name of the constant. (format should be Class.CONSTANT)
43
+ # - @param [Integer] value - The new value of the constant or "reset". (optional)
44
+ def constant(name, value = nil)
45
+ if value
46
+ result = @rpc.request("constant", name, value)
47
+ else
48
+ result = @rpc.request("constant", name)
49
+ end
50
+ return result
51
+ end
52
+
53
+ # create_account - Creates a new account and stores its private key in the client store.
54
+ def create_account
55
+ result = @rpc.request("createAccount")
56
+ return result
57
+ end
58
+
59
+ # create_raw_transaction - Creates and signs a transaction without sending it.
60
+ # The transaction can then be send via `send_raw_transaction` without accidentally replaying it.
61
+ # - @param [TransactionObject] transaction - The transaction object.
62
+ def create_raw_transaction(transaction)
63
+ result = @rpc.request("createRawTransaction", transaction)
64
+ return result
65
+ end
66
+
67
+ # # new: update with more info
68
+ # # get_raw_transaction_info - Checks signed_transaction raw information.
69
+ # # - @param [String] signed_transaction - The hex encoded signed transaction.
70
+ # def get_raw_transaction_info(signed_transaction)
71
+ # result = @rpc.request("getRawTransactionInfo", signed_transaction)
72
+ # return result
73
+ # end
74
+
75
+ # get_account - Returns details for the account of given address.
76
+ # - @param [String] address - Address to get account details.
77
+ def get_account(address)
78
+ result = @rpc.request("getAccount", address)
79
+ return result
80
+ end
81
+
82
+ # get_balance - Returns the balance of the account of given address.
83
+ # - @param [String] address - Address to check for balance.
84
+ def get_balance(address)
85
+ result = @rpc.request("getBalance", address)
86
+ return result
87
+ end
88
+
89
+ # get_block_by_hash - Returns information about a block by hash.
90
+ # - @param [String] block_hash - Hash of the block to gather information on.
91
+ # - @param [Boolean] full_transactions (optional) - If true it returns the full transaction objects, if false only the hashes of the transactions. (default false)
92
+ def get_block_by_hash(block_hash, full_transactions = nil)
93
+ if full_transactions
94
+ result = @rpc.request("getBlockByHash", block_hash, full_transactions)
95
+ else
96
+ result = @rpc.request("getBlockByHash", block_hash)
97
+ end
98
+ return result
99
+ end
100
+
101
+ # get_block_by_number - Returns information about a block by block number.
102
+ # - @param [Integer] block_number - The height of the block to gather information on.
103
+ # - @param [Boolean] full_transactions (optional) - If true it returns the full transaction objects, if false only the hashes of the transactions. (default false)
104
+ def get_block_by_number(block_number, full_transactions = nil)
105
+ if full_transactions
106
+ result = @rpc.request("getBlockByNumber", block_number, full_transactions)
107
+ else
108
+ result = @rpc.request("getBlockByNumber", block_number)
109
+ end
110
+ return result
111
+ end
112
+
113
+ # get_block_template - Returns a template to build the next block for mining.
114
+ # This will consider pool instructions when connected to a pool.
115
+ # - @param [String] address (optional) - Address to use as a miner for this block. This overrides the address provided during startup or from the pool.
116
+ # - @param [String] dada_field (optional) - Hex-encoded value for the extra data field. This overrides the address provided during startup or from the pool.
117
+ def get_block_template(address = nil, dada_field = nil)
118
+ result = @rpc.request("getBlockTemplate")
119
+ return result
120
+ end
121
+
122
+ # get_block_transaction_count_by_hash - Returns the number of transactions in a block from a block matching the given block hash.
123
+ # - @param [String] block_hash - Hash of the block.
124
+ def get_block_transaction_count_by_hash(block_hash)
125
+ result = @rpc.request("getBlockTransactionCountByHash", block_hash)
126
+ return result
127
+ end
128
+
129
+ # get_block_transaction_count_by_number - Returns the number of transactions in a block matching the given block number.
130
+ # - @param [Integer] block_number - Height of the block.
131
+ def get_block_transaction_count_by_number(block_number)
132
+ result = @rpc.request("getBlockTransactionCountByNumber", block_number)
133
+ return result
134
+ end
135
+
136
+ # get_transaction_by_block_hash_and_index - Returns information about a transaction by block hash and transaction index position.
137
+ # - @param [Integer] block_hash - Hash of the block containing the transaction.
138
+ # - @param [Integer] transaction_index - Index of the transaction in the block.
139
+ def get_transaction_by_block_hash_and_index(block_hash, transaction_index)
140
+ result = @rpc.request("getTransactionByBlockHashAndIndex", block_hash, transaction_index)
141
+ return result
142
+ end
143
+
144
+ # get_transaction_by_block_number_and_index - Returns information about a transaction by block number and transaction index position.
145
+ # - @param [Integer] block_height - Height of the block containing the transaction.
146
+ # - @param [Integer] transaction_index - Index of the transaction in the block.
147
+ def get_transaction_by_block_number_and_index(block_height, transaction_index)
148
+ result = @rpc.request("getTransactionByBlockNumberAndIndex", block_height, transaction_index)
149
+ return result
150
+ end
151
+
152
+ # get_transaction_by_hash - Returns the information about a transaction requested by transaction hash.
153
+ # - @param [String] transaction_hash - Hash of a transaction.
154
+ def get_transaction_by_hash(transaction_hash)
155
+ result = @rpc.request("getTransactionByHash", transaction_hash)
156
+ return result
157
+ end
158
+
159
+ # get_transaction_receipt - Returns the receipt of a transaction by transaction hash.
160
+ # Note That the receipt is not available for pending transactions.
161
+ # - @param [String] transaction_hash - Hash of a transaction.
162
+ def get_transaction_receipt(transaction_hash)
163
+ result = @rpc.request("getTransactionReceipt", transaction_hash)
164
+ return result
165
+ end
166
+
167
+ # get_transactions_by_address - Returns the latest transactions successfully performed by or for an address.
168
+ # - @param [String] address - Address of which transactions should be gathered.
169
+ # - @param [Integer] transactions_number (optional) - Number of transactions that shall be returned. (default 1000)
170
+ def get_transactions_by_address(address, transactions_number = nil)
171
+ if transactions_number
172
+ result = @rpc.request("getTransactionsByAddress", address, transactions_number)
173
+ else
174
+ result = @rpc.request("getTransactionsByAddress", address)
175
+ end
176
+ return result
177
+ end
178
+
179
+ # get_work - Returns instructions to mine the next block. This will consider pool instructions when connected to a pool.
180
+ # - @param [String] address (optional) - Address to use as a miner for this block. This overrides the address provided during startup or from the pool.
181
+ # - @param [String] dada_field (optional) - Hex-encoded value for the extra data field. This overrides the address provided during startup or from the pool.
182
+ def get_work(address = nil, dada_field = nil)
183
+ result = @rpc.request("getWork", address, dada_field)
184
+ return result
185
+ end
186
+
187
+ # hashrate - Returns the number of hashes per second that the node is mining with.
188
+ def hashrate
189
+ result = @rpc.request("hashrate")
190
+ return result
191
+ end
192
+
193
+ # log - Sets the log level of the node.
194
+ # - @param [String] tag - If the tag is '*' the log level will be set globally, otherwise the log level is applied only on this tag.
195
+ # - @param [String] log_level - Log levels valid options: `trace`, `verbose`, `debug`, `info`, `warn`, `error`, `assert`.
196
+ def log(tag, log_level)
197
+ result = @rpc.request("log", tag, log_level)
198
+ return result
199
+ end
200
+
201
+ # mempool - Returns information on the current mempool situation. This will provide an overview of the number of transactions sorted into buckets based on their fee per byte (in smallest unit).
202
+ def mempool
203
+ result = @rpc.request("mempool")
204
+ return result
205
+ end
206
+
207
+ # mempool_content - Returns transactions that are currently in the mempool.
208
+ def mempool_content
209
+ result = @rpc.request("mempoolContent")
210
+ return result
211
+ end
212
+
213
+ # miner_address - Returns the miner address.
214
+ def miner_address
215
+ result = @rpc.request("minerAddress")
216
+ return result
217
+ end
218
+
219
+ # miner_threads - Returns or sets the number of CPU threads for the miner.
220
+ # - @param [Integer] set_threads (optional) - The number of threads to allocate for mining.
221
+ def miner_threads(set_threads = nil)
222
+ if set_threads
223
+ result = @rpc.request("minerThreads", set_threads)
224
+ else
225
+ result = @rpc.request("minerThreads")
226
+ end
227
+ return result
228
+ end
229
+
230
+ # min_fee_per_byte - Returns or sets the minimum fee per byte.
231
+ # - @param [Integer] set_min_fee (optional) - The new minimum fee per byte.
232
+ def min_fee_per_byte(set_min_fee = nil)
233
+ if set_min_fee
234
+ result = @rpc.request("minFeePerByte", set_min_fee)
235
+ else
236
+ result = @rpc.request("minFeePerByte")
237
+ end
238
+ return result
239
+ end
240
+
241
+ # mining - Returns `true` if client is actively mining new blocks.
242
+ def mining
243
+ result = @rpc.request("mining")
244
+ return result
245
+ end
246
+
247
+ # peer_count - Returns number of peers currently connected to the client.
248
+ def peer_count
249
+ result = @rpc.request("peerCount")
250
+ return result
251
+ end
252
+
253
+ # peer_list - Returns list of peers known to the client.
254
+ def peer_list
255
+ result = @rpc.request("peerList")
256
+ return result
257
+ end
258
+
259
+ # peer_state - Returns the state of the peer.
260
+ # - @param [String] peer_address - The address of the peer.
261
+ def peer_state(peer_address)
262
+ result = @rpc.request("peerState", peer_address)
263
+ return result
264
+ end
265
+
266
+ # pool - Returns or sets the mining pool.
267
+ # When no parameter is given, it returns the current mining pool. When a value is given as parameter, it sets the mining pool to that value.
268
+ # - @param [String/Boolean] pool_address (optional) - The mining pool connection string (url:port) or boolean to enable/disable pool mining.
269
+ def pool(pool_address = nil)
270
+ if pool_address
271
+ result = @rpc.request("pool", pool_address)
272
+ else
273
+ result = @rpc.request("pool")
274
+ end
275
+ return result
276
+ end
277
+
278
+ # pool_confirmed_balance - Returns the confirmed mining pool balance.
279
+ def pool_confirmed_balance
280
+ result = @rpc.request("poolConfirmedBalance")
281
+ return result
282
+ end
283
+
284
+ # pool_connection_state - Returns the connection state to mining pool.
285
+ def pool_connection_state
286
+ result = @rpc.request("poolConnectionState")
287
+ return result
288
+ end
289
+
290
+ # send_raw_transaction - Sends a signed message call transaction or a contract creation, if the data field contains code.
291
+ # - @param [String] signed_transaction - The hex encoded signed transaction.
292
+ def send_raw_transaction(signed_transaction)
293
+ result = @rpc.request("sendRawTransaction", signed_transaction)
294
+ return result
295
+ end
296
+
297
+ # send_transaction - Creates new message call transaction or a contract creation, if the data field contains code.
298
+ # - @param [TransactionObject] transaction - The transaction object.
299
+ def send_transaction(transaction)
300
+ result = @rpc.request("sendTransaction", transaction)
301
+ return result
302
+ end
303
+
304
+ # submit_block - Submits a block to the node. When the block is valid, the node will forward it to other nodes in the network.
305
+ # When submitting work from getWork, remember to include the suffix.
306
+ # - @param [String] block - Hex-encoded full block (including header, interlink and body).
307
+ def submit_block(block)
308
+ result = @rpc.request("submitBlock", block)
309
+ return result
310
+ end
311
+
312
+ # syncing - Returns an object with data about the sync status or `false`.
313
+ def syncing
314
+ result = @rpc.request("syncing")
315
+ return result
316
+ end
317
+ end
@@ -0,0 +1,3 @@
1
+ module Nimiq # :nodoc: all
2
+ VERSION = "1.2.0"
3
+ end
@@ -0,0 +1,108 @@
1
+ =begin
2
+ Copyright 2020 Nimiq community.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ require "oj"
18
+ require "net/http"
19
+
20
+ # :nodoc: all
21
+ module ClientRPC
22
+ class Connect
23
+ attr_accessor :options, :uri
24
+
25
+ DEFAULTS = {
26
+ host: "localhost",
27
+ port: 18332,
28
+ # dev: true,
29
+ }.freeze
30
+
31
+ def initialize(host)
32
+ @options = DEFAULTS.dup.merge(host.dup)
33
+ @uri = @options[:uri] ? URI(@options[:uri]) : URI(uri_check())
34
+ end
35
+
36
+ def request(name, *args)
37
+ puts "\n> #{name}: #{args.join(",")}" if options[:dev]
38
+ response = request_http_post(name, args)
39
+ puts "< #{response.code} #{response.message}" if options[:dev]
40
+ raise Error, response.message unless (200...300).cover?(response.code.to_i)
41
+ begin
42
+ response = Oj.load(response.body, symbol_keys: true, bigdecimal_load: true)
43
+ rescue StandardError => e
44
+ puts "WARN < Failed to parse JSON response: #{e}" if options[:dev]
45
+ raise
46
+ end
47
+ puts "\n> #{name}: #{args.join(",")}" if options[:dev]
48
+ puts response[:result] if options[:dev]
49
+ raise Error, response[:error] if response[:error]
50
+ response[:result]
51
+ end
52
+
53
+ def ping_node
54
+ user = uri.user
55
+ pass = uri.password
56
+ http = Net::HTTP.new(uri.host, uri.port)
57
+ request = Net::HTTP::Get.new(uri.request_uri)
58
+ request.basic_auth(user, pass)
59
+ request.body = request_body("", nil)
60
+ request["Content-Type"] = "application/json".freeze
61
+ response = http.request(request)
62
+ @pingres = (response.code).to_i.dup
63
+ end
64
+
65
+ private
66
+
67
+ def request_http_post(name, params)
68
+ user = uri.user
69
+ pass = uri.password
70
+ http = Net::HTTP.new(uri.host, uri.port)
71
+ request = Net::HTTP::Post.new(uri.request_uri)
72
+ request.basic_auth(user, pass)
73
+ request.body = request_body(name, params)
74
+ request["Content-Type"] = "application/json".freeze
75
+ http.request(request)
76
+ end
77
+
78
+ def request_body(name, params)
79
+ Oj.dump({
80
+ id: "rpc",
81
+ jsonrpc: "2.0",
82
+ method: name,
83
+ params: params,
84
+ }, mode: :compat)
85
+ end
86
+
87
+ def uri_check
88
+ if (options[:host].include? "http://" or options[:host].include? "https://")
89
+ host = options[:host]
90
+ newhost = url_strip(host.dup)
91
+ if (options[:host].include? "https")
92
+ return "https://#{options[:user]}:#{options[:pass]}@#{newhost}:#{options[:port]}"
93
+ else
94
+ return "http://#{options[:user]}:#{options[:pass]}@#{newhost}:#{options[:port]}"
95
+ end
96
+ else
97
+ return "http://#{options[:user]}:#{options[:pass]}@#{options[:host]}:#{options[:port]}"
98
+ end
99
+ end
100
+
101
+ def url_strip(url)
102
+ return url.to_s.sub!(/https?(\:)?(\/)?(\/)?(www\.)?/, "") if url.include?("http")
103
+ url.to_s.sub!(/(www\.)?/, "") if url.include?("www")
104
+ end
105
+
106
+ class Error < RuntimeError; end
107
+ end
108
+ end
@@ -0,0 +1,46 @@
1
+ =begin
2
+ Copyright 2020 Nimiq community.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ require_relative "nimiq/version"
18
+ require_relative "rpc"
19
+ require_relative "api"
20
+ require "json"
21
+
22
+ module Nimiq
23
+ class Error < StandardError; end # :nodoc: all
24
+
25
+ attr_reader :rpc # :nodoc: all
26
+
27
+ class Client
28
+ include Api
29
+
30
+ def initialize(opts)
31
+ return @rpc = ClientRPC::Connect.new(opts)
32
+ puts "Connecting to #{@opts}"
33
+ end
34
+
35
+ # Sends a raw request to the Nimiq node.
36
+ def request(name, params = nil)
37
+ return @rpc.request(name, params)
38
+ end
39
+
40
+ # Ping the Nimiq node.
41
+ def ping
42
+ @rpc.ping_node
43
+ @pingres = @rpc.instance_variable_get(:@pingres)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,295 @@
1
+ =begin
2
+ Copyright 2020 Nimiq community.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ =end
16
+
17
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
18
+ require "ruby-client"
19
+ # require "minitest/autorun"
20
+
21
+ describe "Nimiq", type: :request do
22
+
23
+ # Initialize
24
+ before(:all) do
25
+ options = {
26
+ host: "localhost",
27
+ port: 8005,
28
+ user: "user",
29
+ pass: "pass",
30
+ # dev: true,
31
+ }
32
+ @signed_transaction = "010000...abcdef"
33
+ @nimiq = Nimiq::Client.new(options)
34
+ end
35
+
36
+ # Test suite for client
37
+ describe "RPC Client" do
38
+
39
+ # Test suite for client version
40
+ it "Must have a version." do
41
+ expect(::Nimiq::VERSION).not_to eq(nil)
42
+ end
43
+
44
+ # Test suite for client connection
45
+ it "Must be able to connect to the Nimiq node." do
46
+ expect(@nimiq.ping).to eq(200)
47
+ end
48
+
49
+ # Test suite for client to send raw requests
50
+ it "Must be able to send raw requests." do
51
+ expect(@nimiq.request("consensus")).to be_a_kind_of(String)
52
+ end
53
+ end
54
+
55
+ # Test suite for api
56
+ describe "Api" do
57
+
58
+ # Test suite for client to retrieve the addresses owned by client.
59
+ it "Must be able to retrieve addresses owned by client." do
60
+ expect(@nimiq.accounts()).to be_a_kind_of(Object)
61
+ end
62
+
63
+ # Test suite for client to retrieve height of most recent block.
64
+ it "Must be able to retrieve height of most recent block." do
65
+ expect(@nimiq.block_number()).to be_a_kind_of(Object)
66
+ end
67
+
68
+ # Test suite for client to retrieve the consensus status.
69
+ it "Must be able to retrieve the consensus status." do
70
+ expect(@nimiq.consensus()).to be_a_kind_of(String)
71
+ end
72
+
73
+ # Test suite for client to override a constant value.
74
+ it "Must be able to override a constant value." do
75
+ constant_value = 10
76
+ expect(@nimiq.constant("BaseConsensus.MAX_ATTEMPTS_TO_FETCH", constant_value)).to eq(constant_value)
77
+ end
78
+
79
+ # Test suite for client to retrieve a constant value.
80
+ it "Must be able to retrieve a constant value." do
81
+ expect(@nimiq.constant("BaseConsensus.MAX_ATTEMPTS_TO_FETCH")).to eq(10)
82
+ end
83
+
84
+ # Test suite for client to create a new account.
85
+ it "Must be able to create a new account." do
86
+ expect(@nimiq.create_account()).to be_a_kind_of(Object)
87
+ end
88
+
89
+ # Test suite for client to create a transaction without sending it.
90
+ it "Must be able to create a transaction without sending it." do
91
+ transaction = {
92
+ "from": "NQ94 VESA PKTA 9YQ0 XKGC HVH0 Q9DF VSFU STSP",
93
+ "to": "NQ16 61ET MB3M 2JG6 TBLK BR0D B6EA X6XQ L91U",
94
+ "value": 100000,
95
+ "fee": 0,
96
+ }
97
+ expect(@nimiq.create_raw_transaction(transaction)).to be_a_kind_of(Object)
98
+ end
99
+
100
+ # # new
101
+ # # Test suite for client to retrieve a transaction information.
102
+ # it "Must be able to retrieve a transaction information." do
103
+ # # signed_transaction = "010000...abcdef"
104
+ # expect(@nimiq.get_raw_transaction_info(@signed_transaction)).to be_a_kind_of(Object)
105
+ # end
106
+
107
+ # Test suite for client to retrieve information related to an account.
108
+ it "Must be able to retrieve information related to an account." do
109
+ expect(@nimiq.get_account("NQ30 JLD6 U347 DFVU 40J3 F93V 9TCF YMMX RKY3")).to be_a_kind_of(Object)
110
+ end
111
+
112
+ # Test suite for client to retrieve balance of account.
113
+ it "Must be able to retrieve balance of account." do
114
+ expect(@nimiq.get_balance("NQ30 JLD6 U347 DFVU 40J3 F93V 9TCF YMMX RKY3")).to be_a_kind_of(Numeric)
115
+ end
116
+
117
+ # Test suite for client to retrieve block by hash.
118
+ it "Must be able to retrieve block by hash." do
119
+ expect(@nimiq.get_block_by_hash("14c91f6d6f3a0b62271e546bb09461231ab7e4d1ddc2c3e1b93de52d48a1da87", false)).to be_a_kind_of(Object)
120
+ end
121
+
122
+ # Test suite for client to retrieve block by hash, full transactions included.
123
+ it "Must be able to retrieve block by hash, full transactions included." do
124
+ expect(@nimiq.get_block_by_hash("14c91f6d6f3a0b62271e546bb09461231ab7e4d1ddc2c3e1b93de52d48a1da87", true)).to be_a_kind_of(Object)
125
+ end
126
+
127
+ # Test suite for client to retrieve block by number.
128
+ it "Must be able to retrieve block by number." do
129
+ expect(@nimiq.get_block_by_number(76415, false)).to be_a_kind_of(Object)
130
+ end
131
+
132
+ # Test suite for client to retrieve block by number, full transactions included.
133
+ it "Must be able to retrieve block by number, full transactions included." do
134
+ expect(@nimiq.get_block_by_number(76415, true)).to be_a_kind_of(Object)
135
+ end
136
+
137
+ # Test suite for client to retrieve block template.
138
+ it "Must be able to retrieve block template." do
139
+ expect(@nimiq.get_block_template()).to be_a_kind_of(Object)
140
+ end
141
+
142
+ # Test suite for client to retrieve the number of transactions in a block by block hash.
143
+ it "Must be able to retrieve the number of transactions in a block by block hash." do
144
+ expect(@nimiq.get_block_transaction_count_by_hash("dfe7d166f2c86bd10fa4b1f29cd06c13228f893167ce9826137c85758645572f")).to be_a_kind_of(Numeric)
145
+ end
146
+
147
+ # Test suite for client to retrieve the number of transactions in a block by block number.
148
+ it "Must be able to retrieve the number of transactions in a block by block number." do
149
+ expect(@nimiq.get_block_transaction_count_by_number(76415)).to be_a_kind_of(Numeric)
150
+ end
151
+
152
+ # Test suite for client to retrieve information about a transaction by block hash and transaction index position.
153
+ it "Must be able to retrieve information about a transaction by block hash and transaction index position." do
154
+ expect(@nimiq.get_transaction_by_block_hash_and_index("dfe7d166f2c86bd10fa4b1f29cd06c13228f893167ce9826137c85758645572f", 20)).to be_a_kind_of(Object)
155
+ end
156
+
157
+ # Test suite for client to retrieve information about a transaction by block number and transaction index position.
158
+ it "Must be able to retrieve information about a transaction by block number and transaction index position." do
159
+ expect(@nimiq.get_transaction_by_block_number_and_index(76415, 20)).to be_a_kind_of(Object)
160
+ end
161
+
162
+ # Test suite for client to retrieve the information about a transaction requested by transaction hash.
163
+ it "Must be able to retrieve the information about a transaction requested by transaction hash." do
164
+ expect(@nimiq.get_transaction_by_hash("9eb228482138a8e64c5bb60608979904aa2be5721c115a9e3db54a0c481bb398")).to be_a_kind_of(Object)
165
+ end
166
+
167
+ # Test suite for client to retrieve the receipt of a transaction by transaction hash.
168
+ it "Must be able to retrieve the receipt of a transaction by transaction hash." do
169
+ expect(@nimiq.get_transaction_receipt("465a63b73aa0b9b54b777be9a585ea00b367a17898ad520e1f22cb2c986ff554")).to be_a_kind_of(Object)
170
+ end
171
+
172
+ # Test suite for client to retrieve the latest transactions successfully performed by or for an address.
173
+ it "Must be able to retrieve the latest transactions successfully performed by or for an address." do
174
+ expect(@nimiq.get_transactions_by_address("NQ699A4AMB83HXDQ4J46BH5R4JFFQMA9C3GN", 100)).to be_a_kind_of(Object)
175
+ end
176
+
177
+ # Test suite for client to retrieve instructions to mine the next block.
178
+ it "Must be able to retrieve instructions to mine the next block." do
179
+ expect(@nimiq.get_work()).to be_a_kind_of(Object)
180
+ end
181
+
182
+ # Test suite for client to retrieve the number of hashes per second that the node is mining with.
183
+ it "Must be able to retrieve the number of hashes per second that the node is mining with." do
184
+ expect(@nimiq.hashrate()).to be_a_kind_of(Numeric)
185
+ end
186
+
187
+ # Test suite for client to set the log level of the node.
188
+ it "Must be able to set the log level of the node." do
189
+ expect(@nimiq.log("BaseConsensus", "debug")).to be(true).or be(false)
190
+ end
191
+
192
+ # Test suite for client to retrieve information on the current mempool situation.
193
+ it "Must be able to retrieve information on the current mempool situation." do
194
+ expect(@nimiq.mempool()).to be_a_kind_of(Object)
195
+ end
196
+
197
+ # Test suite for client to retrieve transactions that are currently in the mempool.
198
+ it "Must be able to retrieve transactions that are currently in the mempool." do
199
+ expect(@nimiq.mempool_content()).to be_a_kind_of(Object)
200
+ end
201
+
202
+ # Test suite for client to retrieve miner address.
203
+ it "Must be able to retrieve miner address." do
204
+ expect(@nimiq.miner_address()).to be_a_kind_of(String)
205
+ end
206
+
207
+ # Test suite for client to set the number of CPU threads for the miner.
208
+ it "Must be able to set the number of CPU threads for the miner." do
209
+ expect(@nimiq.miner_threads(2)).to be_a_kind_of(Numeric)
210
+ end
211
+
212
+ # Test suite for client to retrieve the number of CPU threads for the miner.
213
+ it "Must be able to retrieve the number of CPU threads for the miner." do
214
+ expect(@nimiq.miner_threads()).to be_a_kind_of(Numeric)
215
+ end
216
+
217
+ # Test suite for client to set the minimum fee per byte.
218
+ it "Must be able to set the minimum fee per byte." do
219
+ expect(@nimiq.min_fee_per_byte(1)).to be_a_kind_of(Numeric)
220
+ end
221
+
222
+ # Test suite for client to retrieve the minimum fee per byte.
223
+ it "Must be able to retrieve the minimum fee per byte." do
224
+ expect(@nimiq.min_fee_per_byte()).to be_a_kind_of(Numeric)
225
+ end
226
+
227
+ # Test suite for client to retrieve if client is actively mining new blocks.
228
+ it "Must be able to retrieve if client is actively mining new blocks." do
229
+ expect(@nimiq.mining()).to be(true).or be(false)
230
+ end
231
+
232
+ # Test suite for client to retrieve the number of peers currently connected to the client.
233
+ it "Must be able to retrieve the number of peers currently connected to the client." do
234
+ expect(@nimiq.peer_count()).to be_a_kind_of(Numeric)
235
+ end
236
+
237
+ # Test suite for client to retrieve the list of peers known to the client.
238
+ it "Must be able to retrieve the list of peers known to the client." do
239
+ expect(@nimiq.peer_list()).to be_a_kind_of(Object)
240
+ end
241
+
242
+ # Test suite for client to retrieve the state of the peer.
243
+ it "Must be able to retrieve the state of the peer." do
244
+ expect(@nimiq.peer_state("wss://seed-1.nimiq.com:8443/dfd55fe967d6c0ca707d3a73ec31e4ac")).to be_a_kind_of(Object)
245
+ end
246
+
247
+ # Test suite for client to set the mining pool.
248
+ it "Must be able to set the mining pool." do
249
+ expect(@nimiq.pool("eu.nimpool.io:8444")).to be_a_kind_of(String)
250
+ end
251
+
252
+ # Test suite for client to retrieve the mining pool.
253
+ it "Must be able to retrieve the mining pool." do
254
+ expect(@nimiq.pool()).to be_a_kind_of(String)
255
+ end
256
+
257
+ # Test suite for client to retrieve the confirmed mining pool balance.
258
+ it "Must be able to retrieve the confirmed mining pool balance." do
259
+ expect(@nimiq.pool_confirmed_balance()).to be_a_kind_of(Numeric)
260
+ end
261
+
262
+ # Test suite for client to retrieve the connection state to mining pool.
263
+ it "Must be able to retrieve the connection state to mining pool." do
264
+ expect(@nimiq.pool_connection_state()).to be_a_kind_of(Numeric)
265
+ end
266
+
267
+ # Test suite for client to send a signed message call transaction or a contract creation, if the data field contains code.
268
+ it "Must be able to send a signed message call transaction or a contract creation, if the data field contains code." do
269
+ # signed_transaction = "010000...abcdef"
270
+ expect(@nimiq.send_raw_transaction(@signed_transaction)).to be_a_kind_of(Object)
271
+ end
272
+
273
+ # Test suite for client to create new message call transaction or a contract creation, if the data field contains code.
274
+ it "Must be able to create new message call transaction or a contract creation, if the data field contains code." do
275
+ transaction = {
276
+ "from": "NQ94 VESA PKTA 9YQ0 XKGC HVH0 Q9DF VSFU STSP",
277
+ "to": "NQ16 61ET MB3M 2JG6 TBLK BR0D B6EA X6XQ L91U",
278
+ "value": 100000,
279
+ "fee": 0,
280
+ }
281
+ expect(@nimiq.send_transaction(transaction)).to be_a_kind_of(Object)
282
+ end
283
+
284
+ # Test suite for client to submit a block to the node.
285
+ it "Must be able to submit a block to the node." do
286
+ block = "00000000"
287
+ expect(@nimiq.submit_block(block)).to be_a_kind_of(Numeric)
288
+ end
289
+
290
+ # Test suite for client to retrieve an object with data about the sync status.
291
+ it "Must be able to retrieve an object with data about the sync status." do
292
+ expect(@nimiq.syncing()).to be(true).or be(false)
293
+ end
294
+ end
295
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jxdv
@@ -31,7 +31,13 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
- - lib/nimiq.rb
34
+ - bin/console
35
+ - bin/setup
36
+ - lib/api.rb
37
+ - lib/nimiq/version.rb
38
+ - lib/rpc.rb
39
+ - lib/ruby-client.rb
40
+ - spec/client_spec.rb
35
41
  homepage: https://github.com/jxdv/ruby-client
36
42
  licenses:
37
43
  - Apache-2.0
@@ -57,5 +63,5 @@ requirements: []
57
63
  rubygems_version: 3.1.4
58
64
  signing_key:
59
65
  specification_version: 4
60
- summary: Ruby implementation of the Nimiq RPC client specifications.
66
+ summary: Ruby implementation of the Nimiq RPC client specification.
61
67
  test_files: []
@@ -1,58 +0,0 @@
1
- # =begin
2
- # Copyright 2020 Nimiq community.
3
-
4
- # Licensed under the Apache License, Version 2.0 (the "License");
5
- # you may not use this file except in compliance with the License.
6
- # You may obtain a copy of the License at
7
-
8
- # http://www.apache.org/licenses/LICENSE-2.0
9
-
10
- # Unless required by applicable law or agreed to in writing, software
11
- # distributed under the License is distributed on an "AS IS" BASIS,
12
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- # See the License for the specific language governing permissions and
14
- # limitations under the License.
15
- # =end
16
-
17
- # require_relative "nimiq/version"
18
- # require_relative "rpcclient"
19
- # require_relative "api"
20
- # require "json"
21
-
22
- # module Nimiq
23
- # class Error < StandardError; end # :nodoc: all
24
-
25
- # attr_reader :rpc # :nodoc: all
26
-
27
- # class Client
28
- # include Api
29
-
30
- # def initialize(opts)
31
- # return @rpc = ClientRPC::Connect.new(opts)
32
- # puts "Connecting to #{@opts}"
33
- # end
34
-
35
- # # Sends a raw request to the Nimiq node.
36
- # def request(name, params = nil)
37
- # return @rpc.request(name, params)
38
- # end
39
-
40
- # # Ping the Nimiq node.
41
- # def ping
42
- # @rpc.ping_node
43
- # @pingres = @rpc.instance_variable_get(:@pingres)
44
- # end
45
- # end
46
- # end
47
-
48
- require "nimiq/version"
49
-
50
- module Nimiq
51
- class Error < StandardError; end
52
-
53
- class Client
54
- def world
55
- puts "hey world"
56
- end
57
- end
58
- end