solana-ruby 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/solana-ruby/client.rb +126 -128
- data/lib/solana-ruby/keypair.rb +1 -1
- data/lib/solana-ruby/utils.rb +1 -1
- data/lib/solana-ruby/version.rb +2 -2
- data/lib/solana-ruby.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 301f452c31d1989f2565adbf428c90081ca667eac36089e7b0817807a22d1a87
|
4
|
+
data.tar.gz: dfec2238bd6552db7b625f3016619837d57bd15735ef2c447b98acb3cad97a31
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4a655cc6132c2c281e7aa798785a33b1cbb10754940d82d17f1ec33d34ce847d3bec11f4ac35a038973cc976e0e69c8b95b4fabaea0d6d007504e536dfe0c390
|
7
|
+
data.tar.gz: 3af5cefad5a04134b07cc0562a2ed3ed7720cb1d1289b89483480686f181ddc719ec72d9e3a5320d1b7ec46f4446e2e6d6acdd69e7c30e805056d60317a50bf4
|
data/lib/solana-ruby/client.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
require 'faraday'
|
2
1
|
require 'faye/websocket'
|
2
|
+
require 'httpx'
|
3
3
|
require 'json'
|
4
|
-
require 'thread'
|
5
4
|
|
6
5
|
require_relative 'utils'
|
7
6
|
|
8
|
-
module
|
7
|
+
module Solana
|
9
8
|
##
|
10
9
|
# Client class for interacting with the Solana JSON RPC API over HTTP and WS.
|
11
10
|
class Client
|
@@ -13,15 +12,9 @@ module SolanaRB
|
|
13
12
|
# Initializes a new Client.
|
14
13
|
#
|
15
14
|
# @param [String, nil] api_key Optional API key for authentication.
|
16
|
-
def initialize(api_endpoint =
|
15
|
+
def initialize(api_endpoint = Solana::Utils::MAINNET, api_key = nil)
|
17
16
|
@api_key = api_key
|
18
17
|
@api_endpoint = api_endpoint
|
19
|
-
# @api_ws = WebSocket::Handshake::Client.new(url: @api_endpoint::WS)
|
20
|
-
@api_http = Faraday.new(url: @api_endpoint::HTTP) do |faraday|
|
21
|
-
faraday.request :json
|
22
|
-
faraday.response :json, content_type: 'application/json'
|
23
|
-
faraday.adapter Faraday.default_adapter
|
24
|
-
end
|
25
18
|
end
|
26
19
|
|
27
20
|
##
|
@@ -30,8 +23,8 @@ module SolanaRB
|
|
30
23
|
# @param [String] pubkey The public key of the account.
|
31
24
|
# @param [Hash] options Optional parameters for the request.
|
32
25
|
# @return [Hash] The account information.
|
33
|
-
def get_account_info(pubkey, options = {})
|
34
|
-
request_http('getAccountInfo', [pubkey, options])
|
26
|
+
def get_account_info(pubkey, options = {}, &block)
|
27
|
+
request_http('getAccountInfo', [pubkey, options], &block)
|
35
28
|
end
|
36
29
|
|
37
30
|
##
|
@@ -40,8 +33,8 @@ module SolanaRB
|
|
40
33
|
# @param [String] pubkey The public key of the account.
|
41
34
|
# @param [Hash] options Optional parameters for the request.
|
42
35
|
# @return [Integer] The balance in lamports.
|
43
|
-
def get_balance(pubkey, options = {})
|
44
|
-
request_http('getBalance', [pubkey, options])
|
36
|
+
def get_balance(pubkey, options = {}, &block)
|
37
|
+
request_http('getBalance', [pubkey, options], &block)
|
45
38
|
end
|
46
39
|
|
47
40
|
##
|
@@ -50,8 +43,8 @@ module SolanaRB
|
|
50
43
|
# @param [Integer] slot_number The slot number of the block.
|
51
44
|
# @param [Hash] options Optional parameters for the request.
|
52
45
|
# @return [Hash] The block information.
|
53
|
-
def get_block(slot_number, options = {})
|
54
|
-
request_http('getBlock', [slot_number, options])
|
46
|
+
def get_block(slot_number, options = {}, &block)
|
47
|
+
request_http('getBlock', [slot_number, options], &block)
|
55
48
|
end
|
56
49
|
|
57
50
|
##
|
@@ -60,8 +53,8 @@ module SolanaRB
|
|
60
53
|
# @param [Integer] slot_number The slot number of the block.
|
61
54
|
# @param [Hash] options Optional parameters for the request.
|
62
55
|
# @return [Hash] The block commitment information.
|
63
|
-
def get_block_commitment(slot_number, options = {})
|
64
|
-
request_http('getBlockCommitment', [slot_number, options])
|
56
|
+
def get_block_commitment(slot_number, options = {}, &block)
|
57
|
+
request_http('getBlockCommitment', [slot_number, options], &block)
|
65
58
|
end
|
66
59
|
|
67
60
|
##
|
@@ -69,8 +62,8 @@ module SolanaRB
|
|
69
62
|
#
|
70
63
|
# @param [Hash] options Optional parameters for the request.
|
71
64
|
# @return [Integer] The current block height.
|
72
|
-
def get_block_height(options = {})
|
73
|
-
request_http('getBlockHeight', [options])
|
65
|
+
def get_block_height(options = {}, &block)
|
66
|
+
request_http('getBlockHeight', [options], &block)
|
74
67
|
end
|
75
68
|
|
76
69
|
##
|
@@ -78,8 +71,8 @@ module SolanaRB
|
|
78
71
|
#
|
79
72
|
# @param [Hash] options Optional parameters for the request.
|
80
73
|
# @return [Hash] The block production information.
|
81
|
-
def get_block_production(options = {})
|
82
|
-
request_http('getBlockProduction', [options])
|
74
|
+
def get_block_production(options = {}, &block)
|
75
|
+
request_http('getBlockProduction', [options], &block)
|
83
76
|
end
|
84
77
|
|
85
78
|
##
|
@@ -88,8 +81,8 @@ module SolanaRB
|
|
88
81
|
# @param [Integer] slot_number The slot number of the block.
|
89
82
|
# @param [Hash] options Optional parameters for the request.
|
90
83
|
# @return [Integer] The estimated production time in seconds.
|
91
|
-
def get_block_time(slot_number, options = {})
|
92
|
-
request_http('getBlockTime', [slot_number, options])
|
84
|
+
def get_block_time(slot_number, options = {}, &block)
|
85
|
+
request_http('getBlockTime', [slot_number, options], &block)
|
93
86
|
end
|
94
87
|
|
95
88
|
##
|
@@ -99,8 +92,8 @@ module SolanaRB
|
|
99
92
|
# @param [Integer] end_slot The end slot number.
|
100
93
|
# @param [Hash] options Optional parameters for the request.
|
101
94
|
# @return [Array<Integer>] The list of confirmed blocks.
|
102
|
-
def get_blocks(start_slot, end_slot, options = {})
|
103
|
-
request_http('getBlocks', [start_slot, end_slot, options])
|
95
|
+
def get_blocks(start_slot, end_slot, options = {}, &block)
|
96
|
+
request_http('getBlocks', [start_slot, end_slot, options], &block)
|
104
97
|
end
|
105
98
|
|
106
99
|
##
|
@@ -110,8 +103,8 @@ module SolanaRB
|
|
110
103
|
# @param [Integer] limit The maximum number of blocks to return.
|
111
104
|
# @param [Hash] options Optional parameters for the request.
|
112
105
|
# @return [Array<Integer>] The list of confirmed blocks.
|
113
|
-
def get_blocks_with_limit(start_slot, limit, options = {})
|
114
|
-
request_http('getBlocksWithLimit', [start_slot, limit, options])
|
106
|
+
def get_blocks_with_limit(start_slot, limit, options = {}, &block)
|
107
|
+
request_http('getBlocksWithLimit', [start_slot, limit, options], &block)
|
115
108
|
end
|
116
109
|
|
117
110
|
##
|
@@ -119,8 +112,8 @@ module SolanaRB
|
|
119
112
|
#
|
120
113
|
# @param [Hash] options Optional parameters for the request.
|
121
114
|
# @return [Array<Hash>] The list of cluster nodes.
|
122
|
-
def get_cluster_nodes(options = {})
|
123
|
-
request_http('getClusterNodes', [options])
|
115
|
+
def get_cluster_nodes(options = {}, &block)
|
116
|
+
request_http('getClusterNodes', [options], &block)
|
124
117
|
end
|
125
118
|
|
126
119
|
##
|
@@ -128,8 +121,8 @@ module SolanaRB
|
|
128
121
|
#
|
129
122
|
# @param [Hash] options Optional parameters for the request.
|
130
123
|
# @return [Hash] The epoch information.
|
131
|
-
def get_epoch_info(options = {})
|
132
|
-
request_http('getEpochInfo', [options])
|
124
|
+
def get_epoch_info(options = {}, &block)
|
125
|
+
request_http('getEpochInfo', [options], &block)
|
133
126
|
end
|
134
127
|
|
135
128
|
##
|
@@ -137,8 +130,8 @@ module SolanaRB
|
|
137
130
|
#
|
138
131
|
# @param [Hash] options Optional parameters for the request.
|
139
132
|
# @return [Hash] The epoch schedule.
|
140
|
-
def get_epoch_schedule(options = {})
|
141
|
-
request_http('getEpochSchedule', [options])
|
133
|
+
def get_epoch_schedule(options = {}, &block)
|
134
|
+
request_http('getEpochSchedule', [options], &block)
|
142
135
|
end
|
143
136
|
|
144
137
|
##
|
@@ -147,8 +140,8 @@ module SolanaRB
|
|
147
140
|
# @param [String] message The message for which the fee is to be calculated.
|
148
141
|
# @param [Hash] options Optional parameters for the request.
|
149
142
|
# @return [Integer] The fee for the message.
|
150
|
-
def get_fee_for_message(message, options = {})
|
151
|
-
request_http('getFeeForMessage', [message, options])
|
143
|
+
def get_fee_for_message(message, options = {}, &block)
|
144
|
+
request_http('getFeeForMessage', [message, options], &block)
|
152
145
|
end
|
153
146
|
|
154
147
|
##
|
@@ -156,8 +149,8 @@ module SolanaRB
|
|
156
149
|
#
|
157
150
|
# @param [Hash] options Optional parameters for the request.
|
158
151
|
# @return [Integer] The slot of the first available block.
|
159
|
-
def get_first_available_block(options = {})
|
160
|
-
request_http('getFirstAvailableBlock', [options])
|
152
|
+
def get_first_available_block(options = {}, &block)
|
153
|
+
request_http('getFirstAvailableBlock', [options], &block)
|
161
154
|
end
|
162
155
|
|
163
156
|
##
|
@@ -165,8 +158,8 @@ module SolanaRB
|
|
165
158
|
#
|
166
159
|
# @param [Hash] options Optional parameters for the request.
|
167
160
|
# @return [String] The genesis hash.
|
168
|
-
def get_genesis_hash(options = {})
|
169
|
-
request_http('getGenesisHash', [options])
|
161
|
+
def get_genesis_hash(options = {}, &block)
|
162
|
+
request_http('getGenesisHash', [options], &block)
|
170
163
|
end
|
171
164
|
|
172
165
|
##
|
@@ -174,8 +167,8 @@ module SolanaRB
|
|
174
167
|
#
|
175
168
|
# @param [Hash] options Optional parameters for the request.
|
176
169
|
# @return [String] The health status of the node.
|
177
|
-
def get_health(options = {})
|
178
|
-
request_http('getHealth', [options])
|
170
|
+
def get_health(options = {}, &block)
|
171
|
+
request_http('getHealth', [options], &block)
|
179
172
|
end
|
180
173
|
|
181
174
|
##
|
@@ -183,8 +176,8 @@ module SolanaRB
|
|
183
176
|
#
|
184
177
|
# @param [Hash] options Optional parameters for the request.
|
185
178
|
# @return [Integer] The highest snapshot slot.
|
186
|
-
def get_highest_snapshot_slot(options = {})
|
187
|
-
request_http('getHighestSnapshotSlot', [options])
|
179
|
+
def get_highest_snapshot_slot(options = {}, &block)
|
180
|
+
request_http('getHighestSnapshotSlot', [options], &block)
|
188
181
|
end
|
189
182
|
|
190
183
|
##
|
@@ -192,8 +185,8 @@ module SolanaRB
|
|
192
185
|
#
|
193
186
|
# @param [Hash] options Optional parameters for the request.
|
194
187
|
# @return [Hash] The identity information of the node.
|
195
|
-
def get_identity(options = {})
|
196
|
-
request_http('getIdentity', [options])
|
188
|
+
def get_identity(options = {}, &block)
|
189
|
+
request_http('getIdentity', [options], &block)
|
197
190
|
end
|
198
191
|
|
199
192
|
##
|
@@ -201,8 +194,8 @@ module SolanaRB
|
|
201
194
|
#
|
202
195
|
# @param [Hash] options Optional parameters for the request.
|
203
196
|
# @return [Hash] The inflation governor settings.
|
204
|
-
def get_inflation_governor(options = {})
|
205
|
-
request_http('getInflationGovernor', [options])
|
197
|
+
def get_inflation_governor(options = {}, &block)
|
198
|
+
request_http('getInflationGovernor', [options], &block)
|
206
199
|
end
|
207
200
|
|
208
201
|
##
|
@@ -210,8 +203,8 @@ module SolanaRB
|
|
210
203
|
#
|
211
204
|
# @param [Hash] options Optional parameters for the request.
|
212
205
|
# @return [Hash] The inflation rate.
|
213
|
-
def get_inflation_rate(options = {})
|
214
|
-
request_http('getInflationRate', [options])
|
206
|
+
def get_inflation_rate(options = {}, &block)
|
207
|
+
request_http('getInflationRate', [options], &block)
|
215
208
|
end
|
216
209
|
|
217
210
|
##
|
@@ -220,8 +213,8 @@ module SolanaRB
|
|
220
213
|
# @param [Array<String>] addresses The list of addresses.
|
221
214
|
# @param [Hash] options Optional parameters for the request.
|
222
215
|
# @return [Array<Hash>] The inflation rewards for the addresses.
|
223
|
-
def get_inflation_reward(addresses, options = {})
|
224
|
-
request_http('getInflationReward', [addresses, options])
|
216
|
+
def get_inflation_reward(addresses, options = {}, &block)
|
217
|
+
request_http('getInflationReward', [addresses, options], &block)
|
225
218
|
end
|
226
219
|
|
227
220
|
##
|
@@ -229,8 +222,8 @@ module SolanaRB
|
|
229
222
|
#
|
230
223
|
# @param [Hash] options Optional parameters for the request.
|
231
224
|
# @return [Array<Hash>] The largest accounts.
|
232
|
-
def get_largest_accounts(options = {})
|
233
|
-
request_http('getLargestAccounts', [options])
|
225
|
+
def get_largest_accounts(options = {}, &block)
|
226
|
+
request_http('getLargestAccounts', [options], &block)
|
234
227
|
end
|
235
228
|
|
236
229
|
##
|
@@ -238,8 +231,8 @@ module SolanaRB
|
|
238
231
|
#
|
239
232
|
# @param [Hash] options Optional parameters for the request.
|
240
233
|
# @return [Hash] The latest blockhash.
|
241
|
-
def get_latest_blockhash(options = {})
|
242
|
-
request_http('getLatestBlockhash', [options])
|
234
|
+
def get_latest_blockhash(options = {}, &block)
|
235
|
+
request_http('getLatestBlockhash', [options], &block)
|
243
236
|
end
|
244
237
|
|
245
238
|
##
|
@@ -247,8 +240,8 @@ module SolanaRB
|
|
247
240
|
#
|
248
241
|
# @param [Hash] options Optional parameters for the request.
|
249
242
|
# @return [Hash] The leader schedule.
|
250
|
-
def get_leader_schedule(options = {})
|
251
|
-
request_http('getLeaderSchedule', [options])
|
243
|
+
def get_leader_schedule(options = {}, &block)
|
244
|
+
request_http('getLeaderSchedule', [options], &block)
|
252
245
|
end
|
253
246
|
|
254
247
|
##
|
@@ -256,8 +249,8 @@ module SolanaRB
|
|
256
249
|
#
|
257
250
|
# @param [Hash] options Optional parameters for the request.
|
258
251
|
# @return [Integer] The maximum retransmit slot.
|
259
|
-
def get_max_retransmit_slot(options = {})
|
260
|
-
request_http('getMaxRetransmitSlot', [options])
|
252
|
+
def get_max_retransmit_slot(options = {}, &block)
|
253
|
+
request_http('getMaxRetransmitSlot', [options], &block)
|
261
254
|
end
|
262
255
|
|
263
256
|
##
|
@@ -265,8 +258,8 @@ module SolanaRB
|
|
265
258
|
#
|
266
259
|
# @param [Hash] options Optional parameters for the request.
|
267
260
|
# @return [Integer] The maximum shred insert slot.
|
268
|
-
def get_max_shred_insert_slot(options = {})
|
269
|
-
request_http('getMaxShredInsertSlot', [options])
|
261
|
+
def get_max_shred_insert_slot(options = {}, &block)
|
262
|
+
request_http('getMaxShredInsertSlot', [options], &block)
|
270
263
|
end
|
271
264
|
|
272
265
|
##
|
@@ -275,8 +268,8 @@ module SolanaRB
|
|
275
268
|
# @param [Integer] data_length The length of the data in bytes.
|
276
269
|
# @param [Hash] options Optional parameters for the request.
|
277
270
|
# @return [Integer] The minimum balance for rent exemption.
|
278
|
-
def get_minimum_balance_for_rent_exemption(data_length, options = {})
|
279
|
-
request_http('getMinimumBalanceForRentExemption', [data_length, options])
|
271
|
+
def get_minimum_balance_for_rent_exemption(data_length, options = {}, &block)
|
272
|
+
request_http('getMinimumBalanceForRentExemption', [data_length, options], &block)
|
280
273
|
end
|
281
274
|
|
282
275
|
##
|
@@ -285,8 +278,8 @@ module SolanaRB
|
|
285
278
|
# @param [Array<String>] pubkeys The list of public keys.
|
286
279
|
# @param [Hash] options Optional parameters for the request.
|
287
280
|
# @return [Array<Hash>] The information for the accounts.
|
288
|
-
def get_multiple_accounts(pubkeys, options = {})
|
289
|
-
request_http('getMultipleAccounts', [pubkeys, options])
|
281
|
+
def get_multiple_accounts(pubkeys, options = {}, &block)
|
282
|
+
request_http('getMultipleAccounts', [pubkeys, options], &block)
|
290
283
|
end
|
291
284
|
|
292
285
|
##
|
@@ -295,8 +288,8 @@ module SolanaRB
|
|
295
288
|
# @param [String] pubkey The public key of the program.
|
296
289
|
# @param [Hash] options Optional parameters for the request.
|
297
290
|
# @return [Array<Hash>] The information for the program accounts.
|
298
|
-
def get_program_accounts(pubkey, options = {})
|
299
|
-
request_http('getProgramAccounts', [pubkey, options])
|
291
|
+
def get_program_accounts(pubkey, options = {}, &block)
|
292
|
+
request_http('getProgramAccounts', [pubkey, options], &block)
|
300
293
|
end
|
301
294
|
|
302
295
|
##
|
@@ -304,8 +297,8 @@ module SolanaRB
|
|
304
297
|
#
|
305
298
|
# @param [Hash] options Optional parameters for the request.
|
306
299
|
# @return [Array<Hash>] The recent performance samples.
|
307
|
-
def get_recent_performance_samples(options = {})
|
308
|
-
request_http('getRecentPerformanceSamples', [options])
|
300
|
+
def get_recent_performance_samples(options = {}, &block)
|
301
|
+
request_http('getRecentPerformanceSamples', [options], &block)
|
309
302
|
end
|
310
303
|
|
311
304
|
##
|
@@ -313,8 +306,8 @@ module SolanaRB
|
|
313
306
|
#
|
314
307
|
# @param [Hash] options Optional parameters for the request.
|
315
308
|
# @return [Hash] The recent prioritization fees.
|
316
|
-
def get_recent_prioritization_fees(options = {})
|
317
|
-
request_http('getRecentPrioritizationFees', [options])
|
309
|
+
def get_recent_prioritization_fees(options = {}, &block)
|
310
|
+
request_http('getRecentPrioritizationFees', [options], &block)
|
318
311
|
end
|
319
312
|
|
320
313
|
##
|
@@ -323,8 +316,8 @@ module SolanaRB
|
|
323
316
|
# @param [Array<String>] signatures The list of transaction signatures.
|
324
317
|
# @param [Hash] options Optional parameters for the request.
|
325
318
|
# @return [Array<Hash>] The status of the transaction signatures.
|
326
|
-
def get_signature_statuses(signatures, options = {})
|
327
|
-
request_http('getSignatureStatuses', [signatures, options])
|
319
|
+
def get_signature_statuses(signatures, options = {}, &block)
|
320
|
+
request_http('getSignatureStatuses', [signatures, options], &block)
|
328
321
|
end
|
329
322
|
|
330
323
|
##
|
@@ -333,8 +326,8 @@ module SolanaRB
|
|
333
326
|
# @param [String] address The address for which to retrieve signatures.
|
334
327
|
# @param [Hash] options Optional parameters for the request.
|
335
328
|
# @return [Array<Hash>] The signatures for the address.
|
336
|
-
def get_signatures_for_address(address, options = {})
|
337
|
-
request_http('getSignaturesForAddress', [address, options])
|
329
|
+
def get_signatures_for_address(address, options = {}, &block)
|
330
|
+
request_http('getSignaturesForAddress', [address, options], &block)
|
338
331
|
end
|
339
332
|
|
340
333
|
##
|
@@ -342,8 +335,8 @@ module SolanaRB
|
|
342
335
|
#
|
343
336
|
# @param [Hash] options Optional parameters for the request.
|
344
337
|
# @return [Integer] The current slot.
|
345
|
-
def get_slot(options = {})
|
346
|
-
request_http('getSlot', [options])
|
338
|
+
def get_slot(options = {}, &block)
|
339
|
+
request_http('getSlot', [options], &block)
|
347
340
|
end
|
348
341
|
|
349
342
|
##
|
@@ -351,8 +344,8 @@ module SolanaRB
|
|
351
344
|
#
|
352
345
|
# @param [Hash] options Optional parameters for the request.
|
353
346
|
# @return [String] The current slot leader.
|
354
|
-
def get_slot_leader(options = {})
|
355
|
-
request_http('getSlotLeader', [options])
|
347
|
+
def get_slot_leader(options = {}, &block)
|
348
|
+
request_http('getSlotLeader', [options], &block)
|
356
349
|
end
|
357
350
|
|
358
351
|
##
|
@@ -362,8 +355,8 @@ module SolanaRB
|
|
362
355
|
# @param [Integer] limit The maximum number of leaders to return.
|
363
356
|
# @param [Hash] options Optional parameters for the request.
|
364
357
|
# @return [Array<String>] The slot leaders.
|
365
|
-
def get_slot_leaders(start_slot, limit, options = {})
|
366
|
-
request_http('getSlotLeaders', [start_slot, limit, options])
|
358
|
+
def get_slot_leaders(start_slot, limit, options = {}, &block)
|
359
|
+
request_http('getSlotLeaders', [start_slot, limit, options], &block)
|
367
360
|
end
|
368
361
|
|
369
362
|
##
|
@@ -372,8 +365,8 @@ module SolanaRB
|
|
372
365
|
# @param [String] pubkey The public key of the stake account.
|
373
366
|
# @param [Hash] options Optional parameters for the request.
|
374
367
|
# @return [Hash] The stake activation information.
|
375
|
-
def get_stake_activation(pubkey, options = {})
|
376
|
-
request_http('getStakeActivation', [pubkey, options])
|
368
|
+
def get_stake_activation(pubkey, options = {}, &block)
|
369
|
+
request_http('getStakeActivation', [pubkey, options], &block)
|
377
370
|
end
|
378
371
|
|
379
372
|
##
|
@@ -381,8 +374,8 @@ module SolanaRB
|
|
381
374
|
#
|
382
375
|
# @param [Hash] options Optional parameters for the request.
|
383
376
|
# @return [Integer] The minimum delegation.
|
384
|
-
def get_stake_minimum_delegation(options = {})
|
385
|
-
request_http('getStakeMinimumDelegation', [options])
|
377
|
+
def get_stake_minimum_delegation(options = {}, &block)
|
378
|
+
request_http('getStakeMinimumDelegation', [options], &block)
|
386
379
|
end
|
387
380
|
|
388
381
|
##
|
@@ -390,8 +383,8 @@ module SolanaRB
|
|
390
383
|
#
|
391
384
|
# @param [Hash] options Optional parameters for the request.
|
392
385
|
# @return [Hash] The supply information.
|
393
|
-
def get_supply(options = {})
|
394
|
-
request_http('getSupply', [options])
|
386
|
+
def get_supply(options = {}, &block)
|
387
|
+
request_http('getSupply', [options], &block)
|
395
388
|
end
|
396
389
|
|
397
390
|
##
|
@@ -400,8 +393,8 @@ module SolanaRB
|
|
400
393
|
# @param [String] pubkey The public key of the token account.
|
401
394
|
# @param [Hash] options Optional parameters for the request.
|
402
395
|
# @return [Hash] The token balance.
|
403
|
-
def get_token_account_balance(pubkey, options = {})
|
404
|
-
request_http('getTokenAccountBalance', [pubkey, options])
|
396
|
+
def get_token_account_balance(pubkey, options = {}, &block)
|
397
|
+
request_http('getTokenAccountBalance', [pubkey, options], &block)
|
405
398
|
end
|
406
399
|
|
407
400
|
##
|
@@ -411,8 +404,8 @@ module SolanaRB
|
|
411
404
|
# @param [Hash] opts Additional options for the request.
|
412
405
|
# @param [Hash] options Optional parameters for the request.
|
413
406
|
# @return [Array<Hash>] The token accounts by delegate.
|
414
|
-
def get_token_accounts_by_delegate(delegate, opts = {}, options = {})
|
415
|
-
request_http('getTokenAccountsByDelegate', [delegate, opts, options])
|
407
|
+
def get_token_accounts_by_delegate(delegate, opts = {}, options = {}, &block)
|
408
|
+
request_http('getTokenAccountsByDelegate', [delegate, opts, options], &block)
|
416
409
|
end
|
417
410
|
|
418
411
|
##
|
@@ -422,8 +415,8 @@ module SolanaRB
|
|
422
415
|
# @param [Hash] opts Additional options for the request.
|
423
416
|
# @param [Hash] options Optional parameters for the request.
|
424
417
|
# @return [Array<Hash>] The token accounts by owner.
|
425
|
-
def get_token_accounts_by_owner(owner, opts = {}, options = {})
|
426
|
-
request_http('getTokenAccountsByOwner', [owner, opts, options])
|
418
|
+
def get_token_accounts_by_owner(owner, opts = {}, options = {}, &block)
|
419
|
+
request_http('getTokenAccountsByOwner', [owner, opts, options], &block)
|
427
420
|
end
|
428
421
|
|
429
422
|
##
|
@@ -432,8 +425,8 @@ module SolanaRB
|
|
432
425
|
# @param [String] pubkey The public key of the token.
|
433
426
|
# @param [Hash] options Optional parameters for the request.
|
434
427
|
# @return [Array<Hash>] The largest accounts for the token.
|
435
|
-
def get_token_largest_accounts(pubkey, options = {})
|
436
|
-
request_http('getTokenLargestAccounts', [pubkey, options])
|
428
|
+
def get_token_largest_accounts(pubkey, options = {}, &block)
|
429
|
+
request_http('getTokenLargestAccounts', [pubkey, options], &block)
|
437
430
|
end
|
438
431
|
|
439
432
|
##
|
@@ -442,8 +435,8 @@ module SolanaRB
|
|
442
435
|
# @param [String] pubkey The public key of the token.
|
443
436
|
# @param [Hash] options Optional parameters for the request.
|
444
437
|
# @return [Hash] The token supply.
|
445
|
-
def get_token_supply(pubkey, options = {})
|
446
|
-
request_http('getTokenSupply', [pubkey, options])
|
438
|
+
def get_token_supply(pubkey, options = {}, &block)
|
439
|
+
request_http('getTokenSupply', [pubkey, options], &block)
|
447
440
|
end
|
448
441
|
|
449
442
|
##
|
@@ -452,8 +445,8 @@ module SolanaRB
|
|
452
445
|
# @param [String] signature The transaction signature.
|
453
446
|
# @param [Hash] options Optional parameters for the request.
|
454
447
|
# @return [Hash] The transaction details.
|
455
|
-
def get_transaction(signature, options = {})
|
456
|
-
request_http('getTransaction', [signature, options])
|
448
|
+
def get_transaction(signature, options = {}, &block)
|
449
|
+
request_http('getTransaction', [signature, options], &block)
|
457
450
|
end
|
458
451
|
|
459
452
|
##
|
@@ -461,16 +454,16 @@ module SolanaRB
|
|
461
454
|
#
|
462
455
|
# @param [Hash] options Optional parameters for the request.
|
463
456
|
# @return [Integer] The total number of transactions.
|
464
|
-
def get_transaction_count(options = {})
|
465
|
-
request_http('getTransactionCount', [options])
|
457
|
+
def get_transaction_count(options = {}, &block)
|
458
|
+
request_http('getTransactionCount', [options], &block)
|
466
459
|
end
|
467
460
|
|
468
461
|
##
|
469
462
|
# Retrieves the current version of the Solana software.
|
470
463
|
#
|
471
464
|
# @return [Hash] The current version information.
|
472
|
-
def get_version
|
473
|
-
request_http('getVersion')
|
465
|
+
def get_version(&block)
|
466
|
+
request_http('getVersion', &block)
|
474
467
|
end
|
475
468
|
|
476
469
|
##
|
@@ -478,8 +471,8 @@ module SolanaRB
|
|
478
471
|
#
|
479
472
|
# @param [Hash] options Optional parameters for the request.
|
480
473
|
# @return [Hash] The list of vote accounts.
|
481
|
-
def get_vote_accounts(options = {})
|
482
|
-
request_http('getVoteAccounts', [options])
|
474
|
+
def get_vote_accounts(options = {}, &block)
|
475
|
+
request_http('getVoteAccounts', [options], &block)
|
483
476
|
end
|
484
477
|
|
485
478
|
##
|
@@ -488,8 +481,8 @@ module SolanaRB
|
|
488
481
|
# @param [String] blockhash The blockhash to check.
|
489
482
|
# @param [Hash] options Optional parameters for the request.
|
490
483
|
# @return [Boolean] Whether the blockhash is valid.
|
491
|
-
def is_blockhash_valid(blockhash, options = {})
|
492
|
-
request_http('isBlockhashValid', [blockhash, options])
|
484
|
+
def is_blockhash_valid(blockhash, options = {}, &block)
|
485
|
+
request_http('isBlockhashValid', [blockhash, options], &block)
|
493
486
|
end
|
494
487
|
|
495
488
|
##
|
@@ -497,8 +490,8 @@ module SolanaRB
|
|
497
490
|
#
|
498
491
|
# @param [Hash] options Optional parameters for the request.
|
499
492
|
# @return [Integer] The minimum ledger slot.
|
500
|
-
def minimum_ledger_slot(options = {})
|
501
|
-
request_http('minimumLedgerSlot', [options])
|
493
|
+
def minimum_ledger_slot(options = {}, &block)
|
494
|
+
request_http('minimumLedgerSlot', [options], &block)
|
502
495
|
end
|
503
496
|
|
504
497
|
##
|
@@ -508,8 +501,8 @@ module SolanaRB
|
|
508
501
|
# @param [Integer] lamports The amount of lamports to airdrop.
|
509
502
|
# @param [Hash] options Optional parameters for the request.
|
510
503
|
# @return [Hash] The airdrop request response.
|
511
|
-
def request_airdrop(pubkey, lamports, options = {})
|
512
|
-
request_http('requestAirdrop', [pubkey, lamports, options])
|
504
|
+
def request_airdrop(pubkey, lamports, options = {}, &block)
|
505
|
+
request_http('requestAirdrop', [pubkey, lamports, options], &block)
|
513
506
|
end
|
514
507
|
|
515
508
|
##
|
@@ -517,8 +510,8 @@ module SolanaRB
|
|
517
510
|
#
|
518
511
|
# @param [Hash] transaction The transaction to send.
|
519
512
|
# @return [Hash] The response from the send transaction request.
|
520
|
-
def send_transaction(transaction)
|
521
|
-
request_http('sendTransaction', [transaction.to_json])
|
513
|
+
def send_transaction(transaction, &block)
|
514
|
+
request_http('sendTransaction', [transaction.to_json], &block)
|
522
515
|
end
|
523
516
|
|
524
517
|
##
|
@@ -527,8 +520,8 @@ module SolanaRB
|
|
527
520
|
# @param [Hash] transaction The transaction to simulate.
|
528
521
|
# @param [Hash] options Optional parameters for the request.
|
529
522
|
# @return [Hash] The simulation response.
|
530
|
-
def simulate_transaction(transaction, options = {})
|
531
|
-
request_http('simulateTransaction', [transaction.to_json, options])
|
523
|
+
def simulate_transaction(transaction, options = {}, &block)
|
524
|
+
request_http('simulateTransaction', [transaction.to_json, options], &block)
|
532
525
|
end
|
533
526
|
|
534
527
|
##
|
@@ -693,13 +686,14 @@ module SolanaRB
|
|
693
686
|
request_ws('voteUnsubscribe', [subscription_id], &block)
|
694
687
|
end
|
695
688
|
|
689
|
+
private
|
696
690
|
##
|
697
691
|
# Sends a JSON-RPC request to the Solana API.
|
698
692
|
#
|
699
693
|
# @param [String] method The RPC method to call.
|
700
694
|
# @param [Array] params The parameters for the RPC method.
|
701
|
-
# @
|
702
|
-
def request_http(method, params = nil)
|
695
|
+
# @yield [Object] The parsed response from the API.
|
696
|
+
def request_http(method, params = nil, &block)
|
703
697
|
body = {
|
704
698
|
jsonrpc: '2.0',
|
705
699
|
method: method,
|
@@ -707,12 +701,11 @@ module SolanaRB
|
|
707
701
|
}
|
708
702
|
body[:params] = params if params
|
709
703
|
|
710
|
-
|
711
|
-
|
712
|
-
|
704
|
+
HTTPX.post(@api_endpoint::HTTP, json: body).then do |response|
|
705
|
+
handle_response_http(response, &block)
|
706
|
+
rescue => e
|
707
|
+
puts "HTTP request failed: #{e}"
|
713
708
|
end
|
714
|
-
|
715
|
-
handle_response_http(response)
|
716
709
|
end
|
717
710
|
|
718
711
|
##
|
@@ -720,12 +713,17 @@ module SolanaRB
|
|
720
713
|
#
|
721
714
|
# @param [Faraday::Response] response The HTTP response object.
|
722
715
|
# @raise [RuntimeError] If the request fails (non-success response).
|
723
|
-
# @
|
724
|
-
def handle_response_http(response)
|
725
|
-
if response.
|
726
|
-
response.body['result']
|
716
|
+
# @yield [Object] The parsed result from the API response.
|
717
|
+
def handle_response_http(response, &block)
|
718
|
+
if response.status == 200
|
719
|
+
result = JSON.parse(response.body)['result']
|
720
|
+
if block_given?
|
721
|
+
yield result
|
722
|
+
else
|
723
|
+
result
|
724
|
+
end
|
727
725
|
else
|
728
|
-
raise "Request failed
|
726
|
+
raise "Request failed"
|
729
727
|
end
|
730
728
|
end
|
731
729
|
|
data/lib/solana-ruby/keypair.rb
CHANGED
data/lib/solana-ruby/utils.rb
CHANGED
data/lib/solana-ruby/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = '0.1.
|
1
|
+
module Solana
|
2
|
+
VERSION = '0.1.2'.freeze
|
3
3
|
end
|
data/lib/solana-ruby.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: solana-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabrice Renard
|
@@ -11,33 +11,33 @@ cert_chain: []
|
|
11
11
|
date: 2024-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: httpx
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '1.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '1.2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: faye-websocket
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.11.3
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.11.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: csv
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|