solana_rpc_ruby 1.0.0.pre → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
1
  require 'json'
2
- require 'pry'
3
2
  require_relative 'request_body'
4
3
  require_relative 'helper_methods'
5
4
 
@@ -20,23 +19,35 @@ module SolanaRpcRuby
20
19
  # @return [String]
21
20
  attr_accessor :cluster
22
21
 
22
+ # Unique client-generated identifying integer.
23
+ # @return [Integer]
24
+ attr_accessor :id
25
+
23
26
  # Initialize object with cluster address where requests will be sent.
24
- #
27
+ #
25
28
  # @param api_client [ApiClient]
26
- # @param cluster [String] cluster where requests will be sent.
27
- def initialize(api_client: ApiClient, cluster: SolanaRpcRuby.cluster)
29
+ # @param cluster [String] cluster where requests will be sent.
30
+ # @param id [Integer] unique client-generated identifying integer.
31
+ def initialize(
32
+ api_client: ApiClient,
33
+ cluster: SolanaRpcRuby.cluster,
34
+ id: rand(1...99_999)
35
+ )
36
+
28
37
  @api_client = api_client.new(cluster)
38
+ @cluster = cluster
39
+ @id = id
29
40
  end
30
41
 
31
42
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getaccountinfo
32
43
  # Returns all information associated with the account of provided Pubkey
33
- #
44
+ #
34
45
  # @param account_pubkey [String]
35
46
  # @param encoding [String]
36
47
  # @param data_slice [Hash]
37
48
  # @option data_slice [Integer] :offset
38
49
  # @option data_slice [Integer] :length
39
- #
50
+ #
40
51
  # @return [Response, ApiError] Response when success, ApiError on failure.
41
52
  def get_account_info(account_pubkey, encoding: '', data_slice: {})
42
53
  http_method = :post
@@ -58,10 +69,10 @@ module SolanaRpcRuby
58
69
 
59
70
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getbalance
60
71
  # Returns the balance of the account of provided Pubkey
61
- #
72
+ #
62
73
  # @param account_pubkey [String]
63
74
  # @param commitment [String]
64
- #
75
+ #
65
76
  # @return [Response, ApiError] Response when success, ApiError on failure.
66
77
  def get_balance(account_pubkey, commitment: nil)
67
78
  http_method = :post
@@ -84,13 +95,13 @@ module SolanaRpcRuby
84
95
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getblock
85
96
  # NEW: This method is only available in solana-core v1.7 or newer. Please use getConfirmedBlock for solana-core v1.6
86
97
  # Returns identity and transaction information about a confirmed block in the ledger
87
- #
98
+ #
88
99
  # @param slot [Integer]
89
100
  # @param encoding [String]
90
101
  # @param transaction_details [String]
91
102
  # @param rewards [Boolean]
92
103
  # @param commitment [String]
93
- #
104
+ #
94
105
  # @return [Response, ApiError] Response when success, ApiError on failure.
95
106
  def get_block(slot, encoding: '', transaction_details: '', rewards: true, commitment: nil)
96
107
  http_method = :post
@@ -114,9 +125,9 @@ module SolanaRpcRuby
114
125
 
115
126
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getblockheight
116
127
  # Returns the current block height of the node
117
- #
128
+ #
118
129
  # @param commitment [String]
119
- #
130
+ #
120
131
  # @return [Response, ApiError] Response when success, ApiError on failure.
121
132
  def get_block_height(commitment: nil)
122
133
  http_method = :post
@@ -135,13 +146,13 @@ module SolanaRpcRuby
135
146
 
136
147
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getblockproduction
137
148
  # Returns recent block production information from the current or previous epoch.
138
- #
149
+ #
139
150
  # @param identity [String]
140
151
  # @param range [Hash]
141
152
  # @option range [Integer] first_slot (required for range)
142
153
  # @option range [Integer] last_slot (optional for range)
143
154
  # @param commitment [String]
144
- #
155
+ #
145
156
  # @return [Response, ApiError] Response when success, ApiError on failure.
146
157
  def get_block_production(identity: nil, range: {}, commitment: nil)
147
158
  http_method = :post
@@ -153,7 +164,7 @@ module SolanaRpcRuby
153
164
 
154
165
  range_hash['firstSlot'] = range[:first_slot] unless !range.key?(:first_slot)
155
166
  range_hash['lastSlot'] = range[:last_slot] unless !range.key?(:last_slot)
156
-
167
+
157
168
  params_hash['identity'] = identity unless blank?(identity)
158
169
  params_hash['range'] = range_hash unless range_hash.empty?
159
170
 
@@ -166,9 +177,9 @@ module SolanaRpcRuby
166
177
 
167
178
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getblockcommitment
168
179
  # Returns commitment for particular block
169
- #
180
+ #
170
181
  # @param block [Integer]
171
- #
182
+ #
172
183
  # @return [Response, ApiError] Response when success, ApiError on failure.
173
184
  def get_block_commitment(block)
174
185
  http_method = :post
@@ -186,10 +197,10 @@ module SolanaRpcRuby
186
197
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getblocks
187
198
  # NEW: This method is only available in solana-core v1.7 or newer. Please use getConfirmedBlocks for solana-core v1.6
