ruby-client 1.0.1 → 1.0.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 +317 -317
- data/lib/client.rb +43 -33
- data/lib/nimiq/version.rb +1 -1
- data/lib/rpcclient.rb +93 -93
- data/ruby-client.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a98306ce97d345f4991cf71e383485817adc6b5162697c519e1f2859c711e39c
|
4
|
+
data.tar.gz: 3bfe5fb4352634a6a8c243459393c099bb9b7a1c5156e71b7b7ce00492effdb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d69bbd6a10fcf1b15010affe37072e6deeb4718b70fb3b790847539cb36aada3d1d015d3baf3ebc74dabadf0fd627ac21dd1de821b4cd9eb054d3a98bc0d851
|
7
|
+
data.tar.gz: 645f28cfd002c73a67e910a1a885e4af89e300752c1c6afb37ac38c298d6b728c40f6bb9f2782db552a7af17c6ba6c63b8a7be6b1256bba74d5f6ef926047332
|
data/lib/api.rb
CHANGED
@@ -1,317 +1,317 @@
|
|
1
|
-
=begin
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
=end
|
16
|
-
|
17
|
-
module Api
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
end
|
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
|
data/lib/client.rb
CHANGED
@@ -1,46 +1,56 @@
|
|
1
|
-
=begin
|
2
|
-
|
1
|
+
# =begin
|
2
|
+
# Copyright 2020 Nimiq community.
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
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
7
|
|
8
|
-
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
=end
|
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
16
|
|
17
|
-
require_relative "nimiq/version"
|
18
|
-
require_relative "rpcclient"
|
19
|
-
require_relative "api"
|
20
|
-
require "json"
|
17
|
+
# require_relative "nimiq/version"
|
18
|
+
# require_relative "rpcclient"
|
19
|
+
# require_relative "api"
|
20
|
+
# require "json"
|
21
21
|
|
22
|
-
module Nimiq
|
23
|
-
|
22
|
+
# module Nimiq
|
23
|
+
# class Error < StandardError; end # :nodoc: all
|
24
24
|
|
25
|
-
|
25
|
+
# attr_reader :rpc # :nodoc: all
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
# class Client
|
28
|
+
# include Api
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
# def initialize(opts)
|
31
|
+
# return @rpc = ClientRPC::Connect.new(opts)
|
32
|
+
# puts "Connecting to #{@opts}"
|
33
|
+
# end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
# # Sends a raw request to the Nimiq node.
|
36
|
+
# def request(name, params = nil)
|
37
|
+
# return @rpc.request(name, params)
|
38
|
+
# end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
+
module Nimiq
|
49
|
+
class Error < StandardError; end
|
50
|
+
|
51
|
+
class Client
|
52
|
+
def world
|
53
|
+
puts "hey world"
|
44
54
|
end
|
45
55
|
end
|
46
56
|
end
|
data/lib/nimiq/version.rb
CHANGED
data/lib/rpcclient.rb
CHANGED
@@ -1,108 +1,108 @@
|
|
1
|
-
=begin
|
2
|
-
|
1
|
+
# =begin
|
2
|
+
# Copyright 2020 Nimiq community.
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
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
7
|
|
8
|
-
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
=end
|
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
16
|
|
17
|
-
require "oj"
|
18
|
-
require "net/http"
|
17
|
+
# require "oj"
|
18
|
+
# require "net/http"
|
19
19
|
|
20
|
-
# :nodoc: all
|
21
|
-
module ClientRPC
|
22
|
-
|
23
|
-
|
20
|
+
# # :nodoc: all
|
21
|
+
# module ClientRPC
|
22
|
+
# class Connect
|
23
|
+
# attr_accessor :options, :uri
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
# DEFAULTS = {
|
26
|
+
# host: "localhost",
|
27
|
+
# port: 18332,
|
28
|
+
# # dev: true,
|
29
|
+
# }.freeze
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
# def initialize(host)
|
32
|
+
# @options = DEFAULTS.dup.merge(host.dup)
|
33
|
+
# @uri = @options[:uri] ? URI(@options[:uri]) : URI(uri_check())
|
34
|
+
# end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
64
|
|
65
|
-
|
65
|
+
# private
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
77
|
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
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
86
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
100
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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
105
|
|
106
|
-
|
107
|
-
|
108
|
-
end
|
106
|
+
# class Error < RuntimeError; end
|
107
|
+
# end
|
108
|
+
# end
|
data/ruby-client.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# lib = File.expand_path("lib", __dir__)
|
2
2
|
# $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
# require "nimiq/version"
|
4
|
-
require_relative "lib/nimiq/version
|
4
|
+
require_relative "lib/nimiq/version"
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "ruby-client"
|