nimiq-ruby-client 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/console +6 -0
- data/bin/setup +6 -0
- data/lib/api.rb +397 -0
- data/lib/nimiq/version.rb +3 -0
- data/lib/rpc.rb +123 -0
- data/lib/ruby-client.rb +46 -0
- data/lib/types.rb +111 -0
- data/spec/client_spec.rb +301 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 63d93cbe52bee1af4bb20109a300c86a866c0cdba41909b0f1ac53a8be75c889
|
4
|
+
data.tar.gz: 5b31702ac617fd3320987577374cb0f807bc19ee1df8b3e31b3f41dbf9d44f0d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e581d8db9d05252b579a6517b9fcb8bdbae8ad3e2bb130f68817a09b8c1a016ea00e1d27fbcaba1240f236795f56b4c55aba572e57be7362fbeaa19cdb24291a
|
7
|
+
data.tar.gz: 6125c1aef9ab3885bf7fc724afd85d11b76b9b679b19f30f57fe1b4af0d4d7a18b42242e8a9d9f011ac6d00dfde80820dce0cf48c089405f673970045f7a7e9c
|
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/api.rb
ADDED
@@ -0,0 +1,397 @@
|
|
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 "sorbet-runtime"
|
18
|
+
require_relative "types"
|
19
|
+
|
20
|
+
module Api
|
21
|
+
attr_accessor :rpc
|
22
|
+
extend T::Sig
|
23
|
+
|
24
|
+
# accounts - Returns a list of addresses owned by client.
|
25
|
+
sig { returns(T::Array[Types::Account]) }
|
26
|
+
|
27
|
+
def accounts
|
28
|
+
result = @rpc.request("accounts")
|
29
|
+
return result
|
30
|
+
end
|
31
|
+
|
32
|
+
# block_number - Returns the height of most recent block.
|
33
|
+
sig { returns(Integer) }
|
34
|
+
|
35
|
+
def block_number
|
36
|
+
result = @rpc.request("blockNumber")
|
37
|
+
return result
|
38
|
+
end
|
39
|
+
|
40
|
+
# consensus - Returns information on the current consensus state.
|
41
|
+
sig { returns(String) }
|
42
|
+
|
43
|
+
def consensus
|
44
|
+
result = @rpc.request("consensus")
|
45
|
+
return result
|
46
|
+
end
|
47
|
+
|
48
|
+
# constant - Returns or overrides a constant value.
|
49
|
+
# When no parameter is given, it returns the value of the constant.
|
50
|
+
# When giving a value as parameter, it sets the constant to the given value.
|
51
|
+
# To reset the constant to the default value, the parameter "reset" should be used.
|
52
|
+
# - @param [String] name - The class and name of the constant. (format should be Class.CONSTANT)
|
53
|
+
# - @param [Integer] value - The new value of the constant or "reset". (optional)
|
54
|
+
sig { params(name: String, value: T.nilable(Integer)).returns(Integer) }
|
55
|
+
|
56
|
+
def constant(name, value = nil)
|
57
|
+
if value
|
58
|
+
result = @rpc.request("constant", name, value)
|
59
|
+
else
|
60
|
+
result = @rpc.request("constant", name)
|
61
|
+
end
|
62
|
+
return result
|
63
|
+
end
|
64
|
+
|
65
|
+
# create_account - Creates a new account and stores its private key in the client store.
|
66
|
+
sig { returns(Types::Wallet) }
|
67
|
+
|
68
|
+
def create_account
|
69
|
+
result = @rpc.request("createAccount")
|
70
|
+
return result
|
71
|
+
end
|
72
|
+
|
73
|
+
# create_raw_transaction - Creates and signs a transaction without sending it.
|
74
|
+
# The transaction can then be send via `send_raw_transaction` without accidentally replaying it.
|
75
|
+
# - @param [TransactionObject] transaction - The transaction object.
|
76
|
+
sig { params(transaction: Types::TransactionOutgoing).returns(String) }
|
77
|
+
|
78
|
+
def create_raw_transaction(transaction)
|
79
|
+
result = @rpc.request("createRawTransaction", transaction)
|
80
|
+
return result
|
81
|
+
end
|
82
|
+
|
83
|
+
# NEW
|
84
|
+
# get_raw_transaction_info - Checks signed_transaction raw information.
|
85
|
+
# - @param [String] signed_transaction - The hex encoded signed transaction.
|
86
|
+
sig { params(signed_transaction: String).returns(Object) }
|
87
|
+
|
88
|
+
def get_raw_transaction_info(signed_transaction)
|
89
|
+
result = @rpc.request("getRawTransactionInfo", signed_transaction)
|
90
|
+
return result
|
91
|
+
end
|
92
|
+
|
93
|
+
# get_account - Returns details for the account of given address.
|
94
|
+
# - @param [String] address - Address to get account details.
|
95
|
+
sig { params(address: String).returns(Types::Account) }
|
96
|
+
|
97
|
+
def get_account(address)
|
98
|
+
result = @rpc.request("getAccount", address)
|
99
|
+
return result
|
100
|
+
end
|
101
|
+
|
102
|
+
# get_balance - Returns the balance of the account of given address.
|
103
|
+
# - @param [String] address - Address to check for balance.
|
104
|
+
sig { params(address: String).returns(Integer) }
|
105
|
+
|
106
|
+
def get_balance(address)
|
107
|
+
result = @rpc.request("getBalance", address)
|
108
|
+
return result
|
109
|
+
end
|
110
|
+
|
111
|
+
# get_block_by_hash - Returns information about a block by hash.
|
112
|
+
# - @param [String] block_hash - Hash of the block to gather information on.
|
113
|
+
# - @param [Boolean] full_transactions (optional) - If true it returns the full transaction objects, if false only the hashes of the transactions. (default false)
|
114
|
+
sig { params(block_hash: String, full_transactions: T.nilable(T::Boolean)).returns(Types::Block) }
|
115
|
+
|
116
|
+
def get_block_by_hash(block_hash, full_transactions = nil)
|
117
|
+
if full_transactions
|
118
|
+
result = @rpc.request("getBlockByHash", block_hash, full_transactions)
|
119
|
+
else
|
120
|
+
result = @rpc.request("getBlockByHash", block_hash)
|
121
|
+
end
|
122
|
+
return result
|
123
|
+
end
|
124
|
+
|
125
|
+
# get_block_by_number - Returns information about a block by block number.
|
126
|
+
# - @param [Integer] block_number - The height of the block to gather information on.
|
127
|
+
# - @param [Boolean] full_transactions (optional) - If true it returns the full transaction objects, if false only the hashes of the transactions. (default false)
|
128
|
+
sig { params(block_number: Integer, full_transactions: T.nilable(T::Boolean)).returns(Types::Block) }
|
129
|
+
|
130
|
+
def get_block_by_number(block_number, full_transactions = nil)
|
131
|
+
if full_transactions
|
132
|
+
result = @rpc.request("getBlockByNumber", block_number, full_transactions)
|
133
|
+
else
|
134
|
+
result = @rpc.request("getBlockByNumber", block_number)
|
135
|
+
end
|
136
|
+
return result
|
137
|
+
end
|
138
|
+
|
139
|
+
# get_block_template - Returns a template to build the next block for mining.
|
140
|
+
# This will consider pool instructions when connected to a pool.
|
141
|
+
# - @param [String] address (optional) - Address to use as a miner for this block. This overrides the address provided during startup or from the pool.
|
142
|
+
# - @param [String] data_field (optional) - Hex-encoded value for the extra data field. This overrides the address provided during startup or from the pool.
|
143
|
+
sig { params(address: T.nilable(Integer), data_field: T.nilable(String)).returns(Types::BlockTemplate) }
|
144
|
+
|
145
|
+
def get_block_template(address = nil, data_field = nil)
|
146
|
+
result = @rpc.request("getBlockTemplate")
|
147
|
+
return result
|
148
|
+
end
|
149
|
+
|
150
|
+
# get_block_transaction_count_by_hash - Returns the number of transactions in a block from a block matching the given block hash.
|
151
|
+
# - @param [String] block_hash - Hash of the block.
|
152
|
+
sig { params(block_hash: String).returns(Integer) }
|
153
|
+
|
154
|
+
def get_block_transaction_count_by_hash(block_hash)
|
155
|
+
result = @rpc.request("getBlockTransactionCountByHash", block_hash)
|
156
|
+
return result
|
157
|
+
end
|
158
|
+
|
159
|
+
# get_block_transaction_count_by_number - Returns the number of transactions in a block matching the given block number.
|
160
|
+
# - @param [Integer] block_number - Height of the block.
|
161
|
+
sig { params(block_number: Integer).returns(Integer) }
|
162
|
+
|
163
|
+
def get_block_transaction_count_by_number(block_number)
|
164
|
+
result = @rpc.request("getBlockTransactionCountByNumber", block_number)
|
165
|
+
return result
|
166
|
+
end
|
167
|
+
|
168
|
+
# get_transaction_by_block_hash_and_index - Returns information about a transaction by block hash and transaction index position.
|
169
|
+
# - @param [String] block_hash - Hash of the block containing the transaction.
|
170
|
+
# - @param [Integer] transaction_index - Index of the transaction in the block.
|
171
|
+
sig { params(block_hash: String, transaction_index: Integer).returns(T.nilable(Types::Transaction)) }
|
172
|
+
|
173
|
+
def get_transaction_by_block_hash_and_index(block_hash, transaction_index)
|
174
|
+
result = @rpc.request("getTransactionByBlockHashAndIndex", block_hash, transaction_index)
|
175
|
+
return result
|
176
|
+
end
|
177
|
+
|
178
|
+
# get_transaction_by_block_number_and_index - Returns information about a transaction by block number and transaction index position.
|
179
|
+
# - @param [Integer] block_hash_index - Height of the block containing the transaction.
|
180
|
+
# - @param [Integer] transaction_index - Index of the transaction in the block.
|
181
|
+
sig { params(block_hash_index: Integer, transaction_index: Integer).returns(T.nilable(Types::Transaction)) }
|
182
|
+
|
183
|
+
def get_transaction_by_block_number_and_index(block_hash_index, transaction_index)
|
184
|
+
result = @rpc.request("getTransactionByBlockNumberAndIndex", block_hash_index, transaction_index)
|
185
|
+
return result
|
186
|
+
end
|
187
|
+
|
188
|
+
# get_transaction_by_hash - Returns the information about a transaction requested by transaction hash.
|
189
|
+
# - @param [String] transaction_hash - Hash of a transaction.
|
190
|
+
sig { params(transaction_hash: String).returns(T.nilable(Types::Transaction)) }
|
191
|
+
|
192
|
+
def get_transaction_by_hash(transaction_hash)
|
193
|
+
result = @rpc.request("getTransactionByHash", transaction_hash)
|
194
|
+
return result
|
195
|
+
end
|
196
|
+
|
197
|
+
# get_transaction_receipt - Returns the receipt of a transaction by transaction hash.
|
198
|
+
# Note That the receipt is not available for pending transactions.
|
199
|
+
# - @param [String] transaction_hash - Hash of a transaction.
|
200
|
+
sig { params(transaction_hash: String).returns(T.nilable(Types::TransactionReceipt)) }
|
201
|
+
|
202
|
+
def get_transaction_receipt(transaction_hash)
|
203
|
+
result = @rpc.request("getTransactionReceipt", transaction_hash)
|
204
|
+
return result
|
205
|
+
end
|
206
|
+
|
207
|
+
# get_transactions_by_address - Returns the latest transactions successfully performed by or for an address.
|
208
|
+
# - @param [String] address - Address of which transactions should be gathered.
|
209
|
+
# - @param [Integer] transactions_number (optional) - Number of transactions that shall be returned. (default 1000)
|
210
|
+
sig { params(address: String, transactions_number: T.nilable(Integer)).returns(T.nilable(T::Array[Types::Transaction])) }
|
211
|
+
|
212
|
+
def get_transactions_by_address(address, transactions_number = nil)
|
213
|
+
if transactions_number
|
214
|
+
result = @rpc.request("getTransactionsByAddress", address, transactions_number)
|
215
|
+
else
|
216
|
+
result = @rpc.request("getTransactionsByAddress", address)
|
217
|
+
end
|
218
|
+
return result
|
219
|
+
end
|
220
|
+
|
221
|
+
# get_work - Returns instructions to mine the next block. This will consider pool instructions when connected to a pool.
|
222
|
+
# - @param [String] address (optional) - Address to use as a miner for this block. This overrides the address provided during startup or from the pool.
|
223
|
+
# - @param [String] data_field (optional) - Hex-encoded value for the extra data field. This overrides the address provided during startup or from the pool.
|
224
|
+
sig { params(address: T.nilable(String), data_field: T.nilable(String)).returns(Types::MiningWork) }
|
225
|
+
|
226
|
+
def get_work(address = nil, data_field = nil)
|
227
|
+
result = @rpc.request("getWork", address, data_field)
|
228
|
+
return result
|
229
|
+
end
|
230
|
+
|
231
|
+
# hashrate - Returns the number of hashes per second that the node is mining with.
|
232
|
+
sig { returns(T.any(Integer, Float)) }
|
233
|
+
|
234
|
+
def hashrate
|
235
|
+
result = @rpc.request("hashrate")
|
236
|
+
return result
|
237
|
+
end
|
238
|
+
|
239
|
+
# log - Sets the log level of the node.
|
240
|
+
# - @param [String] tag - If the tag is '*' the log level will be set globally, otherwise the log level is applied only on this tag.
|
241
|
+
# - @param [String] log_level - Log levels valid options: `trace`, `verbose`, `debug`, `info`, `warn`, `error`, `assert`.
|
242
|
+
sig { params(tag: String, log_level: String).returns(T::Boolean) }
|
243
|
+
|
244
|
+
def log(tag, log_level)
|
245
|
+
result = @rpc.request("log", tag, log_level)
|
246
|
+
return result
|
247
|
+
end
|
248
|
+
|
249
|
+
# 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).
|
250
|
+
sig { returns(Object) }
|
251
|
+
|
252
|
+
def mempool
|
253
|
+
result = @rpc.request("mempool")
|
254
|
+
return result
|
255
|
+
end
|
256
|
+
|
257
|
+
# mempool_content - Returns transactions that are currently in the mempool.
|
258
|
+
sig { params(include_full_transactions: T.nilable(T::Boolean)).returns(T.any(T.nilable(T::Array[Types::Transaction]), T.nilable(T::Array))) }
|
259
|
+
|
260
|
+
def mempool_content(include_full_transactions = nil)
|
261
|
+
result = @rpc.request("mempoolContent")
|
262
|
+
return result
|
263
|
+
end
|
264
|
+
|
265
|
+
# miner_address - Returns the miner address.
|
266
|
+
sig { returns(String) }
|
267
|
+
|
268
|
+
def miner_address
|
269
|
+
result = @rpc.request("minerAddress")
|
270
|
+
return result
|
271
|
+
end
|
272
|
+
|
273
|
+
# miner_threads - Returns or sets the number of CPU threads for the miner.
|
274
|
+
# - @param [Integer] set_threads (optional) - The number of threads to allocate for mining.
|
275
|
+
sig { params(set_threads: T.nilable(Integer)).returns(Integer) }
|
276
|
+
|
277
|
+
def miner_threads(set_threads = nil)
|
278
|
+
if set_threads
|
279
|
+
result = @rpc.request("minerThreads", set_threads)
|
280
|
+
else
|
281
|
+
result = @rpc.request("minerThreads")
|
282
|
+
end
|
283
|
+
return result
|
284
|
+
end
|
285
|
+
|
286
|
+
# min_fee_per_byte - Returns or sets the minimum fee per byte.
|
287
|
+
# - @param [Integer] set_min_fee (optional) - The new minimum fee per byte.
|
288
|
+
sig { params(set_min_fee: T.nilable(Integer)).returns(Integer) }
|
289
|
+
|
290
|
+
def min_fee_per_byte(set_min_fee = nil)
|
291
|
+
if set_min_fee
|
292
|
+
result = @rpc.request("minFeePerByte", set_min_fee)
|
293
|
+
else
|
294
|
+
result = @rpc.request("minFeePerByte")
|
295
|
+
end
|
296
|
+
return result
|
297
|
+
end
|
298
|
+
|
299
|
+
# mining - Returns `true` if client is actively mining new blocks.
|
300
|
+
sig { returns(T::Boolean) }
|
301
|
+
|
302
|
+
def mining
|
303
|
+
result = @rpc.request("mining")
|
304
|
+
return result
|
305
|
+
end
|
306
|
+
|
307
|
+
# peer_count - Returns number of peers currently connected to the client.
|
308
|
+
sig { returns(Integer) }
|
309
|
+
|
310
|
+
def peer_count
|
311
|
+
result = @rpc.request("peerCount")
|
312
|
+
return result
|
313
|
+
end
|
314
|
+
|
315
|
+
# peer_list - Returns list of peers known to the client.
|
316
|
+
sig { returns(T::Array[Types::Peer]) }
|
317
|
+
|
318
|
+
def peer_list
|
319
|
+
result = @rpc.request("peerList")
|
320
|
+
return result
|
321
|
+
end
|
322
|
+
|
323
|
+
# peer_state - Returns the state of the peer.
|
324
|
+
# - @param [String] peer_address - The address of the peer.
|
325
|
+
sig { params(peer_address: String).returns(Types::Peer) }
|
326
|
+
|
327
|
+
def peer_state(peer_address)
|
328
|
+
result = @rpc.request("peerState", peer_address)
|
329
|
+
return result
|
330
|
+
end
|
331
|
+
|
332
|
+
# pool - Returns or sets the mining pool.
|
333
|
+
# 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.
|
334
|
+
# - @param [String/Boolean] pool_address (optional) - The mining pool connection string (url:port) or boolean to enable/disable pool mining.
|
335
|
+
sig { params(pool_address_or_action: T.nilable(T.any(String, T::Boolean))).returns(T.nilable(String)) }
|
336
|
+
|
337
|
+
def pool(pool_address_or_action = nil)
|
338
|
+
if pool_address_or_action
|
339
|
+
result = @rpc.request("pool", pool_address_or_action)
|
340
|
+
else
|
341
|
+
result = @rpc.request("pool")
|
342
|
+
end
|
343
|
+
return result
|
344
|
+
end
|
345
|
+
|
346
|
+
# pool_confirmed_balance - Returns the confirmed mining pool balance.
|
347
|
+
sig { returns(Integer) }
|
348
|
+
|
349
|
+
def pool_confirmed_balance
|
350
|
+
result = @rpc.request("poolConfirmedBalance")
|
351
|
+
return result
|
352
|
+
end
|
353
|
+
|
354
|
+
# pool_connection_state - Returns the connection state to mining pool.
|
355
|
+
sig { returns(Integer) }
|
356
|
+
|
357
|
+
def pool_connection_state
|
358
|
+
result = @rpc.request("poolConnectionState")
|
359
|
+
return result
|
360
|
+
end
|
361
|
+
|
362
|
+
# send_raw_transaction - Sends a signed message call transaction or a contract creation, if the data field contains code.
|
363
|
+
# - @param [String] signed_transaction - The hex encoded signed transaction.
|
364
|
+
sig { params(signed_transaction: String).returns(Object) }
|
365
|
+
|
366
|
+
def send_raw_transaction(signed_transaction)
|
367
|
+
result = @rpc.request("sendRawTransaction", signed_transaction)
|
368
|
+
return result
|
369
|
+
end
|
370
|
+
|
371
|
+
# send_transaction - Creates new message call transaction or a contract creation, if the data field contains code.
|
372
|
+
# - @param [TransactionObject] transaction - The transaction object.
|
373
|
+
sig { params(transaction: Types::TransactionOutgoing).returns(String) }
|
374
|
+
|
375
|
+
def send_transaction(transaction)
|
376
|
+
result = @rpc.request("sendTransaction", transaction)
|
377
|
+
return result
|
378
|
+
end
|
379
|
+
|
380
|
+
# submit_block - Submits a block to the node. When the block is valid, the node will forward it to other nodes in the network.
|
381
|
+
# When submitting work from getWork, remember to include the suffix.
|
382
|
+
# - @param [String] block - Hex-encoded full block (including header, interlink and body).
|
383
|
+
sig { params(block: String) }
|
384
|
+
|
385
|
+
def submit_block(block)
|
386
|
+
result = @rpc.request("submitBlock", block)
|
387
|
+
return result
|
388
|
+
end
|
389
|
+
|
390
|
+
# syncing - Returns an object with data about the sync status or `false`.
|
391
|
+
sig { returns(T.any(Object, T::Boolean)) }
|
392
|
+
|
393
|
+
def syncing
|
394
|
+
result = @rpc.request("syncing")
|
395
|
+
return result
|
396
|
+
end
|
397
|
+
end
|
data/lib/rpc.rb
ADDED
@@ -0,0 +1,123 @@
|
|
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, :ssl
|
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
|
+
http.use_ssl = true if @ssl
|
58
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
59
|
+
request.basic_auth(user, pass)
|
60
|
+
request.body = request_body("", nil)
|
61
|
+
request["Content-Type"] = "application/json".freeze
|
62
|
+
response = http.request(request)
|
63
|
+
@pingres = (response.code).to_i.dup
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def request_http_post(name, params)
|
69
|
+
user = URI.decode(uri.user)
|
70
|
+
pass = URI.decode(uri.password)
|
71
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
72
|
+
http.use_ssl = true if @ssl
|
73
|
+
request = Net::HTTP::Post.new(uri)
|
74
|
+
request.basic_auth(user, pass)
|
75
|
+
request.body = request_body(name, params)
|
76
|
+
request["Content-Type"] = "application/json".freeze
|
77
|
+
http.request(request)
|
78
|
+
end
|
79
|
+
|
80
|
+
def request_body(name, params)
|
81
|
+
Oj.dump({
|
82
|
+
id: "rpc",
|
83
|
+
jsonrpc: "2.0",
|
84
|
+
method: name,
|
85
|
+
params: params,
|
86
|
+
}, mode: :compat)
|
87
|
+
end
|
88
|
+
|
89
|
+
def uri_check
|
90
|
+
if (options[:host].include? "http://" or options[:host].include? "https://")
|
91
|
+
host = options[:host]
|
92
|
+
newhost = url_strip(host.dup)
|
93
|
+
if (options[:host].include? "https")
|
94
|
+
@ssl = true
|
95
|
+
if options[:pass]
|
96
|
+
return "https://#{options[:user]}:#{URI.encode(options[:pass])}@#{newhost}:#{options[:port]}"
|
97
|
+
else
|
98
|
+
return "https://#{options[:user]}:@#{newhost}:#{options[:port]}"
|
99
|
+
end
|
100
|
+
else
|
101
|
+
if options[:pass]
|
102
|
+
return "http://#{options[:user]}:#{URI.encode(options[:pass])}@#{newhost}:#{options[:port]}"
|
103
|
+
else
|
104
|
+
return "http://#{options[:user]}:@#{newhost}:#{options[:port]}"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
else
|
108
|
+
if options[:pass]
|
109
|
+
return "http://#{options[:user]}:#{URI.encode(options[:pass])}@#{options[:host]}:#{options[:port]}"
|
110
|
+
else
|
111
|
+
return "http://#{options[:user]}:@#{options[:host]}:#{options[:port]}"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def url_strip(url)
|
117
|
+
return url.to_s.sub!(/https?(\:)?(\/)?(\/)?(www\.)?/, "") if url.include?("http")
|
118
|
+
url.to_s.sub!(/(www\.)?/, "") if url.include?("www")
|
119
|
+
end
|
120
|
+
|
121
|
+
class Error < RuntimeError; end
|
122
|
+
end
|
123
|
+
end
|
data/lib/ruby-client.rb
ADDED
@@ -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
|
+
puts "Connecting to #{opts[:host]}:#{opts[:port]}"
|
32
|
+
return @rpc = ClientRPC::Connect.new(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
|
data/lib/types.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
require "sorbet-runtime"
|
2
|
+
|
3
|
+
# :nodoc: all
|
4
|
+
module Types
|
5
|
+
extend T::Sig
|
6
|
+
|
7
|
+
Block = {
|
8
|
+
number: Integer,
|
9
|
+
hash: String,
|
10
|
+
pow: String,
|
11
|
+
parentHash: String,
|
12
|
+
nonce: Integer,
|
13
|
+
bodyHash: String,
|
14
|
+
accountsHash: String,
|
15
|
+
miner: String,
|
16
|
+
minerAddress: String,
|
17
|
+
difficulty: String,
|
18
|
+
extraData: String,
|
19
|
+
size: Integer,
|
20
|
+
timestamp: Integer,
|
21
|
+
transactions: Array,
|
22
|
+
confirmations: T.nilable(Integer),
|
23
|
+
}
|
24
|
+
|
25
|
+
BlockTemplate = {
|
26
|
+
header: {
|
27
|
+
version: Integer,
|
28
|
+
prevHash: String,
|
29
|
+
interlinkHash: String,
|
30
|
+
accountsHash: String,
|
31
|
+
nBits: Integer,
|
32
|
+
height: Integer,
|
33
|
+
},
|
34
|
+
interlink: String,
|
35
|
+
body: {
|
36
|
+
hash: String,
|
37
|
+
minerAddr: String,
|
38
|
+
extraData: String,
|
39
|
+
transactions: T::Array[String],
|
40
|
+
prunedAccounts: T::Array[String],
|
41
|
+
merkleHashes: T::Array[String],
|
42
|
+
},
|
43
|
+
target: Integer,
|
44
|
+
}
|
45
|
+
|
46
|
+
Wallet = {
|
47
|
+
id: String,
|
48
|
+
address: String,
|
49
|
+
publicKey: String,
|
50
|
+
}
|
51
|
+
|
52
|
+
Account = {
|
53
|
+
id: String,
|
54
|
+
address: String,
|
55
|
+
balance: Integer,
|
56
|
+
type: Integer,
|
57
|
+
}
|
58
|
+
|
59
|
+
Transaction = {
|
60
|
+
hash: String,
|
61
|
+
blockHash: T.nilable(String),
|
62
|
+
blockNumber: T.nilable(Integer),
|
63
|
+
timestamp: T.nilable(Integer),
|
64
|
+
confirmations: T.nilable(Integer),
|
65
|
+
transactionIndex: T.nilable(Integer),
|
66
|
+
from: String,
|
67
|
+
fromAddress: String,
|
68
|
+
to: String,
|
69
|
+
toAddress: String,
|
70
|
+
value: Integer,
|
71
|
+
fee: Integer,
|
72
|
+
data: T.nilable(String),
|
73
|
+
flags: Integer,
|
74
|
+
}
|
75
|
+
|
76
|
+
TransactionOutgoing = {
|
77
|
+
from: String,
|
78
|
+
to: String,
|
79
|
+
value: Integer,
|
80
|
+
fee: Integer,
|
81
|
+
}
|
82
|
+
|
83
|
+
TransactionReceipt = {
|
84
|
+
transactionHash: String,
|
85
|
+
transactionIndex: Integer,
|
86
|
+
blockNumber: Integer,
|
87
|
+
blockHash: String,
|
88
|
+
confirmations: Integer,
|
89
|
+
timestamp: Integer,
|
90
|
+
}
|
91
|
+
|
92
|
+
MiningWork = {
|
93
|
+
data: String,
|
94
|
+
suffix: String,
|
95
|
+
target: Integer,
|
96
|
+
algorithm: String,
|
97
|
+
}
|
98
|
+
|
99
|
+
Peer = {
|
100
|
+
id: String,
|
101
|
+
address: String,
|
102
|
+
addressState: Integer,
|
103
|
+
connectionState: T.nilable(Integer),
|
104
|
+
version: T.nilable(Integer),
|
105
|
+
timeOffset: T.nilable(Integer),
|
106
|
+
headHash: T.nilable(String),
|
107
|
+
latency: T.nilable(Integer),
|
108
|
+
rx: T.nilable(Integer),
|
109
|
+
tx: T.nilable(Integer),
|
110
|
+
}
|
111
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,301 @@
|
|
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
|
+
|
20
|
+
describe "Nimiq", type: :request do
|
21
|
+
|
22
|
+
# Initialize
|
23
|
+
before(:all) do
|
24
|
+
options = {
|
25
|
+
host: "localhost",
|
26
|
+
port: "8648",
|
27
|
+
# user: "user",
|
28
|
+
# pass: "pass",
|
29
|
+
# dev: true,
|
30
|
+
}
|
31
|
+
@main_addr = "NQ70 46LN 1SKC KGFN VV8U G92N XC4X 9VFB SBVJ" # Node address
|
32
|
+
@seco_addr = "NQ27 B9ED 98G5 3VH7 FY8D BFP0 XNF4 BD8L TN4B" # Some address
|
33
|
+
@signed_transaction = "000000.......1A84FA23" # get this by running Makes @signed_transaction
|
34
|
+
@nimiq = Nimiq::Client.new(options)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Test suite for client
|
38
|
+
describe "RPC Client" do
|
39
|
+
|
40
|
+
# Test suite for client version
|
41
|
+
it "Must have a version." do
|
42
|
+
expect(::Nimiq::VERSION).not_to eq(nil)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Test suite for client connection
|
46
|
+
it "Must be able to connect to the Nimiq node." do
|
47
|
+
expect(@nimiq.ping).to eq(200)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Test suite for client to send raw requests
|
51
|
+
it "Must be able to send raw requests." do
|
52
|
+
expect(@nimiq.request("consensus")).to be_a_kind_of(String)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Test suite for API
|
57
|
+
describe "Api" do
|
58
|
+
|
59
|
+
# Test suite for client to retrieve the addresses owned by client.
|
60
|
+
it "Must be able to retrieve addresses owned by client." do
|
61
|
+
expect(@nimiq.accounts()).to be_a_kind_of(Object)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Test suite for client to retrieve height of most recent block.
|
65
|
+
it "Must be able to retrieve height of most recent block." do
|
66
|
+
expect(@nimiq.block_number()).to be_a_kind_of(Object)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Test suite for client to retrieve the consensus status.
|
70
|
+
it "Must be able to retrieve the consensus status." do
|
71
|
+
expect(@nimiq.consensus()).to be_a_kind_of(String)
|
72
|
+
end
|
73
|
+
|
74
|
+
# Test suite for client to override a constant value.
|
75
|
+
it "Must be able to override a constant value." do
|
76
|
+
constant_value = 10
|
77
|
+
expect(@nimiq.constant("BaseConsensus.MAX_ATTEMPTS_TO_FETCH", constant_value)).to eq(constant_value)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Test suite for client to retrieve a constant value.
|
81
|
+
it "Must be able to retrieve a constant value." do
|
82
|
+
expect(@nimiq.constant("BaseConsensus.MAX_ATTEMPTS_TO_FETCH")).to eq(10)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Test suite for client to create a new account.
|
86
|
+
it "Must be able to create a new account." do
|
87
|
+
expect(@nimiq.create_account()).to be_a_kind_of(Object)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Test suite for client to retrieve information related to an account.
|
91
|
+
it "Must be able to retrieve information related to an account." do
|
92
|
+
expect(@nimiq.get_account(@seco_addr)).to be_a_kind_of(Object)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Test suite for client to retrieve balance of account.
|
96
|
+
it "Must be able to retrieve balance of account." do
|
97
|
+
expect(@nimiq.get_balance(@main_addr)).to be_a_kind_of(Integer)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Test suite for client to retrieve block by hash.
|
101
|
+
it "Must be able to retrieve block by hash." do
|
102
|
+
expect(@nimiq.get_block_by_hash("14c91f6d6f3a0b62271e546bb09461231ab7e4d1ddc2c3e1b93de52d48a1da87", false)).to be_a_kind_of(Object)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Test suite for client to retrieve block by hash, full transactions included.
|
106
|
+
it "Must be able to retrieve block by hash, full transactions included." do
|
107
|
+
expect(@nimiq.get_block_by_hash("14c91f6d6f3a0b62271e546bb09461231ab7e4d1ddc2c3e1b93de52d48a1da87", true)).to be_a_kind_of(Object)
|
108
|
+
end
|
109
|
+
|
110
|
+
# Test suite for client to retrieve block by number.
|
111
|
+
it "Must be able to retrieve block by number." do
|
112
|
+
expect(@nimiq.get_block_by_number(76415, false)).to be_a_kind_of(Object)
|
113
|
+
end
|
114
|
+
|
115
|
+
# Test suite for client to retrieve block by number, full transactions included.
|
116
|
+
it "Must be able to retrieve block by number, full transactions included." do
|
117
|
+
expect(@nimiq.get_block_by_number(76415, true)).to be_a_kind_of(Object)
|
118
|
+
end
|
119
|
+
|
120
|
+
# Test suite for client to retrieve block template.
|
121
|
+
it "Must be able to retrieve block template." do
|
122
|
+
expect(@nimiq.get_block_template()).to be_a_kind_of(Object)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Test suite for client to retrieve the number of transactions in a block by block hash.
|
126
|
+
it "Must be able to retrieve the number of transactions in a block by block hash." do
|
127
|
+
expect(@nimiq.get_block_transaction_count_by_hash("dfe7d166f2c86bd10fa4b1f29cd06c13228f893167ce9826137c85758645572f")).to be_a_kind_of(Integer)
|
128
|
+
end
|
129
|
+
|
130
|
+
# Test suite for client to retrieve the number of transactions in a block by block number.
|
131
|
+
it "Must be able to retrieve the number of transactions in a block by block number." do
|
132
|
+
expect(@nimiq.get_block_transaction_count_by_number(76415)).to be_a_kind_of(Integer)
|
133
|
+
end
|
134
|
+
|
135
|
+
# Test suite for client to retrieve information about a transaction by block hash and transaction index position.
|
136
|
+
it "Must be able to retrieve information about a transaction by block hash and transaction index position." do
|
137
|
+
expect(@nimiq.get_transaction_by_block_hash_and_index("dfe7d166f2c86bd10fa4b1f29cd06c13228f893167ce9826137c85758645572f", 20)).to be_a_kind_of(Object)
|
138
|
+
end
|
139
|
+
|
140
|
+
# Test suite for client to retrieve information about a transaction by block number and transaction index position.
|
141
|
+
it "Must be able to retrieve information about a transaction by block number and transaction index position." do
|
142
|
+
expect(@nimiq.get_transaction_by_block_number_and_index(76415, 20)).to be_a_kind_of(Object)
|
143
|
+
end
|
144
|
+
|
145
|
+
# Test suite for client to retrieve the information about a transaction requested by transaction hash.
|
146
|
+
it "Must be able to retrieve the information about a transaction requested by transaction hash." do
|
147
|
+
expect(@nimiq.get_transaction_by_hash("465a63b73aa0b9b54b777be9a585ea00b367a17898ad520e1f22cb2c986ff554")).to be_a_kind_of(Object)
|
148
|
+
end
|
149
|
+
|
150
|
+
# Test suite for client to retrieve the receipt of a transaction by transaction hash.
|
151
|
+
it "Must be able to retrieve the receipt of a transaction by transaction hash." do
|
152
|
+
expect(@nimiq.get_transaction_receipt("465a63b73aa0b9b54b777be9a585ea00b367a17898ad520e1f22cb2c986ff554")).to be_a_kind_of(Object)
|
153
|
+
end
|
154
|
+
|
155
|
+
# Test suite for client to retrieve the latest transactions successfully performed by or for an address.
|
156
|
+
it "Must be able to retrieve the latest transactions successfully performed by or for an address." do
|
157
|
+
expect(@nimiq.get_transactions_by_address("NQ699A4AMB83HXDQ4J46BH5R4JFFQMA9C3GN", 100)).to be_a_kind_of(Object)
|
158
|
+
end
|
159
|
+
|
160
|
+
# Test suite for client to retrieve instructions to mine the next block.
|
161
|
+
it "Must be able to retrieve instructions to mine the next block." do
|
162
|
+
expect(@nimiq.get_work()).to be_a_kind_of(Object)
|
163
|
+
end
|
164
|
+
|
165
|
+
# Test suite for client to retrieve the number of hashes per second that the node is mining with.
|
166
|
+
it "Must be able to retrieve the number of hashes per second that the node is mining with." do
|
167
|
+
expect(@nimiq.hashrate()).to be_a_kind_of(Integer)
|
168
|
+
end
|
169
|
+
|
170
|
+
# Test suite for client to set the log level of the node.
|
171
|
+
it "Must be able to set the log level of the node." do
|
172
|
+
expect(@nimiq.log("BaseConsensus", "debug")).to be(true).or be(false)
|
173
|
+
end
|
174
|
+
|
175
|
+
# Test suite for client to retrieve information on the current mempool situation.
|
176
|
+
it "Must be able to retrieve information on the current mempool situation." do
|
177
|
+
expect(@nimiq.mempool()).to be_a_kind_of(Object)
|
178
|
+
end
|
179
|
+
|
180
|
+
# Test suite for client to retrieve transactions that are currently in the mempool.
|
181
|
+
it "Must be able to retrieve transactions that are currently in the mempool." do
|
182
|
+
expect(@nimiq.mempool_content()).to be_a_kind_of(Object)
|
183
|
+
end
|
184
|
+
|
185
|
+
# Test suite for client to retrieve miner address.
|
186
|
+
it "Must be able to retrieve miner address." do
|
187
|
+
expect(@nimiq.miner_address()).to be_a_kind_of(String)
|
188
|
+
end
|
189
|
+
|
190
|
+
# Test suite for client to set the number of CPU threads for the miner.
|
191
|
+
it "Must be able to set the number of CPU threads for the miner." do
|
192
|
+
expect(@nimiq.miner_threads(2)).to be_a_kind_of(Integer)
|
193
|
+
end
|
194
|
+
|
195
|
+
# Test suite for client to retrieve the number of CPU threads for the miner.
|
196
|
+
it "Must be able to retrieve the number of CPU threads for the miner." do
|
197
|
+
expect(@nimiq.miner_threads()).to be_a_kind_of(Integer)
|
198
|
+
end
|
199
|
+
|
200
|
+
# Test suite for client to set the minimum fee per byte.
|
201
|
+
it "Must be able to set the minimum fee per byte." do
|
202
|
+
expect(@nimiq.min_fee_per_byte(1)).to be_a_kind_of(Integer)
|
203
|
+
end
|
204
|
+
|
205
|
+
# Test suite for client to retrieve the minimum fee per byte.
|
206
|
+
it "Must be able to retrieve the minimum fee per byte." do
|
207
|
+
expect(@nimiq.min_fee_per_byte()).to be_a_kind_of(Integer)
|
208
|
+
end
|
209
|
+
|
210
|
+
# Test suite for client to retrieve if client is actively mining new blocks.
|
211
|
+
it "Must be able to retrieve if client is actively mining new blocks." do
|
212
|
+
expect(@nimiq.mining()).to be(true).or be(false)
|
213
|
+
end
|
214
|
+
|
215
|
+
# Test suite for client to retrieve the number of peers currently connected to the client.
|
216
|
+
it "Must be able to retrieve the number of peers currently connected to the client." do
|
217
|
+
expect(@nimiq.peer_count()).to be_a_kind_of(Integer)
|
218
|
+
end
|
219
|
+
|
220
|
+
# Test suite for client to retrieve the list of peers known to the client.
|
221
|
+
it "Must be able to retrieve the list of peers known to the client." do
|
222
|
+
expect(@nimiq.peer_list()).to be_a_kind_of(Object)
|
223
|
+
end
|
224
|
+
|
225
|
+
# Test suite for client to retrieve the state of the peer.
|
226
|
+
it "Must be able to retrieve the state of the peer." do
|
227
|
+
expect(@nimiq.peer_state("wss://seed-1.nimiq.com:8443/dfd55fe967d6c0ca707d3a73ec31e4ac")).to be_a_kind_of(Object)
|
228
|
+
end
|
229
|
+
|
230
|
+
# Test suite for client to set the mining pool.
|
231
|
+
it "Must be able to set the mining pool." do
|
232
|
+
expect(@nimiq.pool("eu.nimpool.io:8444")).to be_a_kind_of(String).or be(nil)
|
233
|
+
end
|
234
|
+
|
235
|
+
# Test suite for client to retrieve the mining pool.
|
236
|
+
it "Must be able to retrieve the mining pool." do
|
237
|
+
expect(@nimiq.pool()).to be_a_kind_of(String).or be(nil)
|
238
|
+
end
|
239
|
+
|
240
|
+
# Test suite for client to retrieve the confirmed mining pool balance.
|
241
|
+
it "Must be able to retrieve the confirmed mining pool balance." do
|
242
|
+
expect(@nimiq.pool_confirmed_balance()).to be_a_kind_of(Integer)
|
243
|
+
end
|
244
|
+
|
245
|
+
# Test suite for client to retrieve the connection state to mining pool.
|
246
|
+
it "Must be able to retrieve the connection state to mining pool." do
|
247
|
+
expect(@nimiq.pool_connection_state()).to be_a_kind_of(Integer)
|
248
|
+
end
|
249
|
+
|
250
|
+
# Makes @signed_transaction
|
251
|
+
# Test suite for client to create a transaction without sending it.
|
252
|
+
it "Must be able to create a transaction without sending it." do
|
253
|
+
transaction = {
|
254
|
+
"from": @main_addr,
|
255
|
+
"to": @seco_addr,
|
256
|
+
"value": 100,
|
257
|
+
"fee": 0,
|
258
|
+
}
|
259
|
+
@signed_transaction = @nimiq.create_raw_transaction(transaction)
|
260
|
+
expect(@signed_transaction).to be_a_kind_of(Object)
|
261
|
+
end
|
262
|
+
|
263
|
+
# NEW
|
264
|
+
# Test suite for client to retrieve a transaction information.
|
265
|
+
it "Must be able to retrieve a transaction information." do
|
266
|
+
# expect(@nimiq.get_raw_transaction_info(@signed_transaction)).to be_a_kind_of(Object)
|
267
|
+
expect(@nimiq.get_raw_transaction_info("009de5aeefe9fa3b4017cbf460e863831808d121b614ae034337a69cdabbeeb4185a5cd4a2051f6277fd0d5bee0f59e45b514dd88b000000000000006400000000000000000007f8642afa9861e3dd9c708318aba517f0d40882af99579841cc78afd395927de3913b88c87990659a6c55b2ee28c073559520fe685c051f2daa7cc63ffb9caa9ac9e20f")).to be_a_kind_of(Object)
|
268
|
+
end
|
269
|
+
|
270
|
+
# Test suite for client to retrieve an object with data about the sync status.
|
271
|
+
it "Must be able to retrieve an object with data about the sync status." do
|
272
|
+
expect(@nimiq.syncing()[:startingBlock]).to be > 0
|
273
|
+
end
|
274
|
+
|
275
|
+
# # Must have at least some NIM to be able to send it to another address
|
276
|
+
# # Test suite for client to send a signed message call transaction or a contract creation, if the data field contains code.
|
277
|
+
# it "Must be able to send a signed message call transaction or a contract creation, if the data field contains code." do
|
278
|
+
# expect(@nimiq.send_raw_transaction(@signed_transaction)).to be_a_kind_of(Object)
|
279
|
+
# end
|
280
|
+
|
281
|
+
# # Must have at least some NIM to be able to send it to another address
|
282
|
+
# # Test suite for client to create new message call transaction or a contract creation, if the data field contains code.
|
283
|
+
# it "Must be able to create new message call transaction or a contract creation, if the data field contains code." do
|
284
|
+
# transaction = {
|
285
|
+
# "from": @main_addr,
|
286
|
+
# "to": @seco_addr,
|
287
|
+
# "value": 100,
|
288
|
+
# "fee": 0,
|
289
|
+
# }
|
290
|
+
# expect(@nimiq.send_transaction(transaction)).to be_a_kind_of(Object)
|
291
|
+
# end
|
292
|
+
|
293
|
+
# # Must have a valid generated block for the blockchain to accept, returns nothing if block is valid
|
294
|
+
# # Test suite for client to submit a block to the node.
|
295
|
+
# it "Must be able to submit a block to the node." do
|
296
|
+
# block = "14c91f6d6f3a0b62271e546bb09461231ab7e4d1ddc2c3e1b93de52d48a1da87"
|
297
|
+
# expect(@nimiq.submit_block(block)).to be("")
|
298
|
+
# end
|
299
|
+
|
300
|
+
end
|
301
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nimiq-ruby-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jxdv
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-08-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oj
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.15'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.15'
|
27
|
+
description: Ruby implementation of the Nimiq RPC client specification.
|
28
|
+
email:
|
29
|
+
- root@localhost
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
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
|
+
- lib/types.rb
|
41
|
+
- spec/client_spec.rb
|
42
|
+
homepage: https://github.com/jxdv/ruby-client
|
43
|
+
licenses:
|
44
|
+
- Apache-2.0
|
45
|
+
metadata:
|
46
|
+
homepage_uri: https://github.com/jxdv/ruby-client
|
47
|
+
source_code_uri: https://github.com/jxdv/ruby-client
|
48
|
+
changelog_uri: https://github.com/jxdv/ruby-client/readme.md
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 2.3.0
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubygems_version: 3.1.4
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: Ruby implementation of the Nimiq RPC client specification.
|
68
|
+
test_files: []
|