188
199
  # Returns a list of confirmed blocks between two slots
189
- #
200
+ #
190
201
  # @param start_slot [Integer]
191
202
  # @param end_slot [Integer]
192
- #
203
+ #
193
204
  # @return [Response, ApiError] Response when success, ApiError on failure.
194
205
  def get_blocks(start_slot, end_slot: nil)
195
206
  http_method = :post
@@ -208,11 +219,11 @@ module SolanaRpcRuby
208
219
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getblockswithlimit
209
220
  # NEW: This method is only available in solana-core v1.7 or newer. Please use getConfirmedBlocks for solana-core v1.6
210
221
  # Returns a list of confirmed blocks starting at the given slot
211
- #
222
+ #
212
223
  # @param start_slot [Integer]
213
224
  # @param limit [Integer]
214
225
  # @param commitment [String]
215
- #
226
+ #
216
227
  # @return [Response, ApiError] Response when success, ApiError on failure.
217
228
  def get_blocks_with_limit(start_slot, limit, commitment: nil)
218
229
  http_method = :post
@@ -234,9 +245,9 @@ module SolanaRpcRuby
234
245
 
235
246
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getblocktime
236
247
  # Returns the estimated production time of a block.
237
- #
248
+ #
238
249
  # @param block [Integer]
239
- #
250
+ #
240
251
  # @return [Response, ApiError] Response when success, ApiError on failure.
241
252
  def get_block_time(block)
242
253
  http_method = :post
@@ -253,7 +264,7 @@ module SolanaRpcRuby
253
264
 
254
265
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getclusternodes
255
266
  # Returns information about all the nodes participating in the cluster
256
- #
267
+ #
257
268
  # @return [Response, ApiError] Response when success, ApiError on failure.
258
269
  def get_cluster_nodes
259
270
  http_method = :post
@@ -267,10 +278,10 @@ module SolanaRpcRuby
267
278
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getepochinfo
268
279
  # DEPRECATED: Please use getBlocks instead This method is expected to be removed in solana-core v1.8
269
280
  # Returns a list of confirmed blocks between two slots
270
- #
281
+ #
271
282
  # @param start_slot [Integer]
272
283
  # @param end_slot [Integer]
273
- #
284
+ #
274
285
  # @return [Response, ApiError] Response when success, ApiError on failure.
275
286
  def get_confirmed_blocks(start_slot, end_slot: nil)
276
287
  http_method = :post
@@ -288,9 +299,9 @@ module SolanaRpcRuby
288
299
 
289
300
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getepochinfo
290
301
  # Returns information about the current epoch
291
- #
302
+ #
292
303
  # @param commitment [String]
293
- #
304
+ #
294
305
  # @return [Response, ApiError] Response when success, ApiError on failure.
295
306
  def get_epoch_info(commitment: nil)
296
307
  http_method = :post
@@ -300,7 +311,7 @@ module SolanaRpcRuby
300
311
  params_hash = {}
301
312
 
302
313
  params_hash['commitment'] = commitment unless blank?(commitment)
303
-
314
+
304
315
  params << params_hash unless params_hash.empty?
305
316
 
306
317
  body = create_json_body(method, method_params: params)
@@ -310,7 +321,7 @@ module SolanaRpcRuby
310
321
 
311
322
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getepochschedule
312
323
  # Returns epoch schedule information from this cluster's genesis config
313
- #
324
+ #
314
325
  # @return [Response, ApiError] Response when success, ApiError on failure.
315
326
  def get_epoch_schedule
316
327
  http_method = :post
@@ -323,10 +334,10 @@ module SolanaRpcRuby
323
334
 
324
335
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getfeecalculatorforblockhash
325
336
  # Returns the fee calculator associated with the query blockhash, or null if the blockhash has expired
326
- #
337
+ #
327
338
  # @param query_blockhash [String]
328
339
  # @param commitment [String]
329
- #
340
+ #
330
341
  # @return [Response, ApiError] Response when success, ApiError on failure.
331
342
  def get_fee_calculator_for_blockhash(query_blockhash, commitment: nil)
332
343
  http_method = :post
@@ -347,7 +358,7 @@ module SolanaRpcRuby
347
358
 
348
359
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getfeerategovernor
349
360
  # Returns the fee rate governor information from the root bank
350
- #
361
+ #
351
362
  # @return [Response, ApiError] Response when success, ApiError on failure.
352
363
  def get_fee_rate_governor
353
364
  http_method = :post
@@ -359,11 +370,11 @@ module SolanaRpcRuby
359
370
  end
360
371
 
361
372
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getfees
362
- # Returns a recent block hash from the ledger, a fee schedule that can be used to compute
373
+ # Returns a recent block hash from the ledger, a fee schedule that can be used to compute
363
374
  # the cost of submitting a transaction using it, and the last slot in which the blockhash will be valid.
364
- #
375
+ #
365
376
  # @param commitment [String]
366
- #
377
+ #
367
378
  # @return [Response, ApiError] Response when success, ApiError on failure.
368
379
  def get_fees(commitment: nil)
369
380
  http_method = :post
@@ -382,7 +393,7 @@ module SolanaRpcRuby
382
393
 
