solana_rpc_ruby 1.0.0.pre
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 +7 -0
- data/.github/CODE_OF_CONDUCT.md +77 -0
- data/.github/CONTRIBUTING.md +14 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +11 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +8 -0
- data/LICENSE +674 -0
- data/README.md +50 -0
- data/Rakefile +19 -0
- data/lib/generators/solana_rpc_ruby/install_generator.rb +13 -0
- data/lib/generators/templates/solana_rpc_ruby_config.rb +14 -0
- data/lib/solana_rpc_ruby.rb +27 -0
- data/lib/solana_rpc_ruby/api_client.rb +63 -0
- data/lib/solana_rpc_ruby/api_error.rb +27 -0
- data/lib/solana_rpc_ruby/helper_methods.rb +16 -0
- data/lib/solana_rpc_ruby/methods_wrapper.rb +1316 -0
- data/lib/solana_rpc_ruby/request_body.rb +34 -0
- data/lib/solana_rpc_ruby/response.rb +33 -0
- data/lib/solana_rpc_ruby/version.rb +5 -0
- data/solana_rpc_ruby.gemspec +41 -0
- metadata +245 -0
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+

|
2
|
+
# solana_rpc_ruby
|
3
|
+
A Solana RPC Client for Ruby. This gem provides a wrapper methods for Solana RPC JSON API https://docs.solana.com/developing/clients/jsonrpc-api.
|
4
|
+
|
5
|
+
## Getting started
|
6
|
+
|
7
|
+
### Requirements
|
8
|
+
|
9
|
+
This gem requires Ruby 2.6+ and h Rails 6.0+. It MIGHT work with lower versions, but was not tested againt them.
|
10
|
+
Add the following line to your Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'solana_rpc_ruby'
|
14
|
+
```
|
15
|
+
|
16
|
+
Then run `bundle install`
|
17
|
+
|
18
|
+
Next, you need to run the generator:
|
19
|
+
|
20
|
+
```console
|
21
|
+
rails g solana_rpc_ruby:install
|
22
|
+
```
|
23
|
+
|
24
|
+
The latter command will generate a new config file `config/solana_rpc_ruby_config.rb` looking like this:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'solana_rpc_ruby'
|
28
|
+
|
29
|
+
SolanaRpcRuby.config do |c|
|
30
|
+
c.cluster = 'https://api.testnet.solana.com'
|
31
|
+
c.json_rpc_version = '2.0'
|
32
|
+
c.encoding = 'base58'
|
33
|
+
# ...other options
|
34
|
+
end
|
35
|
+
```
|
36
|
+
You can customize it to your needs.
|
37
|
+
|
38
|
+
### Usage examples
|
39
|
+
```ruby
|
40
|
+
# If you set default cluster you don't need to pass it every time.
|
41
|
+
method_wrapper = SolanaRpcRuby::MethodsWrapper.new(cluster: 'https://api.testnet.solana.com')
|
42
|
+
response = method_wrapper.get_account_info(account_pubkey)
|
43
|
+
puts response
|
44
|
+
```
|
45
|
+
|
46
|
+
All info about methods you can find in the docs on: FILL THE ADDRESS!!!
|
47
|
+
Also, as a reference you can use docs from solana: https://docs.solana.com/developing/clients/jsonrpc-api
|
48
|
+
## License
|
49
|
+
|
50
|
+
Copyright (c) [Block Logic Team]. License type is [MIT](https://github.com/Block-Logic/solana-rpc-ruby/blob/main/LICENSE).
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
Bundler::GemHelper.install_tasks
|
6
|
+
rescue LoadError
|
7
|
+
puts 'although not required, bundler is recommended for running the tests'
|
8
|
+
end
|
9
|
+
|
10
|
+
task default: :spec
|
11
|
+
|
12
|
+
require 'rspec/core/rake_task'
|
13
|
+
RSpec::Core::RakeTask.new(:spec)
|
14
|
+
|
15
|
+
require 'rubocop/rake_task'
|
16
|
+
RuboCop::RakeTask.new do |task|
|
17
|
+
task.requires << 'rubocop-performance'
|
18
|
+
task.requires << 'rubocop-rspec'
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
module SolanaRpcRuby
|
3
|
+
module Generators
|
4
|
+
class InstallGenerator < Rails::Generators::Base
|
5
|
+
source_root File.expand_path('../templates', __dir__)
|
6
|
+
|
7
|
+
desc 'Creates a SolanaRpcRuby config file.'
|
8
|
+
def copy_config
|
9
|
+
template 'solana_rpc_ruby_config.rb', "#{Rails.root}/config/solana_rpc_ruby.rb"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative 'solana_rpc_ruby'
|
2
|
+
|
3
|
+
# DEVNET_CLUSTER = 'https://api.devnet.solana.com'
|
4
|
+
# MAINNET_CLUSTER = 'https://api.mainnet-beta.solana.com'
|
5
|
+
# TESTNET_CLUSTER = 'https://api.testnet.solana.com'
|
6
|
+
|
7
|
+
SolanaRpcRuby.config do |c|
|
8
|
+
# These are mandatory options that you must set before using gem:
|
9
|
+
#
|
10
|
+
# c.cluster = 'https://api.testnet.solana.com'
|
11
|
+
# c.json_rpc = '2.0
|
12
|
+
# c.encoding = 'base58'
|
13
|
+
# c.id = 1
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'solana_rpc_ruby/api_client'
|
2
|
+
require_relative 'solana_rpc_ruby/api_error'
|
3
|
+
require_relative 'solana_rpc_ruby/methods_wrapper'
|
4
|
+
require_relative 'solana_rpc_ruby/response'
|
5
|
+
|
6
|
+
# Namespace for classes and modules that handle connection with solana JSON RPC API.
|
7
|
+
module SolanaRpcRuby
|
8
|
+
class << self
|
9
|
+
# Default cluster address that will be used if not passed.
|
10
|
+
# @return [String] cluster address.
|
11
|
+
attr_accessor :cluster
|
12
|
+
|
13
|
+
# Default json rpc version that will be used.
|
14
|
+
# @return [String] json rpc version.
|
15
|
+
attr_accessor :json_rpc_version
|
16
|
+
|
17
|
+
# Default encoding that will be used.
|
18
|
+
# @return [String] encoding.
|
19
|
+
attr_accessor :encoding
|
20
|
+
|
21
|
+
# Config set from initializer.
|
22
|
+
# @return [String] encoding.
|
23
|
+
def config
|
24
|
+
yield self
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module SolanaRpcRuby
|
4
|
+
##
|
5
|
+
# ApiClient class serves as a client for solana JSON RPC API.
|
6
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api
|
7
|
+
class ApiClient
|
8
|
+
# Determines which cluster will be used to send requests.
|
9
|
+
# @return [String]
|
10
|
+
attr_accessor :cluster
|
11
|
+
|
12
|
+
# Default headers.
|
13
|
+
# @return [Hash]
|
14
|
+
attr_accessor :default_headers
|
15
|
+
|
16
|
+
# Initialize object with cluster address where requests will be sent.
|
17
|
+
#
|
18
|
+
# @param cluster [String]
|
19
|
+
def initialize(cluster = nil)
|
20
|
+
@cluster = cluster || SolanaRpcRuby.cluster
|
21
|
+
|
22
|
+
message = 'Cluster is missing. Please provide default cluster in config or pass it to the client directly.'
|
23
|
+
raise ArgumentError, message unless @cluster
|
24
|
+
end
|
25
|
+
|
26
|
+
# Sends request to the api.
|
27
|
+
#
|
28
|
+
# @param body [Hash]
|
29
|
+
# @param http_method [Symbol]
|
30
|
+
# @param params [Hash]
|
31
|
+
#
|
32
|
+
# @return [Object] Net::HTTPOK
|
33
|
+
def call_api(body:, http_method:, params: {})
|
34
|
+
uri = URI(@cluster)
|
35
|
+
rpc_response = Net::HTTP.public_send(
|
36
|
+
http_method,
|
37
|
+
uri,
|
38
|
+
body,
|
39
|
+
default_headers,
|
40
|
+
)
|
41
|
+
|
42
|
+
rpc_response
|
43
|
+
|
44
|
+
rescue Timeout::Error,
|
45
|
+
Net::HTTPError,
|
46
|
+
Net::HTTPNotFound,
|
47
|
+
Net::HTTPServerException,
|
48
|
+
Net::HTTPFatalError,
|
49
|
+
Net::ReadTimeout => e
|
50
|
+
|
51
|
+
fail ApiError.new(message: e.message)
|
52
|
+
rescue StandardError => e
|
53
|
+
message = "#{e.class} #{e.message}\n Backtrace: \n #{e.backtrace}"
|
54
|
+
fail ApiError.new(message: message)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def default_headers
|
60
|
+
{ "Content-Type" => "application/json" }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module SolanaRpcRuby
|
2
|
+
##
|
3
|
+
# ApiError is a wrapper class for errors
|
4
|
+
#
|
5
|
+
class ApiError < StandardError
|
6
|
+
# Error code.
|
7
|
+
# @return [Integer]
|
8
|
+
attr_reader :code
|
9
|
+
|
10
|
+
# Error message.
|
11
|
+
# @return [String]
|
12
|
+
attr_reader :message
|
13
|
+
|
14
|
+
# Initialize object with json response from the API with error.
|
15
|
+
#
|
16
|
+
# @param code [Integer]
|
17
|
+
# @param message [String]
|
18
|
+
#
|
19
|
+
# @return [SolanaRpcRuby::ApiError]
|
20
|
+
def initialize(code: nil, message:)
|
21
|
+
@code = code
|
22
|
+
@message = message
|
23
|
+
|
24
|
+
super message
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module SolanaRpcRuby
|
2
|
+
# Namespace for helper methods.
|
3
|
+
module HelperMethods
|
4
|
+
# Checks if the object is nil or empty.
|
5
|
+
#
|
6
|
+
# @param object [String, Array, Hash]
|
7
|
+
#
|
8
|
+
# @return [Boolean]
|
9
|
+
def blank?(object)
|
10
|
+
raise ArgumentError, 'Object must be a String, Array or Hash or nil class.'\
|
11
|
+
unless object.is_a?(String) || object.is_a?(Array) || object.is_a?(Hash) || object.nil?
|
12
|
+
|
13
|
+
object.nil? || object.empty?
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,1316 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'pry'
|
3
|
+
require_relative 'request_body'
|
4
|
+
require_relative 'helper_methods'
|
5
|
+
|
6
|
+
module SolanaRpcRuby
|
7
|
+
##
|
8
|
+
# MethodsWrapper class serves as a wrapper for solana JSON RPC API methods.
|
9
|
+
# All informations about params:
|
10
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#json-rpc-api-reference
|
11
|
+
class MethodsWrapper
|
12
|
+
include RequestBody
|
13
|
+
include HelperMethods
|
14
|
+
|
15
|
+
# Determines which cluster will be used to send requests.
|
16
|
+
# @return [SolanaRpcRuby::ApiClient]
|
17
|
+
attr_accessor :api_client
|
18
|
+
|
19
|
+
# Cluster where requests will be sent.
|
20
|
+
# @return [String]
|
21
|
+
attr_accessor :cluster
|
22
|
+
|
23
|
+
# Initialize object with cluster address where requests will be sent.
|
24
|
+
#
|
25
|
+
# @param api_client [ApiClient]
|
26
|
+
# @param cluster [String] cluster where requests will be sent.
|
27
|
+
def initialize(api_client: ApiClient, cluster: SolanaRpcRuby.cluster)
|
28
|
+
@api_client = api_client.new(cluster)
|
29
|
+
end
|
30
|
+
|
31
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getaccountinfo
|
32
|
+
# Returns all information associated with the account of provided Pubkey
|
33
|
+
#
|
34
|
+
# @param account_pubkey [String]
|
35
|
+
# @param encoding [String]
|
36
|
+
# @param data_slice [Hash]
|
37
|
+
# @option data_slice [Integer] :offset
|
38
|
+
# @option data_slice [Integer] :length
|
39
|
+
#
|
40
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
41
|
+
def get_account_info(account_pubkey, encoding: '', data_slice: {})
|
42
|
+
http_method = :post
|
43
|
+
method = create_method_name(__method__)
|
44
|
+
|
45
|
+
params = []
|
46
|
+
params_hash = {}
|
47
|
+
|
48
|
+
params_hash['encoding'] = encoding unless blank?(encoding)
|
49
|
+
params_hash['dataSlice'] = data_slice unless data_slice.empty?
|
50
|
+
|
51
|
+
params << account_pubkey
|
52
|
+
params << params_hash unless params_hash.empty?
|
53
|
+
|
54
|
+
body = create_json_body(method, method_params: params)
|
55
|
+
|
56
|
+
send_request(body, http_method)
|
57
|
+
end
|
58
|
+
|
59
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getbalance
|
60
|
+
# Returns the balance of the account of provided Pubkey
|
61
|
+
#
|
62
|
+
# @param account_pubkey [String]
|
63
|
+
# @param commitment [String]
|
64
|
+
#
|
65
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
66
|
+
def get_balance(account_pubkey, commitment: nil)
|
67
|
+
http_method = :post
|
68
|
+
method = create_method_name(__method__)
|
69
|
+
|
70
|
+
params = []
|
71
|
+
|
72
|
+
params_hash = {}
|
73
|
+
|
74
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
75
|
+
|
76
|
+
params << account_pubkey
|
77
|
+
params << params_hash unless params_hash.empty?
|
78
|
+
|
79
|
+
body = create_json_body(method, method_params: params)
|
80
|
+
|
81
|
+
send_request(body, http_method)
|
82
|
+
end
|
83
|
+
|
84
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getblock
|
85
|
+
# NEW: This method is only available in solana-core v1.7 or newer. Please use getConfirmedBlock for solana-core v1.6
|
86
|
+
# Returns identity and transaction information about a confirmed block in the ledger
|
87
|
+
#
|
88
|
+
# @param slot [Integer]
|
89
|
+
# @param encoding [String]
|
90
|
+
# @param transaction_details [String]
|
91
|
+
# @param rewards [Boolean]
|
92
|
+
# @param commitment [String]
|
93
|
+
#
|
94
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
95
|
+
def get_block(slot, encoding: '', transaction_details: '', rewards: true, commitment: nil)
|
96
|
+
http_method = :post
|
97
|
+
method = create_method_name(__method__)
|
98
|
+
|
99
|
+
params = []
|
100
|
+
|
101
|
+
params_hash = {}
|
102
|
+
params_hash['encoding'] = encoding unless blank?(encoding)
|
103
|
+
params_hash['transactionDetails'] = transaction_details unless blank?(transaction_details)
|
104
|
+
params_hash['rewards'] = rewards unless rewards.nil?
|
105
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
106
|
+
|
107
|
+
params << slot
|
108
|
+
params << params_hash unless params_hash.empty?
|
109
|
+
|
110
|
+
body = create_json_body(method, method_params: params)
|
111
|
+
|
112
|
+
send_request(body, http_method)
|
113
|
+
end
|
114
|
+
|
115
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getblockheight
|
116
|
+
# Returns the current block height of the node
|
117
|
+
#
|
118
|
+
# @param commitment [String]
|
119
|
+
#
|
120
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
121
|
+
def get_block_height(commitment: nil)
|
122
|
+
http_method = :post
|
123
|
+
method = create_method_name(__method__)
|
124
|
+
|
125
|
+
params = []
|
126
|
+
params_hash = {}
|
127
|
+
|
128
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
129
|
+
params << params_hash unless params_hash.empty?
|
130
|
+
|
131
|
+
body = create_json_body(method, method_params: params)
|
132
|
+
|
133
|
+
send_request(body, http_method)
|
134
|
+
end
|
135
|
+
|
136
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getblockproduction
|
137
|
+
# Returns recent block production information from the current or previous epoch.
|
138
|
+
#
|
139
|
+
# @param identity [String]
|
140
|
+
# @param range [Hash]
|
141
|
+
# @option range [Integer] first_slot (required for range)
|
142
|
+
# @option range [Integer] last_slot (optional for range)
|
143
|
+
# @param commitment [String]
|
144
|
+
#
|
145
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
146
|
+
def get_block_production(identity: nil, range: {}, commitment: nil)
|
147
|
+
http_method = :post
|
148
|
+
method = create_method_name(__method__)
|
149
|
+
|
150
|
+
params = []
|
151
|
+
params_hash = {}
|
152
|
+
range_hash = {}
|
153
|
+
|
154
|
+
range_hash['firstSlot'] = range[:first_slot] unless !range.key?(:first_slot)
|
155
|
+
range_hash['lastSlot'] = range[:last_slot] unless !range.key?(:last_slot)
|
156
|
+
|
157
|
+
params_hash['identity'] = identity unless blank?(identity)
|
158
|
+
params_hash['range'] = range_hash unless range_hash.empty?
|
159
|
+
|
160
|
+
params << params_hash unless params_hash.empty?
|
161
|
+
|
162
|
+
body = create_json_body(method, method_params: params)
|
163
|
+
|
164
|
+
send_request(body, http_method)
|
165
|
+
end
|
166
|
+
|
167
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getblockcommitment
|
168
|
+
# Returns commitment for particular block
|
169
|
+
#
|
170
|
+
# @param block [Integer]
|
171
|
+
#
|
172
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
173
|
+
def get_block_commitment(block)
|
174
|
+
http_method = :post
|
175
|
+
method = create_method_name(__method__)
|
176
|
+
|
177
|
+
params = []
|
178
|
+
|
179
|
+
params << block
|
180
|
+
|
181
|
+
body = create_json_body(method, method_params: params)
|
182
|
+
|
183
|
+
send_request(body, http_method)
|
184
|
+
end
|
185
|
+
|
186
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getblocks
|
187
|
+
# NEW: This method is only available in solana-core v1.7 or newer. Please use getConfirmedBlocks for solana-core v1.6
|
188
|
+
# Returns a list of confirmed blocks between two slots
|
189
|
+
#
|
190
|
+
# @param start_slot [Integer]
|
191
|
+
# @param end_slot [Integer]
|
192
|
+
#
|
193
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
194
|
+
def get_blocks(start_slot, end_slot: nil)
|
195
|
+
http_method = :post
|
196
|
+
method = create_method_name(__method__)
|
197
|
+
|
198
|
+
params = []
|
199
|
+
|
200
|
+
params << start_slot
|
201
|
+
params << end_slot unless end_slot.nil?
|
202
|
+
|
203
|
+
body = create_json_body(method, method_params: params)
|
204
|
+
|
205
|
+
send_request(body, http_method)
|
206
|
+
end
|
207
|
+
|
208
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getblockswithlimit
|
209
|
+
# NEW: This method is only available in solana-core v1.7 or newer. Please use getConfirmedBlocks for solana-core v1.6
|
210
|
+
# Returns a list of confirmed blocks starting at the given slot
|
211
|
+
#
|
212
|
+
# @param start_slot [Integer]
|
213
|
+
# @param limit [Integer]
|
214
|
+
# @param commitment [String]
|
215
|
+
#
|
216
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
217
|
+
def get_blocks_with_limit(start_slot, limit, commitment: nil)
|
218
|
+
http_method = :post
|
219
|
+
method = create_method_name(__method__)
|
220
|
+
|
221
|
+
params = []
|
222
|
+
params_hash = {}
|
223
|
+
|
224
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
225
|
+
|
226
|
+
params << start_slot
|
227
|
+
params << limit
|
228
|
+
params << params_hash unless params_hash.empty?
|
229
|
+
|
230
|
+
body = create_json_body(method, method_params: params)
|
231
|
+
|
232
|
+
send_request(body, http_method)
|
233
|
+
end
|
234
|
+
|
235
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getblocktime
|
236
|
+
# Returns the estimated production time of a block.
|
237
|
+
#
|
238
|
+
# @param block [Integer]
|
239
|
+
#
|
240
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
241
|
+
def get_block_time(block)
|
242
|
+
http_method = :post
|
243
|
+
method = create_method_name(__method__)
|
244
|
+
|
245
|
+
params = []
|
246
|
+
|
247
|
+
params << block
|
248
|
+
|
249
|
+
body = create_json_body(method, method_params: params)
|
250
|
+
|
251
|
+
send_request(body, http_method)
|
252
|
+
end
|
253
|
+
|
254
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getclusternodes
|
255
|
+
# Returns information about all the nodes participating in the cluster
|
256
|
+
#
|
257
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
258
|
+
def get_cluster_nodes
|
259
|
+
http_method = :post
|
260
|
+
method = create_method_name(__method__)
|
261
|
+
|
262
|
+
body = create_json_body(method)
|
263
|
+
|
264
|
+
send_request(body, http_method)
|
265
|
+
end
|
266
|
+
|
267
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getepochinfo
|
268
|
+
# DEPRECATED: Please use getBlocks instead This method is expected to be removed in solana-core v1.8
|
269
|
+
# Returns a list of confirmed blocks between two slots
|
270
|
+
#
|
271
|
+
# @param start_slot [Integer]
|
272
|
+
# @param end_slot [Integer]
|
273
|
+
#
|
274
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
275
|
+
def get_confirmed_blocks(start_slot, end_slot: nil)
|
276
|
+
http_method = :post
|
277
|
+
method = create_method_name(__method__)
|
278
|
+
|
279
|
+
params = []
|
280
|
+
|
281
|
+
params << start_slot
|
282
|
+
params << end_slot unless end_slot.nil? # optional
|
283
|
+
|
284
|
+
body = create_json_body(method, method_params: params)
|
285
|
+
|
286
|
+
send_request(body, http_method)
|
287
|
+
end
|
288
|
+
|
289
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getepochinfo
|
290
|
+
# Returns information about the current epoch
|
291
|
+
#
|
292
|
+
# @param commitment [String]
|
293
|
+
#
|
294
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
295
|
+
def get_epoch_info(commitment: nil)
|
296
|
+
http_method = :post
|
297
|
+
method = create_method_name(__method__)
|
298
|
+
|
299
|
+
params = []
|
300
|
+
params_hash = {}
|
301
|
+
|
302
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
303
|
+
|
304
|
+
params << params_hash unless params_hash.empty?
|
305
|
+
|
306
|
+
body = create_json_body(method, method_params: params)
|
307
|
+
|
308
|
+
send_request(body, http_method)
|
309
|
+
end
|
310
|
+
|
311
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getepochschedule
|
312
|
+
# Returns epoch schedule information from this cluster's genesis config
|
313
|
+
#
|
314
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
315
|
+
def get_epoch_schedule
|
316
|
+
http_method = :post
|
317
|
+
method = create_method_name(__method__)
|
318
|
+
|
319
|
+
body = create_json_body(method)
|
320
|
+
|
321
|
+
send_request(body, http_method)
|
322
|
+
end
|
323
|
+
|
324
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getfeecalculatorforblockhash
|
325
|
+
# Returns the fee calculator associated with the query blockhash, or null if the blockhash has expired
|
326
|
+
#
|
327
|
+
# @param query_blockhash [String]
|
328
|
+
# @param commitment [String]
|
329
|
+
#
|
330
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
331
|
+
def get_fee_calculator_for_blockhash(query_blockhash, commitment: nil)
|
332
|
+
http_method = :post
|
333
|
+
method = create_method_name(__method__)
|
334
|
+
|
335
|
+
params = []
|
336
|
+
params_hash = {}
|
337
|
+
|
338
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
339
|
+
|
340
|
+
params << query_blockhash
|
341
|
+
params << params_hash unless params_hash.empty?
|
342
|
+
|
343
|
+
body = create_json_body(method, method_params: params)
|
344
|
+
|
345
|
+
send_request(body, http_method)
|
346
|
+
end
|
347
|
+
|
348
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getfeerategovernor
|
349
|
+
# Returns the fee rate governor information from the root bank
|
350
|
+
#
|
351
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
352
|
+
def get_fee_rate_governor
|
353
|
+
http_method = :post
|
354
|
+
method = create_method_name(__method__)
|
355
|
+
|
356
|
+
body = create_json_body(method)
|
357
|
+
|
358
|
+
send_request(body, http_method)
|
359
|
+
end
|
360
|
+
|
361
|
+
# @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
|
363
|
+
# the cost of submitting a transaction using it, and the last slot in which the blockhash will be valid.
|
364
|
+
#
|
365
|
+
# @param commitment [String]
|
366
|
+
#
|
367
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
368
|
+
def get_fees(commitment: nil)
|
369
|
+
http_method = :post
|
370
|
+
method = create_method_name(__method__)
|
371
|
+
|
372
|
+
params = []
|
373
|
+
params_hash = {}
|
374
|
+
|
375
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
376
|
+
params << params_hash unless params_hash.empty?
|
377
|
+
|
378
|
+
body = create_json_body(method, method_params: params)
|
379
|
+
|
380
|
+
send_request(body, http_method)
|
381
|
+
end
|
382
|
+
|
383
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getfirstavailableblock
|
384
|
+
# Returns the slot of the lowest confirmed block that has not been purged from the ledger
|
385
|
+
#
|
386
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
387
|
+
def get_first_available_block
|
388
|
+
http_method = :post
|
389
|
+
method = create_method_name(__method__)
|
390
|
+
|
391
|
+
body = create_json_body(method)
|
392
|
+
|
393
|
+
send_request(body, http_method)
|
394
|
+
end
|
395
|
+
|
396
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getgenesishash
|
397
|
+
# Returns the genesis hash.
|
398
|
+
#
|
399
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
400
|
+
def get_genesis_hash
|
401
|
+
http_method = :post
|
402
|
+
method = create_method_name(__method__)
|
403
|
+
|
404
|
+
body = create_json_body(method)
|
405
|
+
|
406
|
+
send_request(body, http_method)
|
407
|
+
end
|
408
|
+
|
409
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#gethealth
|
410
|
+
# Returns the current health of the node.
|
411
|
+
#
|
412
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
413
|
+
def get_health
|
414
|
+
http_method = :post
|
415
|
+
method = create_method_name(__method__)
|
416
|
+
|
417
|
+
body = create_json_body(method)
|
418
|
+
|
419
|
+
send_request(body, http_method)
|
420
|
+
end
|
421
|
+
|
422
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getidentity
|
423
|
+
# Returns the identity pubkey for the current node.
|
424
|
+
#
|
425
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
426
|
+
def get_identity
|
427
|
+
http_method = :post
|
428
|
+
method = create_method_name(__method__)
|
429
|
+
|
430
|
+
body = create_json_body(method)
|
431
|
+
|
432
|
+
send_request(body, http_method)
|
433
|
+
end
|
434
|
+
|
435
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getinflationgovernor
|
436
|
+
# Returns the current inflation governor.
|
437
|
+
#
|
438
|
+
# @param commitment [String]
|
439
|
+
#
|
440
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
441
|
+
def get_inflation_governor(commitment: nil)
|
442
|
+
http_method = :post
|
443
|
+
method = create_method_name(__method__)
|
444
|
+
|
445
|
+
params = []
|
446
|
+
params_hash = {}
|
447
|
+
|
448
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
449
|
+
|
450
|
+
params << params_hash unless params_hash.empty?
|
451
|
+
|
452
|
+
body = create_json_body(method, method_params: params)
|
453
|
+
|
454
|
+
send_request(body, http_method)
|
455
|
+
end
|
456
|
+
|
457
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getinflationrate
|
458
|
+
# Returns the specific inflation values for the current epoch.
|
459
|
+
#
|
460
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
461
|
+
def get_inflation_rate
|
462
|
+
http_method = :post
|
463
|
+
method = create_method_name(__method__)
|
464
|
+
|
465
|
+
body = create_json_body(method)
|
466
|
+
|
467
|
+
send_request(body, http_method)
|
468
|
+
end
|
469
|
+
|
470
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getinflationreward
|
471
|
+
# Returns the inflation reward for a list of addresses for an epoch.
|
472
|
+
#
|
473
|
+
# @param addresses [Array]
|
474
|
+
# @param commitment [String]
|
475
|
+
# @param epoch [Integer]
|
476
|
+
#
|
477
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
478
|
+
def get_inflation_reward(addresses, commitment: nil, epoch: nil)
|
479
|
+
http_method = :post
|
480
|
+
method = create_method_name(__method__)
|
481
|
+
|
482
|
+
params = []
|
483
|
+
params_hash = {}
|
484
|
+
|
485
|
+
params << addresses
|
486
|
+
|
487
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
488
|
+
params_hash['epoch'] = epoch unless epoch.nil?
|
489
|
+
|
490
|
+
params << params_hash unless params_hash.empty?
|
491
|
+
|
492
|
+
body = create_json_body(method, method_params: params)
|
493
|
+
|
494
|
+
send_request(body, http_method)
|
495
|
+
end
|
496
|
+
|
497
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getlargestaccounts
|
498
|
+
# Returns the 20 largest accounts, by lamport balance (results may be cached up to two hours)
|
499
|
+
#
|
500
|
+
# @param commitment [String]
|
501
|
+
# @param filter [String]
|
502
|
+
#
|
503
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
504
|
+
def get_largest_accounts(commitment: nil, filter: '')
|
505
|
+
http_method = :post
|
506
|
+
method = create_method_name(__method__)
|
507
|
+
|
508
|
+
params = []
|
509
|
+
params_hash = {}
|
510
|
+
|
511
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
512
|
+
params_hash['filter'] = filter unless filter.empty?
|
513
|
+
|
514
|
+
params << params_hash unless params_hash.empty?
|
515
|
+
|
516
|
+
body = create_json_body(method, method_params: params)
|
517
|
+
|
518
|
+
send_request(body, http_method)
|
519
|
+
end
|
520
|
+
|
521
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getleaderschedule
|
522
|
+
# Returns the leader schedule for an epoch.
|
523
|
+
#
|
524
|
+
# @param epoch [Integer]
|
525
|
+
# @param commitment [String]
|
526
|
+
# @param identity [String]
|
527
|
+
#
|
528
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
529
|
+
def get_leader_schedule(epoch: nil, commitment: nil, identity: '')
|
530
|
+
http_method = :post
|
531
|
+
method = create_method_name(__method__)
|
532
|
+
|
533
|
+
params = []
|
534
|
+
params_hash = {}
|
535
|
+
|
536
|
+
params_hash['epoch'] = epoch unless epoch.nil?
|
537
|
+
params_hash['identity'] = identity unless identity.empty?
|
538
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
539
|
+
|
540
|
+
params << params_hash unless params_hash.empty?
|
541
|
+
|
542
|
+
body = create_json_body(method, method_params: params)
|
543
|
+
|
544
|
+
send_request(body, http_method)
|
545
|
+
end
|
546
|
+
|
547
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getmaxretransmitslot
|
548
|
+
# Get the max slot seen from retransmit stage.
|
549
|
+
#
|
550
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
551
|
+
def get_max_retransmit_slot
|
552
|
+
http_method = :post
|
553
|
+
method = create_method_name(__method__)
|
554
|
+
|
555
|
+
body = create_json_body(method)
|
556
|
+
|
557
|
+
send_request(body, http_method)
|
558
|
+
end
|
559
|
+
|
560
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getmaxshredinsertslot
|
561
|
+
# Get the max slot seen from after shred insert.
|
562
|
+
#
|
563
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
564
|
+
def get_max_shred_insert_slot
|
565
|
+
http_method = :post
|
566
|
+
method = create_method_name(__method__)
|
567
|
+
|
568
|
+
body = create_json_body(method)
|
569
|
+
|
570
|
+
send_request(body, http_method)
|
571
|
+
end
|
572
|
+
|
573
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getminimumbalanceforrentexemption
|
574
|
+
# Returns minimum balance required to make account rent exempt.
|
575
|
+
#
|
576
|
+
# @param account_data_length [String]
|
577
|
+
# @param commitment [String]
|
578
|
+
#
|
579
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
580
|
+
def get_minimum_balance_for_rent_exemption(
|
581
|
+
account_data_length,
|
582
|
+
commitment: nil
|
583
|
+
)
|
584
|
+
http_method = :post
|
585
|
+
method = create_method_name(__method__)
|
586
|
+
|
587
|
+
params = []
|
588
|
+
params_hash = {}
|
589
|
+
|
590
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
591
|
+
|
592
|
+
params << account_data_length
|
593
|
+
params << params_hash unless params_hash.empty?
|
594
|
+
|
595
|
+
body = create_json_body(method, method_params: params)
|
596
|
+
|
597
|
+
send_request(body, http_method)
|
598
|
+
end
|
599
|
+
|
600
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getmultipleaccounts
|
601
|
+
# Returns the account information for a list of Pubkeys.
|
602
|
+
# @param account_data_length [String]
|
603
|
+
# @param commitment [String]
|
604
|
+
#
|
605
|
+
# @return [Response, ApiError] Response when success, ApiError on failure. # @param account_data_length [String]
|
606
|
+
# @param commitment [String]
|
607
|
+
#
|
608
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
609
|
+
def get_multiple_accounts(
|
610
|
+
pubkeys,
|
611
|
+
commitment: nil,
|
612
|
+
encoding: '',
|
613
|
+
data_slice: {}
|
614
|
+
)
|
615
|
+
http_method = :post
|
616
|
+
method = create_method_name(__method__)
|
617
|
+
|
618
|
+
params = []
|
619
|
+
params_hash = {}
|
620
|
+
|
621
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
622
|
+
params_hash['encoding'] = encoding unless blank?(encoding)
|
623
|
+
params_hash['dataSlice'] = data_slice unless data_slice.empty?
|
624
|
+
|
625
|
+
params << pubkeys
|
626
|
+
params << params_hash unless params_hash.empty?
|
627
|
+
|
628
|
+
body = create_json_body(method, method_params: params)
|
629
|
+
|
630
|
+
send_request(body, http_method)
|
631
|
+
end
|
632
|
+
|
633
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getprogramaccounts
|
634
|
+
# Returns all accounts owned by the provided program Pubkey
|
635
|
+
#
|
636
|
+
# @param pubkey [String]
|
637
|
+
# @param commitment [String]
|
638
|
+
# @param encoding [String]
|
639
|
+
# @param data_slice [Hash]
|
640
|
+
# @option data_slice [Integer] :offset
|
641
|
+
# @option data_slice [Integer] :length
|
642
|
+
# @param filters [Array<Hash, Hash>]
|
643
|
+
# @param with_context [Boolean]
|
644
|
+
#
|
645
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
646
|
+
def get_program_accounts(
|
647
|
+
pubkey,
|
648
|
+
commitment: nil,
|
649
|
+
encoding: '',
|
650
|
+
data_slice: {},
|
651
|
+
filters: [],
|
652
|
+
with_context: false
|
653
|
+
)
|
654
|
+
http_method = :post
|
655
|
+
method = create_method_name(__method__)
|
656
|
+
|
657
|
+
params = []
|
658
|
+
params_hash = {}
|
659
|
+
|
660
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
661
|
+
params_hash['encoding'] = encoding unless blank?(encoding)
|
662
|
+
params_hash['dataSlice'] = data_slice unless data_slice.empty?
|
663
|
+
params_hash['filters'] = filters unless filters.empty?
|
664
|
+
params_hash['withContext'] = with_context
|
665
|
+
|
666
|
+
params << pubkey
|
667
|
+
params << params_hash unless params_hash.empty?
|
668
|
+
|
669
|
+
body = create_json_body(method, method_params: params)
|
670
|
+
|
671
|
+
send_request(body, http_method)
|
672
|
+
end
|
673
|
+
|
674
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getrecentblockhash
|
675
|
+
# Returns a recent block hash from the ledger, and a fee schedule
|
676
|
+
# that can be used to compute the cost of submitting a transaction using it.
|
677
|
+
#
|
678
|
+
# @param commitment [String]
|
679
|
+
#
|
680
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
681
|
+
def get_recent_blockhash(commitment: nil)
|
682
|
+
http_method = :post
|
683
|
+
method = create_method_name(__method__)
|
684
|
+
|
685
|
+
params = []
|
686
|
+
params_hash = {}
|
687
|
+
|
688
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
689
|
+
|
690
|
+
params << params_hash unless params_hash.empty?
|
691
|
+
|
692
|
+
body = create_json_body(method, method_params: params)
|
693
|
+
|
694
|
+
send_request(body, http_method)
|
695
|
+
end
|
696
|
+
|
697
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getrecentperformancesamples
|
698
|
+
# Returns a list of recent performance samples, in reverse slot order.
|
699
|
+
# Performance samples are taken every 60 seconds and include the number of transactions and slots that occur in a given time window.
|
700
|
+
#
|
701
|
+
# @param limit [Integer]
|
702
|
+
#
|
703
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
704
|
+
def get_recent_performance_samples(limit: nil)
|
705
|
+
http_method = :post
|
706
|
+
method = create_method_name(__method__)
|
707
|
+
|
708
|
+
params = []
|
709
|
+
|
710
|
+
params << limit unless limit.nil?
|
711
|
+
|
712
|
+
body = create_json_body(method, method_params: params)
|
713
|
+
|
714
|
+
send_request(body, http_method)
|
715
|
+
end
|
716
|
+
|
717
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getsnapshotslot
|
718
|
+
# Returns the highest slot that the node has a snapshot for.
|
719
|
+
#
|
720
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
721
|
+
def get_snapshot_slot
|
722
|
+
http_method = :post
|
723
|
+
method = create_method_name(__method__)
|
724
|
+
|
725
|
+
body = create_json_body(method)
|
726
|
+
|
727
|
+
send_request(body, http_method)
|
728
|
+
end
|
729
|
+
|
730
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getsignaturesforaddress
|
731
|
+
# NEW: This method is only available in solana-core v1.7 or newer.
|
732
|
+
# Please use getConfirmedSignaturesForAddress2 for solana-core v1.6
|
733
|
+
#
|
734
|
+
# Returns confirmed signatures for transactions involving an address backwards
|
735
|
+
# in time from the provided signature or most recent confirmed block
|
736
|
+
#
|
737
|
+
# @param account_address [String]
|
738
|
+
# @param limit [Integer]
|
739
|
+
# @param before [String]
|
740
|
+
# @param until_ [String]
|
741
|
+
# @param commitment [String]
|
742
|
+
#
|
743
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
744
|
+
def get_signatures_for_address(
|
745
|
+
account_address,
|
746
|
+
limit: nil,
|
747
|
+
before: '',
|
748
|
+
until_: '',
|
749
|
+
commitment: nil
|
750
|
+
)
|
751
|
+
http_method = :post
|
752
|
+
method = create_method_name(__method__)
|
753
|
+
|
754
|
+
params = []
|
755
|
+
params_hash = {}
|
756
|
+
|
757
|
+
params_hash['limit'] = limit unless limit.nil?
|
758
|
+
params_hash['before'] = before unless before.empty?
|
759
|
+
params_hash['until'] = until_ unless until_.empty?
|
760
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
761
|
+
|
762
|
+
params << account_address
|
763
|
+
params << params_hash unless params_hash.empty?
|
764
|
+
|
765
|
+
body = create_json_body(method, method_params: params)
|
766
|
+
|
767
|
+
send_request(body, http_method)
|
768
|
+
end
|
769
|
+
|
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,
|
775
|
+
# which retains statuses for all active slots plus MAX_RECENT_BLOCKHASHES rooted slots.
|
776
|
+
#
|
777
|
+
# @param transaction_signatures [Array]
|
778
|
+
# @param search_transaction_history [Boolean]
|
779
|
+
#
|
780
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
781
|
+
def get_signature_statuses(
|
782
|
+
transaction_signatures,
|
783
|
+
search_transaction_history: false
|
784
|
+
)
|
785
|
+
http_method = :post
|
786
|
+
method = create_method_name(__method__)
|
787
|
+
|
788
|
+
params = []
|
789
|
+
params_hash = {}
|
790
|
+
|
791
|
+
params_hash['searchTransactionHistory'] = search_transaction_history unless search_transaction_history.nil?
|
792
|
+
|
793
|
+
params << transaction_signatures
|
794
|
+
params << params_hash unless params_hash.empty?
|
795
|
+
|
796
|
+
body = create_json_body(method, method_params: params)
|
797
|
+
|
798
|
+
send_request(body, http_method)
|
799
|
+
end
|
800
|
+
|
801
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getslot
|
802
|
+
# Returns the current slot the node is processing.
|
803
|
+
#
|
804
|
+
# @param commitment [String]
|
805
|
+
#
|
806
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
807
|
+
def get_slot(commitment: nil)
|
808
|
+
http_method = :post
|
809
|
+
method = create_method_name(__method__)
|
810
|
+
|
811
|
+
params = []
|
812
|
+
params_hash = {}
|
813
|
+
|
814
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
815
|
+
|
816
|
+
params << params_hash unless params_hash.empty?
|
817
|
+
|
818
|
+
body = create_json_body(method, method_params: params)
|
819
|
+
|
820
|
+
send_request(body, http_method)
|
821
|
+
end
|
822
|
+
|
823
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getslotleader
|
824
|
+
# Returns the current slot leader
|
825
|
+
#
|
826
|
+
# @param commitment [String]
|
827
|
+
#
|
828
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
829
|
+
def get_slot_leader(commitment: nil)
|
830
|
+
http_method = :post
|
831
|
+
method = create_method_name(__method__)
|
832
|
+
|
833
|
+
params = []
|
834
|
+
params_hash = {}
|
835
|
+
|
836
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
837
|
+
|
838
|
+
params << params_hash unless params_hash.empty?
|
839
|
+
|
840
|
+
body = create_json_body(method, method_params: params)
|
841
|
+
|
842
|
+
send_request(body, http_method)
|
843
|
+
end
|
844
|
+
|
845
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getslotleaders
|
846
|
+
# Returns the slot leaders for a given slot range.
|
847
|
+
#
|
848
|
+
# @param start_slot [Integer]
|
849
|
+
# @param limit [Integer]
|
850
|
+
#
|
851
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
852
|
+
def get_slot_leaders(start_slot, limit)
|
853
|
+
http_method = :post
|
854
|
+
method = create_method_name(__method__)
|
855
|
+
|
856
|
+
params = [start_slot, limit]
|
857
|
+
|
858
|
+
body = create_json_body(method, method_params: params)
|
859
|
+
|
860
|
+
send_request(body, http_method)
|
861
|
+
end
|
862
|
+
|
863
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getstakeactivation
|
864
|
+
# Returns epoch activation information for a stake account.
|
865
|
+
#
|
866
|
+
# @param pubkey [String]
|
867
|
+
# @param commitment [String]
|
868
|
+
# @param epoch [Integer]
|
869
|
+
#
|
870
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
871
|
+
def get_stake_activation(pubkey, commitment: nil, epoch: nil)
|
872
|
+
http_method = :post
|
873
|
+
method = create_method_name(__method__)
|
874
|
+
|
875
|
+
params = []
|
876
|
+
params_hash = {}
|
877
|
+
|
878
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
879
|
+
params_hash['epoch'] = epoch unless epoch.nil?
|
880
|
+
|
881
|
+
params << pubkey
|
882
|
+
params << params_hash unless params_hash.empty?
|
883
|
+
|
884
|
+
body = create_json_body(method, method_params: params)
|
885
|
+
|
886
|
+
send_request(body, http_method)
|
887
|
+
end
|
888
|
+
|
889
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getsupply
|
890
|
+
# Returns information about the current supply.
|
891
|
+
#
|
892
|
+
# @param commitment [String]
|
893
|
+
#
|
894
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
895
|
+
def get_supply(commitment: nil)
|
896
|
+
http_method = :post
|
897
|
+
method = create_method_name(__method__)
|
898
|
+
|
899
|
+
params = []
|
900
|
+
params_hash = {}
|
901
|
+
|
902
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
903
|
+
|
904
|
+
params << params_hash unless params_hash.empty?
|
905
|
+
|
906
|
+
body = create_json_body(method, method_params: params)
|
907
|
+
|
908
|
+
send_request(body, http_method)
|
909
|
+
end
|
910
|
+
|
911
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#gettokenaccountbalance
|
912
|
+
#
|
913
|
+
# Returns the token balance of an SPL Token account.
|
914
|
+
#
|
915
|
+
# @param token_account_pubkey [String]
|
916
|
+
# @param commitment [String]
|
917
|
+
#
|
918
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
919
|
+
def get_token_account_balance(token_account_pubkey, commitment: nil)
|
920
|
+
http_method = :post
|
921
|
+
method = create_method_name(__method__)
|
922
|
+
|
923
|
+
params = []
|
924
|
+
params_hash = {}
|
925
|
+
|
926
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
927
|
+
|
928
|
+
params << token_account_pubkey
|
929
|
+
params << params_hash unless params_hash.empty?
|
930
|
+
|
931
|
+
body = create_json_body(method, method_params: params)
|
932
|
+
|
933
|
+
send_request(body, http_method)
|
934
|
+
end
|
935
|
+
|
936
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#gettokenaccountsbydelegate # Returns the token balance of an SPL Token account.
|
937
|
+
#
|
938
|
+
# Returns all SPL Token accounts by approved Delegate.
|
939
|
+
#
|
940
|
+
# IMPORTANT: According to docs there should be mint or program_id passed in, not both.
|
941
|
+
#
|
942
|
+
# @param token_account_pubkey [String]
|
943
|
+
# @param mint [String]
|
944
|
+
# @param program_id [String]
|
945
|
+
# @param commitment [String]
|
946
|
+
# @param encoding [String]
|
947
|
+
# @param data_slice [Hash]
|
948
|
+
# @option data_slice [Integer] :offset
|
949
|
+
# @option data_slice [Integer] :length
|
950
|
+
#
|
951
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
952
|
+
def get_token_accounts_by_delegate(
|
953
|
+
token_account_pubkey,
|
954
|
+
mint: '',
|
955
|
+
program_id: '',
|
956
|
+
commitment: nil,
|
957
|
+
encoding: '',
|
958
|
+
data_slice: {}
|
959
|
+
)
|
960
|
+
|
961
|
+
raise ArgumentError, 'You should pass mint or program_id, not both.' if !mint.empty? && !program_id.empty?
|
962
|
+
|
963
|
+
http_method = :post
|
964
|
+
method = create_method_name(__method__)
|
965
|
+
|
966
|
+
params = []
|
967
|
+
params_hash = {}
|
968
|
+
params_hash_2 = {}
|
969
|
+
|
970
|
+
params_hash['mint'] = mint unless mint.empty?
|
971
|
+
params_hash['programId'] = program_id unless program_id.empty?
|
972
|
+
|
973
|
+
params_hash_2['commitment'] = commitment unless blank?(commitment)
|
974
|
+
params_hash_2['encoding'] = encoding unless blank?(encoding)
|
975
|
+
params_hash_2['dataSlice'] = data_slice unless data_slice.empty?
|
976
|
+
|
977
|
+
params << token_account_pubkey
|
978
|
+
params << params_hash unless params_hash.empty?
|
979
|
+
params << params_hash_2 if params_hash_2.any?
|
980
|
+
|
981
|
+
body = create_json_body(method, method_params: params)
|
982
|
+
|
983
|
+
send_request(body, http_method)
|
984
|
+
end
|
985
|
+
|
986
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#gettokenaccountsbyowner #
|
987
|
+
#
|
988
|
+
# Returns all SPL Token accounts by token owner.
|
989
|
+
#
|
990
|
+
# IMPORTANT: According to docs there should be mint or program_id passed in, not both.
|
991
|
+
#
|
992
|
+
# @param token_account_pubkey [String]
|
993
|
+
# @param mint [String]
|
994
|
+
# @param program_id [String]
|
995
|
+
# @param commitment [String]
|
996
|
+
# @param encoding [String]
|
997
|
+
# @param data_slice [Hash]
|
998
|
+
# @option data_slice [Integer] :offset
|
999
|
+
# @option data_slice [Integer] :length
|
1000
|
+
#
|
1001
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
1002
|
+
def get_token_accounts_by_owner(
|
1003
|
+
token_account_pubkey,
|
1004
|
+
mint: '',
|
1005
|
+
program_id: '',
|
1006
|
+
commitment: nil,
|
1007
|
+
encoding: '',
|
1008
|
+
data_slice: {}
|
1009
|
+
)
|
1010
|
+
|
1011
|
+
raise ArgumentError, 'You should pass mint or program_id, not both.' if !mint.empty? && !program_id.empty?
|
1012
|
+
|
1013
|
+
http_method = :post
|
1014
|
+
method = create_method_name(__method__)
|
1015
|
+
|
1016
|
+
params = []
|
1017
|
+
params_hash = {}
|
1018
|
+
params_hash_2 = {}
|
1019
|
+
param_data_slice = {}
|
1020
|
+
|
1021
|
+
params_hash['mint'] = mint unless mint.empty?
|
1022
|
+
params_hash['programId'] = program_id unless program_id.empty?
|
1023
|
+
|
1024
|
+
params_hash_2['commitment'] = commitment unless blank?(commitment)
|
1025
|
+
params_hash_2['encoding'] = encoding unless blank?(encoding)
|
1026
|
+
params_hash_2['dataSlice'] = data_slice unless data_slice.empty?
|
1027
|
+
|
1028
|
+
params << token_account_pubkey
|
1029
|
+
params << params_hash unless params_hash.empty?
|
1030
|
+
params << params_hash_2 unless params_hash_2.empty?
|
1031
|
+
|
1032
|
+
body = create_json_body(method, method_params: params)
|
1033
|
+
|
1034
|
+
send_request(body, http_method)
|
1035
|
+
end
|
1036
|
+
|
1037
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#gettokenlargestaccounts #
|
1038
|
+
#
|
1039
|
+
# Returns the 20 largest accounts of a particular SPL Token type.
|
1040
|
+
#
|
1041
|
+
# @param token_mint_pubkey [String]
|
1042
|
+
# @param commitment [String]
|
1043
|
+
#
|
1044
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
1045
|
+
def get_token_largest_accounts(
|
1046
|
+
token_mint_pubkey,
|
1047
|
+
commitment: nil
|
1048
|
+
)
|
1049
|
+
|
1050
|
+
http_method = :post
|
1051
|
+
method = create_method_name(__method__)
|
1052
|
+
|
1053
|
+
params = []
|
1054
|
+
params_hash = {}
|
1055
|
+
|
1056
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
1057
|
+
|
1058
|
+
params << token_mint_pubkey
|
1059
|
+
params << params_hash unless params_hash.empty?
|
1060
|
+
|
1061
|
+
body = create_json_body(method, method_params: params)
|
1062
|
+
|
1063
|
+
send_request(body, http_method)
|
1064
|
+
end
|
1065
|
+
|
1066
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#gettransaction
|
1067
|
+
#
|
1068
|
+
# Returns transaction details for a confirmed transaction
|
1069
|
+
#
|
1070
|
+
# @param transaction_signature [String]
|
1071
|
+
# @param encoding [String]
|
1072
|
+
# @param commitment [String]
|
1073
|
+
#
|
1074
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
1075
|
+
def get_transaction(transaction_signature, encoding: '', commitment: nil)
|
1076
|
+
http_method = :post
|
1077
|
+
method = create_method_name(__method__)
|
1078
|
+
|
1079
|
+
params = []
|
1080
|
+
params_hash = {}
|
1081
|
+
|
1082
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
1083
|
+
params_hash['encoding'] = encoding unless blank?(encoding)
|
1084
|
+
|
1085
|
+
params << transaction_signature
|
1086
|
+
params << params_hash unless params_hash.empty?
|
1087
|
+
|
1088
|
+
body = create_json_body(method, method_params: params)
|
1089
|
+
|
1090
|
+
send_request(body, http_method)
|
1091
|
+
end
|
1092
|
+
|
1093
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#gettransactioncount
|
1094
|
+
#
|
1095
|
+
# Returns the current Transaction count from the ledger
|
1096
|
+
#
|
1097
|
+
# @param commitment [String]
|
1098
|
+
#
|
1099
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
1100
|
+
def get_transaction_count(commitment: nil)
|
1101
|
+
http_method = :post
|
1102
|
+
method = create_method_name(__method__)
|
1103
|
+
|
1104
|
+
params = []
|
1105
|
+
params_hash = {}
|
1106
|
+
|
1107
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
1108
|
+
|
1109
|
+
params << params_hash unless params_hash.empty?
|
1110
|
+
|
1111
|
+
body = create_json_body(method, method_params: params)
|
1112
|
+
|
1113
|
+
send_request(body, http_method)
|
1114
|
+
end
|
1115
|
+
|
1116
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getversion
|
1117
|
+
#
|
1118
|
+
# Returns the current solana versions running on the node.
|
1119
|
+
#
|
1120
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
1121
|
+
def get_version
|
1122
|
+
http_method = :post
|
1123
|
+
method = create_method_name(__method__)
|
1124
|
+
|
1125
|
+
body = create_json_body(method)
|
1126
|
+
|
1127
|
+
send_request(body, http_method)
|
1128
|
+
end
|
1129
|
+
|
1130
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#getvoteaccounts
|
1131
|
+
# Returns the account info and associated stake for all the voting accounts in the current bank.
|
1132
|
+
#
|
1133
|
+
# @param commitment [String]
|
1134
|
+
# @param vote_pubkey [String]
|
1135
|
+
#
|
1136
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
1137
|
+
def get_vote_accounts(commitment: nil, vote_pubkey: nil)
|
1138
|
+
http_method = :post
|
1139
|
+
method = create_method_name(__method__)
|
1140
|
+
|
1141
|
+
params = []
|
1142
|
+
params_hash = {}
|
1143
|
+
|
1144
|
+
params_hash['votePubkey'] = vote_pubkey unless blank?(vote_pubkey)
|
1145
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
1146
|
+
|
1147
|
+
params << params_hash unless params_hash.empty?
|
1148
|
+
|
1149
|
+
body = create_json_body(method, method_params: params)
|
1150
|
+
|
1151
|
+
send_request(body, http_method)
|
1152
|
+
end
|
1153
|
+
|
1154
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#minimumledgerslot
|
1155
|
+
#
|
1156
|
+
# Returns the current solana versions running on the node.
|
1157
|
+
#
|
1158
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
1159
|
+
def get_version
|
1160
|
+
http_method = :post
|
1161
|
+
method = create_method_name(__method__)
|
1162
|
+
|
1163
|
+
body = create_json_body(method)
|
1164
|
+
|
1165
|
+
send_request(body, http_method)
|
1166
|
+
end
|
1167
|
+
|
1168
|
+
# @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.
|
1171
|
+
# This value may increase over time if the node is configured to purge older ledger data
|
1172
|
+
#
|
1173
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
1174
|
+
def minimum_ledger_slot
|
1175
|
+
http_method = :post
|
1176
|
+
method = create_method_name(__method__)
|
1177
|
+
|
1178
|
+
body = create_json_body(method)
|
1179
|
+
|
1180
|
+
send_request(body, http_method)
|
1181
|
+
end
|
1182
|
+
|
1183
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#requestairdrop
|
1184
|
+
#
|
1185
|
+
# Requests an airdrop of lamports to a Pubkey
|
1186
|
+
#
|
1187
|
+
# @param pubkey [String]
|
1188
|
+
# @param lamports [Integer]
|
1189
|
+
# @param commitment [String]
|
1190
|
+
#
|
1191
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
1192
|
+
def request_airdrop(pubkey, lamports, commitment: nil)
|
1193
|
+
http_method = :post
|
1194
|
+
method = create_method_name(__method__)
|
1195
|
+
|
1196
|
+
params = []
|
1197
|
+
params_hash = {}
|
1198
|
+
|
1199
|
+
params << pubkey
|
1200
|
+
params << lamports
|
1201
|
+
params << params_hash unless params_hash.empty?
|
1202
|
+
|
1203
|
+
body = create_json_body(method, method_params: params)
|
1204
|
+
|
1205
|
+
send_request(body, http_method)
|
1206
|
+
end
|
1207
|
+
|
1208
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#sendtransaction
|
1209
|
+
#
|
1210
|
+
# Submits a signed transaction to the cluster for processing.
|
1211
|
+
#
|
1212
|
+
# @param transaction_signature [String]
|
1213
|
+
# @param skip_pre_flight [Boolean]
|
1214
|
+
# @param pre_flight_commitment [String]
|
1215
|
+
# @param encoding [String]
|
1216
|
+
#
|
1217
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
1218
|
+
def send_transaction(
|
1219
|
+
transaction_signature,
|
1220
|
+
skip_pre_flight: false,
|
1221
|
+
pre_flight_commitment: nil,
|
1222
|
+
encoding: ''
|
1223
|
+
)
|
1224
|
+
http_method = :post
|
1225
|
+
method = create_method_name(__method__)
|
1226
|
+
|
1227
|
+
params = []
|
1228
|
+
params_hash = {}
|
1229
|
+
|
1230
|
+
params_hash['skipPreFlight'] = skip_pre_flight unless skip_pre_flight.nil?
|
1231
|
+
params_hash['preflightCommitment'] = pre_flight_commitment unless blank?(pre_flight_commitment)
|
1232
|
+
params_hash['encoding'] = encoding unless blank?(encoding)
|
1233
|
+
|
1234
|
+
params << transaction_signature
|
1235
|
+
params << params_hash unless params_hash.empty?
|
1236
|
+
|
1237
|
+
body = create_json_body(method, method_params: params)
|
1238
|
+
|
1239
|
+
send_request(body, http_method)
|
1240
|
+
end
|
1241
|
+
|
1242
|
+
|
1243
|
+
# @see https://docs.solana.com/developing/clients/jsonrpc-api#simulatetransaction
|
1244
|
+
#
|
1245
|
+
# Simulate sending a transaction
|
1246
|
+
# accounts_addresses should be an empty array (?)
|
1247
|
+
#
|
1248
|
+
# @param transaction_signature [String]
|
1249
|
+
# @param accounts_addresses [Array]
|
1250
|
+
# @param sig_verify [Boolean]
|
1251
|
+
# @param commitment [String]
|
1252
|
+
# @param encoding [String]
|
1253
|
+
# @param replace_recent_blockhash [Boolean]
|
1254
|
+
# @param accounts_encoding [String]
|
1255
|
+
#
|
1256
|
+
# @return [Response, ApiError] Response when success, ApiError on failure.
|
1257
|
+
def simulate_transaction(
|
1258
|
+
transaction_signature,
|
1259
|
+
accounts_addresses,
|
1260
|
+
sig_verify: false,
|
1261
|
+
commitment: nil,
|
1262
|
+
encoding: '',
|
1263
|
+
replace_recent_blockhash: false,
|
1264
|
+
accounts_encoding: ''
|
1265
|
+
)
|
1266
|
+
|
1267
|
+
raise ArgumentError, 'Params sig_verify and replace_recent_blockhash cannot both be set to true.' \
|
1268
|
+
if sig_verify && replace_recent_blockhash
|
1269
|
+
|
1270
|
+
http_method = :post
|
1271
|
+
method = create_method_name(__method__)
|
1272
|
+
|
1273
|
+
params = []
|
1274
|
+
params_hash = {}
|
1275
|
+
params_hash['accounts'] = {}
|
1276
|
+
|
1277
|
+
params_hash['accounts']['addresses'] = accounts_addresses
|
1278
|
+
params_hash['accounts']['encoding'] = accounts_encoding unless blank?(accounts_encoding)
|
1279
|
+
params_hash['sigVerify'] = sig_verify unless sig_verify.nil?
|
1280
|
+
params_hash['commitment'] = commitment unless blank?(commitment)
|
1281
|
+
params_hash['encoding'] = encoding unless blank?(encoding)
|
1282
|
+
params_hash['replaceRecentBlockhash'] = replace_recent_blockhash unless replace_recent_blockhash.nil?
|
1283
|
+
|
1284
|
+
params << transaction_signature
|
1285
|
+
params << params_hash unless params_hash.empty?
|
1286
|
+
|
1287
|
+
body = create_json_body(method, method_params: params)
|
1288
|
+
|
1289
|
+
send_request(body, http_method)
|
1290
|
+
end
|
1291
|
+
|
1292
|
+
private
|
1293
|
+
def send_request(body, http_method)
|
1294
|
+
api_response = api_client.call_api(
|
1295
|
+
body: body,
|
1296
|
+
http_method: http_method,
|
1297
|
+
)
|
1298
|
+
|
1299
|
+
if api_response.body
|
1300
|
+
response = Response.new(api_response)
|
1301
|
+
|
1302
|
+
fail ApiError.new(response.parsed_response) if response.parsed_response.key?('error')
|
1303
|
+
|
1304
|
+
return response
|
1305
|
+
end
|
1306
|
+
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
|
+
end
|
1316
|
+
end
|