solana_rpc_ruby 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/LICENSE +20 -674
- data/README.md +14 -9
- data/lib/solana_rpc_ruby/api_client.rb +22 -12
- data/lib/solana_rpc_ruby/api_error.rb +13 -2
- data/lib/solana_rpc_ruby/methods_wrapper.rb +303 -109
- data/lib/solana_rpc_ruby/version.rb +1 -1
- data/lib/solana_rpc_ruby/websocket_client.rb +0 -18
- data/lib/solana_rpc_ruby/websocket_methods_wrapper.rb +82 -31
- metadata +6 -6
data/README.md
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|

|
2
|
+

|
3
|
+

|
4
|
+

|
5
|
+

|
6
|
+
[](https://opensource.org/licenses/MIT)
|
2
7
|
# solana_rpc_ruby
|
3
8
|
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
9
|
|
@@ -6,7 +11,7 @@ A Solana RPC Client for Ruby. This gem provides a wrapper methods for Solana RPC
|
|
6
11
|
|
7
12
|
### Requirements
|
8
13
|
|
9
|
-
This gem requires Ruby 2.6+ and h Rails 6.0+. It MIGHT work with lower versions, but was not tested
|
14
|
+
This gem requires Ruby 2.6+ and h Rails 6.0+. It MIGHT work with lower versions, but was not tested with them.
|
10
15
|
Add the following line to your Gemfile:
|
11
16
|
|
12
17
|
```ruby
|
@@ -90,7 +95,7 @@ More explanation on Action Cable here: https://www.pluralsight.com/guides/updati
|
|
90
95
|
0. Make sure that you have action_cable and solana_rpc_ruby gems installed properly. Also install redis unless you have it.
|
91
96
|
|
92
97
|
1. Mount action_cable in `routes.rb`.
|
93
|
-
```
|
98
|
+
```ruby
|
94
99
|
Rails.application.routes.draw do
|
95
100
|
mount ActionCable.server => '/cable'
|
96
101
|
...
|
@@ -98,25 +103,25 @@ end
|
|
98
103
|
```
|
99
104
|
|
100
105
|
2. Update `config/environments/development.rb`.
|
101
|
-
```
|
106
|
+
```ruby
|
102
107
|
config.action_cable.url = "ws://localhost:3000/cable"
|
103
108
|
config.action_cable.allowed_request_origins = [/http:\/\/*/, /https:\/\/*/]
|
104
109
|
```
|
105
110
|
|
106
111
|
3. Update adapter in `cable.yml`.
|
107
|
-
```
|
112
|
+
```ruby
|
108
113
|
development:
|
109
114
|
adapter: redis
|
110
115
|
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
|
111
116
|
```
|
112
117
|
|
113
118
|
4. Create a channel.
|
114
|
-
```
|
119
|
+
```ruby
|
115
120
|
rails g channel wall
|
116
121
|
```
|
117
122
|
|
118
123
|
5. Your `wall_channel.rb` should look like this:
|
119
|
-
```
|
124
|
+
```ruby
|
120
125
|
class WallChannel < ApplicationCable::Channel
|
121
126
|
def subscribed
|
122
127
|
stream_from "wall_channel"
|
@@ -129,7 +134,7 @@ end
|
|
129
134
|
```
|
130
135
|
|
131
136
|
6. Your `wall_channel.js` should look like this (json keys are configured for `root_subscription` method response):
|
132
|
-
```
|
137
|
+
```js
|
133
138
|
import consumer from "./consumer"
|
134
139
|
|
135
140
|
consumer.subscriptions.create("WallChannel", {
|
@@ -154,14 +159,14 @@ consumer.subscriptions.create("WallChannel", {
|
|
154
159
|
```
|
155
160
|
|
156
161
|
7. Create placeholder somewhere in your view for messages.
|
157
|
-
```
|
162
|
+
```html
|
158
163
|
<div id='wall' style='overflow-y: scroll; height:400px;''>
|
159
164
|
<h1>Solana subscription messages</h1>
|
160
165
|
</div>
|
161
166
|
```
|
162
167
|
|
163
168
|
8. Create a script with a block to run websockets (`script/websockets_solana.rb`).
|
164
|
-
```
|
169
|
+
```ruby
|
165
170
|
require_relative '../config/environment'
|
166
171
|
|
167
172
|
ws_method_wrapper = SolanaRpcRuby::WebsocketsMethodsWrapper.new
|
@@ -4,6 +4,9 @@ module SolanaRpcRuby
|
|
4
4
|
# ApiClient class serves as a client for solana JSON RPC API.
|
5
5
|
# @see https://docs.solana.com/developing/clients/jsonrpc-api
|
6
6
|
class ApiClient
|
7
|
+
OPEN_TIMEOUT = 120
|
8
|
+
READ_TIMEOUT = 120
|
9
|
+
|
7
10
|
# Determines which cluster will be used to send requests.
|
8
11
|
# @return [String]
|
9
12
|
attr_accessor :cluster
|
@@ -30,27 +33,34 @@ module SolanaRpcRuby
|
|
30
33
|
#
|
31
34
|
# @return [Object] Net::HTTPOK
|
32
35
|
def call_api(body:, http_method:, params: {})
|
33
|
-
uri = URI(@cluster)
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
body,
|
38
|
-
default_headers,
|
39
|
-
)
|
36
|
+
uri = URI.parse(@cluster)
|
37
|
+
|
38
|
+
request = Net::HTTP::Post.new(uri, default_headers)
|
39
|
+
request.body = body
|
40
40
|
|
41
|
-
|
41
|
+
Net::HTTP.start(
|
42
|
+
uri.host,
|
43
|
+
uri.port,
|
44
|
+
use_ssl: true,
|
45
|
+
open_timeout: OPEN_TIMEOUT,
|
46
|
+
read_timeout: READ_TIMEOUT
|
47
|
+
) do |http|
|
48
|
+
http.request(request)
|
49
|
+
end
|
42
50
|
|
43
51
|
rescue Timeout::Error,
|
44
52
|
Net::HTTPError,
|
45
53
|
Net::HTTPNotFound,
|
46
54
|
Net::HTTPClientException,
|
47
55
|
Net::HTTPFatalError,
|
48
|
-
Net::ReadTimeout
|
49
|
-
|
50
|
-
|
56
|
+
Net::ReadTimeout,
|
57
|
+
Errno::ECONNREFUSED,
|
58
|
+
SocketError => e
|
51
59
|
|
60
|
+
fail ApiError.new(error_class: e.class, message: e.message)
|
61
|
+
rescue StandardError => e
|
52
62
|
message = "#{e.class} #{e.message}\n Backtrace: \n #{e.backtrace}"
|
53
|
-
fail ApiError.new(message: message)
|
63
|
+
fail ApiError.new(error_class: e.class, message: e.message)
|
54
64
|
end
|
55
65
|
|
56
66
|
private
|
@@ -17,11 +17,22 @@ module SolanaRpcRuby
|
|
17
17
|
# @param message [String]
|
18
18
|
#
|
19
19
|
# @return [SolanaRpcRuby::ApiError]
|
20
|
-
def initialize(
|
20
|
+
def initialize(message:, error_class: nil, code: nil)
|
21
21
|
@code = code
|
22
22
|
@message = message.to_s
|
23
|
+
@error_class = error_class
|
23
24
|
|
24
|
-
|
25
|
+
additional_info
|
26
|
+
|
27
|
+
super @message
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def additional_info
|
32
|
+
wrong_url_errors = [Errno::ECONNREFUSED, SocketError]
|
33
|
+
if wrong_url_errors.include?(@error_class)
|
34
|
+
@message += '. Check if the RPC url you provided is correct.'
|
35
|
+
end
|
25
36
|
end
|
26
37
|
end
|
27
38
|
end
|