383
394
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getfirstavailableblock
384
395
  # Returns the slot of the lowest confirmed block that has not been purged from the ledger
385
- #
396
+ #
386
397
  # @return [Response, ApiError] Response when success, ApiError on failure.
387
398
  def get_first_available_block
388
399
  http_method = :post
@@ -395,12 +406,12 @@ module SolanaRpcRuby
395
406
 
396
407
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getgenesishash
397
408
  # Returns the genesis hash.
398
- #
409
+ #
399
410
  # @return [Response, ApiError] Response when success, ApiError on failure.
400
411
  def get_genesis_hash
401
412
  http_method = :post
402
413
  method = create_method_name(__method__)
403
-
414
+
404
415
  body = create_json_body(method)
405
416
 
406
417
  send_request(body, http_method)
@@ -408,12 +419,12 @@ module SolanaRpcRuby
408
419
 
409
420
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#gethealth
410
421
  # Returns the current health of the node.
411
- #
422
+ #
412
423
  # @return [Response, ApiError] Response when success, ApiError on failure.
413
424
  def get_health
414
425
  http_method = :post
415
426
  method = create_method_name(__method__)
416
-
427
+
417
428
  body = create_json_body(method)
418
429
 
419
430
  send_request(body, http_method)
@@ -421,12 +432,12 @@ module SolanaRpcRuby
421
432
 
422
433
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getidentity
423
434
  # Returns the identity pubkey for the current node.
424
- #
435
+ #
425
436
  # @return [Response, ApiError] Response when success, ApiError on failure.
426
437
  def get_identity
427
438
  http_method = :post
428
439
  method = create_method_name(__method__)
429
-
440
+
430
441
  body = create_json_body(method)
431
442
 
432
443
  send_request(body, http_method)
@@ -434,9 +445,9 @@ module SolanaRpcRuby
434
445
 
435
446
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getinflationgovernor
436
447
  # Returns the current inflation governor.
437
- #
448
+ #
438
449
  # @param commitment [String]
439
- #
450
+ #
440
451
  # @return [Response, ApiError] Response when success, ApiError on failure.
441
452
  def get_inflation_governor(commitment: nil)
442
453
  http_method = :post
@@ -448,7 +459,7 @@ module SolanaRpcRuby
448
459
  params_hash['commitment'] = commitment unless blank?(commitment)
449
460
 
450
461
  params << params_hash unless params_hash.empty?
451
-
462
+
452
463
  body = create_json_body(method, method_params: params)
453
464
 
454
465
  send_request(body, http_method)
@@ -456,12 +467,12 @@ module SolanaRpcRuby
456
467
 
457
468
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getinflationrate
458
469
  # Returns the specific inflation values for the current epoch.
459
- #
470
+ #
460
471
  # @return [Response, ApiError] Response when success, ApiError on failure.
461
472
  def get_inflation_rate
462
473
  http_method = :post
463
474
  method = create_method_name(__method__)
464
-
475
+
465
476
  body = create_json_body(method)
466
477
 
467
478
  send_request(body, http_method)
@@ -469,16 +480,16 @@ module SolanaRpcRuby
469
480
 
470
481
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getinflationreward
471
482
  # Returns the inflation reward for a list of addresses for an epoch.
472
- #
483
+ #
473
484
  # @param addresses [Array]
474
485
  # @param commitment [String]
475
486
  # @param epoch [Integer]
476
- #
487
+ #
477
488
  # @return [Response, ApiError] Response when success, ApiError on failure.
478
489
  def get_inflation_reward(addresses, commitment: nil, epoch: nil)
479
490
  http_method = :post
480
491
  method = create_method_name(__method__)
481
-
492
+
482
493
  params = []
483
494
  params_hash = {}
484
495
 
@@ -496,15 +507,15 @@ module SolanaRpcRuby
496
507
 
497
508
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getlargestaccounts
498
509
  # Returns the 20 largest accounts, by lamport balance (results may be cached up to two hours)
499
- #
510
+ #
500
511
  # @param commitment [String]
501
512
  # @param filter [String]
502
- #
513
+ #
503
514
  # @return [Response, ApiError] Response when success, ApiError on failure.
504
515
  def get_largest_accounts(commitment: nil, filter: '')
505
516
  http_method = :post
506
517
  method = create_method_name(__method__)
507
-
518
+
508
519
  params = []
509
520
  params_hash = {}
510
521
 
@@ -520,16 +531,16 @@ module SolanaRpcRuby
520
531
 
521
532
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getleaderschedule
522
533
  # Returns the leader schedule for an epoch.
523
- #
534
+ #
524
535
  # @param epoch [Integer]
525
536
  # @param commitment [String]
526
537
  # @param identity [String]
527
- #
538
+ #
528
539
  # @return [Response, ApiError] Response when success, ApiError on failure.
529
540
  def get_leader_schedule(epoch: nil, commitment: nil, identity: '')
530
541
  http_method = :post
531
542
  method = create_method_name(__method__)
532
-
543
+
533
544
  params = []
534
545
  params_hash = {}
535
546
 
@@ -546,12 +557,12 @@ module SolanaRpcRuby
546
557
 
547
558
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getmaxretransmitslot
548
559
  # Get the max slot seen from retransmit stage.
