solana-ruby 0.1.1 → 0.1.3

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