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