549
- #
560
+ #
550
561
  # @return [Response, ApiError] Response when success, ApiError on failure.
551
562
  def get_max_retransmit_slot
552
563
  http_method = :post
553
564
  method = create_method_name(__method__)
554
-
565
+
555
566
  body = create_json_body(method)
556
567
 
557
568
  send_request(body, http_method)
@@ -559,12 +570,12 @@ module SolanaRpcRuby
559
570
 
560
571
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getmaxshredinsertslot
561
572
  # Get the max slot seen from after shred insert.
562
- #
573
+ #
563
574
  # @return [Response, ApiError] Response when success, ApiError on failure.
564
575
  def get_max_shred_insert_slot
565
576
  http_method = :post
566
577
  method = create_method_name(__method__)
567
-
578
+
568
579
  body = create_json_body(method)
569
580
 
570
581
  send_request(body, http_method)
@@ -572,23 +583,23 @@ module SolanaRpcRuby
572
583
 
573
584
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getminimumbalanceforrentexemption
574
585
  # Returns minimum balance required to make account rent exempt.
575
- #
586
+ #
576
587
  # @param account_data_length [String]
577
588
  # @param commitment [String]
578
- #
589
+ #
579
590
  # @return [Response, ApiError] Response when success, ApiError on failure.
580
591
  def get_minimum_balance_for_rent_exemption(
581
- account_data_length,
592
+ account_data_length,
582
593
  commitment: nil
583
594
  )
584
595
  http_method = :post
585
596
  method = create_method_name(__method__)
586
-
597
+
587
598
  params = []
588
599
  params_hash = {}
589
600
 
590
601
  params_hash['commitment'] = commitment unless blank?(commitment)
591
-
602
+
592
603
  params << account_data_length
593
604
  params << params_hash unless params_hash.empty?
594
605
 
@@ -597,31 +608,31 @@ module SolanaRpcRuby
597
608
  send_request(body, http_method)
598
609
  end
599
610
 
600
- # @see https://docs.solana.com/developing/clients/jsonrpc-api#getmultipleaccounts
611
+ # @see https://docs.solana.com/developing/clients/jsonrpc-api#getmultipleaccounts
601
612
  # Returns the account information for a list of Pubkeys.
602
613
  # @param account_data_length [String]
603
614
  # @param commitment [String]
604
- #
615
+ #
605
616
  # @return [Response, ApiError] Response when success, ApiError on failure. # @param account_data_length [String]
606
617
  # @param commitment [String]
607
- #
618
+ #
608
619
  # @return [Response, ApiError] Response when success, ApiError on failure.
609
620
  def get_multiple_accounts(
610
- pubkeys,
621
+ pubkeys,
611
622
  commitment: nil,
612
623
  encoding: '',
613
624
  data_slice: {}
614
625
  )
615
626
  http_method = :post
616
627
  method = create_method_name(__method__)
617
-
628
+
618
629
  params = []
619
630
  params_hash = {}
620
-
631
+
621
632
  params_hash['commitment'] = commitment unless blank?(commitment)
622
633
  params_hash['encoding'] = encoding unless blank?(encoding)
623
634
  params_hash['dataSlice'] = data_slice unless data_slice.empty?
624
-
635
+
625
636
  params << pubkeys
626
637
  params << params_hash unless params_hash.empty?
627
638
 
@@ -632,7 +643,7 @@ module SolanaRpcRuby
632
643
 
633
644
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getprogramaccounts
634
645
  # Returns all accounts owned by the provided program Pubkey
635
- #
646
+ #
636
647
  # @param pubkey [String]
637
648
  # @param commitment [String]
638
649
  # @param encoding [String]
@@ -640,11 +651,17 @@ module SolanaRpcRuby
640
651
  # @option data_slice [Integer] :offset
641
652
  # @option data_slice [Integer] :length
642
653
  # @param filters [Array<Hash, Hash>]
654
+ # @option filters [Hash<String, Integer>]
655
+ # * dataSize, Integer, 1
656
+ # @option filters [Hash<String, Hash>]
657
+ # * memcmp, Hash<String, Object>
658
+ # * offset, Integer, 1
659
+ # * bytes, String, '3Mc6vR'
643
660
  # @param with_context [Boolean]
644
- #
661
+ #
645
662
  # @return [Response, ApiError] Response when success, ApiError on failure.
646
663
  def get_program_accounts(
647
- pubkey,
664
+ pubkey,
648
665
  commitment: nil,
649
666
  encoding: '',
650
667
  data_slice: {},
@@ -653,10 +670,10 @@ module SolanaRpcRuby
653
670
  )
654
671
  http_method = :post
655
672
  method = create_method_name(__method__)
656
-
673
+
657
674
  params = []
658
675
  params_hash = {}
659
-
676
+
660
677
  params_hash['commitment'] = commitment unless blank?(commitment)
661
678
  params_hash['encoding'] = encoding unless blank?(encoding)
662
679
  params_hash['dataSlice'] = data_slice unless data_slice.empty?
@@ -672,19 +689,19 @@ module SolanaRpcRuby
672
689
  end
673
690
 
674
691
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getrecentblockhash
675
- # Returns a recent block hash from the ledger, and a fee schedule
692
+ # Returns a recent block hash from the ledger, and a fee schedule
676
693
  # that can be used to compute the cost of submitting a transaction using it.
677
- #
694
+ #
678
695
  # @param commitment [String]
679
- #
696
+ #
680
697
  # @return [Response, ApiError] Response when success, ApiError on failure.
681
698
  def get_recent_blockhash(commitment: nil)
682
699
  http_method = :post
683
700
  method = create_method_name(__method__)
684
-
701
+
685
702
  params = []
686
703
  params_hash = {}
687
-
704
+
688
705
  params_hash['commitment'] = commitment unless blank?(commitment)
689
706
 
690
707
  params << params_hash unless params_hash.empty?
@@ -695,16 +712,16 @@ module SolanaRpcRuby
695
712
  end
696
713
 
697
714
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getrecentperformancesamples
698
- # Returns a list of recent performance samples, in reverse slot order.
715
+ # Returns a list of recent performance samples, in reverse slot order.
699
716
  # Performance samples are taken every 60 seconds and include the number of transactions and slots that occur in a given time window.
700
- #
717
+ #
701
718
  # @param limit [Integer]
702
- #
719
+ #
703
720
  # @return [Response, ApiError] Response when success, ApiError on failure.
704
721
  def get_recent_performance_samples(limit: nil)
705
722
  http_method = :post
706
723
  method = create_method_name(__method__)
707
-
724
+
708
725
  params = []
709
726
 
710
727
  params << limit unless limit.nil?
@@ -716,7 +733,7 @@ module SolanaRpcRuby
716
733
 
717
734
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getsnapshotslot
718
735
  # Returns the highest slot that the node has a snapshot for.
719
- #
736
+ #
720
737
  # @return [Response, ApiError] Response when success, ApiError on failure.
721
738
  def get_snapshot_slot
722
739
  http_method = :post
@@ -728,18 +745,18 @@ module SolanaRpcRuby
728
745
  end
729
746
 
730
747
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getsignaturesforaddress
731
- # NEW: This method is only available in solana-core v1.7 or newer.
748
+ # NEW: This method is only available in solana-core v1.7 or newer.
732
749
  # Please use getConfirmedSignaturesForAddress2 for solana-core v1.6
733
- #
734
- # Returns confirmed signatures for transactions involving an address backwards
750
+ #
751
+ # Returns confirmed signatures for transactions involving an address backwards
735
752
  # in time from the provided signature or most recent confirmed block
736
- #
753
+ #
737
754
  # @param account_address [String]
738
755
  # @param limit [Integer]
739
756
  # @param before [String]
740
757
  # @param until_ [String]
741
758
  # @param commitment [String]
742
- #
759
+ #
743
760
  # @return [Response, ApiError] Response when success, ApiError on failure.
744
761
  def get_signatures_for_address(
745
762
  account_address,
@@ -750,7 +767,7 @@ module SolanaRpcRuby
750
767
  )
751
768
  http_method = :post
752
769
  method = create_method_name(__method__)
753
-
770
+
754
771
  params = []
755
772
  params_hash = {}
756
773
 
@@ -767,16 +784,16 @@ module SolanaRpcRuby
767
784
  send_request(body, http_method)
768
785
  end
769
786
 
770
- # @see https://docs.solana.com/developing/clients/jsonrpc-api#getsignaturestatuses # NEW: This method is only available in solana-core v1.7 or newer.
771
- #
772
- # Returns the statuses of a list of signatures.
773
- # Unless the searchTransactionHistory configuration parameter is included,
774
- # this method only searches the recent status cache of signatures,
787
+ # @see https://docs.solana.com/developing/clients/jsonrpc-api#getsignaturestatuses # NEW: This method is only available in solana-core v1.7 or newer.
788
+ #
789
+ # Returns the statuses of a list of signatures.
790
+ # Unless the searchTransactionHistory configuration parameter is included,
791
+ # this method only searches the recent status cache of signatures,
775
792
  # which retains statuses for all active slots plus MAX_RECENT_BLOCKHASHES rooted slots.
776
- #
793
+ #
777
794
  # @param transaction_signatures [Array]
778
795
  # @param search_transaction_history [Boolean]
779
- #
796
+ #
780
797
  # @return [Response, ApiError] Response when success, ApiError on failure.
781
798
  def get_signature_statuses(
782
799
  transaction_signatures,
@@ -784,7 +801,7 @@ module SolanaRpcRuby
784
801
  )
785
802
  http_method = :post
786
803
  method = create_method_name(__method__)
787
-
804
+
788
805
  params = []
789
806
  params_hash = {}
790
807
 
@@ -800,17 +817,17 @@ module SolanaRpcRuby
800
817
 
801
818
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getslot
802
819
  # Returns the current slot the node is processing.
803
- #
820
+ #
804
821
  # @param commitment [String]
805
- #
822
+ #
806
823
  # @return [Response, ApiError] Response when success, ApiError on failure.
807
824
  def get_slot(commitment: nil)
808
825
  http_method = :post
809
826
  method = create_method_name(__method__)
810
-
827
+
811
828
  params = []
812
829
  params_hash = {}
813
-
830
+
814
831
  params_hash['commitment'] = commitment unless blank?(commitment)
815
832
 
816
833
  params << params_hash unless params_hash.empty?
@@ -822,19 +839,19 @@ module SolanaRpcRuby
822
839
 
823
840
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getslotleader
824
841
  # Returns the current slot leader
825
- #
842
+ #
826
843
  # @param commitment [String]
827
- #
844
+ #
828
845
  # @return [Response, ApiError] Response when success, ApiError on failure.
829
846
  def get_slot_leader(commitment: nil)
830
847
  http_method = :post
831
848
  method = create_method_name(__method__)
832
-
849
+
833
850
  params = []
834
851
  params_hash = {}
835
852
 
836
853
  params_hash['commitment'] = commitment unless blank?(commitment)
837
-
854
+
838
855
  params << params_hash unless params_hash.empty?
839
856
 
840
857
  body = create_json_body(method, method_params: params)
@@ -844,15 +861,15 @@ module SolanaRpcRuby
844
861
 
845
862
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getslotleaders
846
863
  # Returns the slot leaders for a given slot range.
847
- #
864
+ #
848
865
  # @param start_slot [Integer]
849
866
  # @param limit [Integer]
850
- #
867
+ #
851
868
  # @return [Response, ApiError] Response when success, ApiError on failure.
852
869
  def get_slot_leaders(start_slot, limit)
853
870
  http_method = :post
854
871
  method = create_method_name(__method__)
855
-
872
+
856
873
  params = [start_slot, limit]
857
874
 
858
875
  body = create_json_body(method, method_params: params)
@@ -862,16 +879,16 @@ module SolanaRpcRuby
862
879
 
863
880
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getstakeactivation
864
881
  # Returns epoch activation information for a stake account.
865
- #
882
+ #
866
883
  # @param pubkey [String]
867
884
  # @param commitment [String]
868
885
  # @param epoch [Integer]
869
- #
886
+ #
870
887
  # @return [Response, ApiError] Response when success, ApiError on failure.
871
888
  def get_stake_activation(pubkey, commitment: nil, epoch: nil)
872
889
  http_method = :post
873
890
  method = create_method_name(__method__)
874
-
891
+
875
892
  params = []
876
893
  params_hash = {}
877
894
 
@@ -888,14 +905,14 @@ module SolanaRpcRuby
888
905
 
889
906
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getsupply
890
907
  # Returns information about the current supply.
891
- #
908
+ #
892
909
  # @param commitment [String]
893
- #
910
+ #
894
911
  # @return [Response, ApiError] Response when success, ApiError on failure.
895
912
  def get_supply(commitment: nil)
896
913
  http_method = :post
897
914
  method = create_method_name(__method__)
898
-
915
+
899
916
  params = []
900
917
  params_hash = {}
901
918
 
@@ -909,17 +926,17 @@ module SolanaRpcRuby
909
926
  end
910
927
 
911
928
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#gettokenaccountbalance
912
- #
929
+ #
913
930
  # Returns the token balance of an SPL Token account.
914
- #
931
+ #
915
932
  # @param token_account_pubkey [String]
916
933
  # @param commitment [String]
917
- #
934
+ #
918
935
  # @return [Response, ApiError] Response when success, ApiError on failure.
919
936
  def get_token_account_balance(token_account_pubkey, commitment: nil)
920
937
  http_method = :post
921
938
  method = create_method_name(__method__)
922
-
939
+
923
940
  params = []
924
941
  params_hash = {}
925
942
 
@@ -934,11 +951,11 @@ module SolanaRpcRuby
934
951
  end
935
952
 
936
953
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#gettokenaccountsbydelegate # Returns the token balance of an SPL Token account.
937
- #
954
+ #
938
955
  # Returns all SPL Token accounts by approved Delegate.
939
- #
956
+ #
940
957
  # IMPORTANT: According to docs there should be mint or program_id passed in, not both.
941
- #
958
+ #
942
959
  # @param token_account_pubkey [String]
943
960
  # @param mint [String]
944
961
  # @param program_id [String]
@@ -947,7 +964,7 @@ module SolanaRpcRuby
947
964
  # @param data_slice [Hash]
948
965
  # @option data_slice [Integer] :offset
949
966
  # @option data_slice [Integer] :length
950
- #
967
+ #
951
968
  # @return [Response, ApiError] Response when success, ApiError on failure.
952
969
  def get_token_accounts_by_delegate(
953
970
  token_account_pubkey,
@@ -957,22 +974,22 @@ module SolanaRpcRuby
957
974
  encoding: '',
958
975
  data_slice: {}
959
976
  )
960
-
961
- raise ArgumentError, 'You should pass mint or program_id, not both.' if !mint.empty? && !program_id.empty?
977
+
978
+ raise ArgumentError, 'You should pass mint or program_id, not both.' if !blank?(mint) && !blank?(program_id)
962
979
 
963
980
  http_method = :post
964
981
  method = create_method_name(__method__)
965
-
982
+
966
983
  params = []
967
984
  params_hash = {}
968
985
  params_hash_2 = {}
969
986
 
970
- params_hash['mint'] = mint unless mint.empty?
971
- params_hash['programId'] = program_id unless program_id.empty?
987
+ params_hash['mint'] = mint unless blank?(mint)
988
+ params_hash['programId'] = program_id unless blank?(program_id)
972
989
 
973
990
  params_hash_2['commitment'] = commitment unless blank?(commitment)
974
991
  params_hash_2['encoding'] = encoding unless blank?(encoding)
975
- params_hash_2['dataSlice'] = data_slice unless data_slice.empty?
992
+ params_hash_2['dataSlice'] = data_slice unless blank?(data_slice)
976
993
 
977
994
  params << token_account_pubkey
978
995
  params << params_hash unless params_hash.empty?
@@ -983,12 +1000,12 @@ module SolanaRpcRuby
983
1000
  send_request(body, http_method)
984
1001
  end
985
1002
 
986
- # @see https://docs.solana.com/developing/clients/jsonrpc-api#gettokenaccountsbyowner #
987
- #
1003
+ # @see https://docs.solana.com/developing/clients/jsonrpc-api#gettokenaccountsbyowner #
1004
+ #
988
1005
  # Returns all SPL Token accounts by token owner.
989
- #
1006
+ #
990
1007
  # IMPORTANT: According to docs there should be mint or program_id passed in, not both.
991
- #
1008
+ #
992
1009
  # @param token_account_pubkey [String]
993
1010
  # @param mint [String]
994
1011
  # @param program_id [String]
@@ -997,7 +1014,7 @@ module SolanaRpcRuby
997
1014
  # @param data_slice [Hash]
998
1015
  # @option data_slice [Integer] :offset
999
1016
  # @option data_slice [Integer] :length
1000
- #
1017
+ #
1001
1018
  # @return [Response, ApiError] Response when success, ApiError on failure.
1002
1019
  def get_token_accounts_by_owner(
1003
1020
  token_account_pubkey,
@@ -1012,7 +1029,7 @@ module SolanaRpcRuby
1012
1029
 
1013
1030
  http_method = :post
1014
1031
  method = create_method_name(__method__)
1015
-
1032
+
1016
1033
  params = []
1017
1034
  params_hash = {}
1018
1035
  params_hash_2 = {}
@@ -1034,13 +1051,13 @@ module SolanaRpcRuby
1034
1051
  send_request(body, http_method)
1035
1052
  end
1036
1053
 
1037
- # @see https://docs.solana.com/developing/clients/jsonrpc-api#gettokenlargestaccounts #
1038
- #
1054
+ # @see https://docs.solana.com/developing/clients/jsonrpc-api#gettokenlargestaccounts #
1055
+ #
1039
1056
  # Returns the 20 largest accounts of a particular SPL Token type.
1040
- #
1057
+ #
1041
1058
  # @param token_mint_pubkey [String]
1042
1059
  # @param commitment [String]
1043
- #
1060
+ #
1044
1061
  # @return [Response, ApiError] Response when success, ApiError on failure.
1045
1062
  def get_token_largest_accounts(
1046
1063
  token_mint_pubkey,
@@ -1049,7 +1066,7 @@ module SolanaRpcRuby
1049
1066
 
1050
1067
  http_method = :post
1051
1068
  method = create_method_name(__method__)
1052
-
1069
+
1053
1070
  params = []
1054
1071
  params_hash = {}
1055
1072
 
@@ -1063,19 +1080,19 @@ module SolanaRpcRuby
1063
1080
  send_request(body, http_method)
1064
1081
  end
1065
1082
 
1066
- # @see https://docs.solana.com/developing/clients/jsonrpc-api#gettransaction
1067
- #
1083
+ # @see https://docs.solana.com/developing/clients/jsonrpc-api#gettransaction
1084
+ #
1068
1085
  # Returns transaction details for a confirmed transaction
1069
- #
1086
+ #
1070
1087
  # @param transaction_signature [String]
1071
1088
  # @param encoding [String]
1072
1089
  # @param commitment [String]
1073
- #
1090
+ #
1074
1091
  # @return [Response, ApiError] Response when success, ApiError on failure.
1075
1092
  def get_transaction(transaction_signature, encoding: '', commitment: nil)
1076
1093
  http_method = :post
1077
1094
  method = create_method_name(__method__)
1078
-
1095
+
1079
1096
  params = []
1080
1097
  params_hash = {}
1081
1098
 
@@ -1090,17 +1107,17 @@ module SolanaRpcRuby
1090
1107
  send_request(body, http_method)
1091
1108
  end
1092
1109
 
1093
- # @see https://docs.solana.com/developing/clients/jsonrpc-api#gettransactioncount
1094
- #
1110
+ # @see https://docs.solana.com/developing/clients/jsonrpc-api#gettransactioncount
1111
+ #
1095
1112
  # Returns the current Transaction count from the ledger
1096
- #
1113
+ #
1097
1114
  # @param commitment [String]
1098
- #
1115
+ #
1099
1116
  # @return [Response, ApiError] Response when success, ApiError on failure.
1100
1117
  def get_transaction_count(commitment: nil)
1101
1118
  http_method = :post
1102
1119
  method = create_method_name(__method__)
1103
-
1120
+
1104
1121
  params = []
1105
1122
  params_hash = {}
1106
1123
 
@@ -1114,9 +1131,9 @@ module SolanaRpcRuby
1114
1131
  end
1115
1132
 
1116
1133
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getversion
1117
- #
1134
+ #
1118
1135
  # Returns the current solana versions running on the node.
1119
- #
1136
+ #
1120
1137
  # @return [Response, ApiError] Response when success, ApiError on failure.
1121
1138
  def get_version
1122
1139
  http_method = :post
@@ -1129,10 +1146,10 @@ module SolanaRpcRuby
1129
1146
 
1130
1147
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#getvoteaccounts
1131
1148
  # Returns the account info and associated stake for all the voting accounts in the current bank.
1132
- #
1149
+ #
1133
1150
  # @param commitment [String]
1134
1151
  # @param vote_pubkey [String]
1135
- #
1152
+ #
1136
1153
  # @return [Response, ApiError] Response when success, ApiError on failure.
1137
1154
  def get_vote_accounts(commitment: nil, vote_pubkey: nil)
1138
1155
  http_method = :post
@@ -1152,9 +1169,9 @@ module SolanaRpcRuby
1152
1169
  end
1153
1170
 
1154
1171
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#minimumledgerslot
1155
- #
1172
+ #
1156
1173
  # Returns the current solana versions running on the node.
1157
- #
1174
+ #
1158
1175
  # @return [Response, ApiError] Response when success, ApiError on failure.
1159
1176
  def get_version
1160
1177
  http_method = :post
@@ -1166,10 +1183,10 @@ module SolanaRpcRuby
1166
1183
  end
1167
1184
 
1168
1185
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#minimumledgerslot
1169
- #
1170
- # Returns the lowest slot that the node has information about in its ledger.
1186
+ #
1187
+ # Returns the lowest slot that the node has information about in its ledger.
1171
1188
  # This value may increase over time if the node is configured to purge older ledger data
1172
- #
1189
+ #
1173
1190
  # @return [Response, ApiError] Response when success, ApiError on failure.
1174
1191
  def minimum_ledger_slot
1175
1192
  http_method = :post
@@ -1181,13 +1198,13 @@ module SolanaRpcRuby
1181
1198
  end
1182
1199
 
1183
1200
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#requestairdrop
1184
- #
1201
+ #
1185
1202
  # Requests an airdrop of lamports to a Pubkey
1186
- #
1203
+ #
1187
1204
  # @param pubkey [String]
1188
1205
  # @param lamports [Integer]
1189
1206
  # @param commitment [String]
1190
- #
1207
+ #
1191
1208
  # @return [Response, ApiError] Response when success, ApiError on failure.
1192
1209
  def request_airdrop(pubkey, lamports, commitment: nil)
1193
1210
  http_method = :post
@@ -1206,17 +1223,17 @@ module SolanaRpcRuby
1206
1223
  end
1207
1224
 
1208
1225
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#sendtransaction
1209
- #
1226
+ #
1210
1227
  # Submits a signed transaction to the cluster for processing.
1211
- #
1228
+ #
1212
1229
  # @param transaction_signature [String]
1213
1230
  # @param skip_pre_flight [Boolean]
1214
1231
  # @param pre_flight_commitment [String]
1215
1232
  # @param encoding [String]
1216
- #
1233
+ #
1217
1234
  # @return [Response, ApiError] Response when success, ApiError on failure.
1218
1235
  def send_transaction(
1219
- transaction_signature,
1236
+ transaction_signature,
1220
1237
  skip_pre_flight: false,
1221
1238
  pre_flight_commitment: nil,
1222
1239
  encoding: ''
@@ -1241,10 +1258,10 @@ module SolanaRpcRuby
1241
1258
 
1242
1259
 
1243
1260
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#simulatetransaction
1244
- #
1261
+ #
1245
1262
  # Simulate sending a transaction
1246
1263
  # accounts_addresses should be an empty array (?)
1247
- #
1264
+ #
1248
1265
  # @param transaction_signature [String]
1249
1266
  # @param accounts_addresses [Array]
1250
1267
  # @param sig_verify [Boolean]
@@ -1252,7 +1269,7 @@ module SolanaRpcRuby
1252
1269
  # @param encoding [String]
1253
1270
  # @param replace_recent_blockhash [Boolean]
1254
1271
  # @param accounts_encoding [String]
1255
- #
1272
+ #
1256
1273
  # @return [Response, ApiError] Response when success, ApiError on failure.
1257
1274
  def simulate_transaction(
1258
1275
  transaction_signature,
@@ -1299,18 +1316,10 @@ module SolanaRpcRuby
1299
1316
  if api_response.body
1300
1317
  response = Response.new(api_response)
1301
1318
 
1302
- fail ApiError.new(response.parsed_response) if response.parsed_response.key?('error')
1319
+ fail ApiError.new(message: response.parsed_response) if response.parsed_response.key?('error')
1303
1320
 
1304
1321
  return response
1305
1322
  end
1306
1323
  end
1307
-
1308
- def create_method_name(method)
1309
- return '' unless method
1310
-
1311
- method.to_s.split('_').map.with_index do |string, i|
1312
- i == 0 ? string : string.capitalize
1313
- end.join
1314
- end
1315
1324
  end
1316
1325
  end