solana-ruby-web3js 1.0.1.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.rspec +1 -0
- data/.rubocop.yml +13 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +184 -0
- data/README.md +273 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/.DS_Store +0 -0
- data/lib/solana_ruby/.DS_Store +0 -0
- data/lib/solana_ruby/base_client.rb +46 -0
- data/lib/solana_ruby/http_client.rb +42 -0
- data/lib/solana_ruby/http_methods/account_methods.rb +98 -0
- data/lib/solana_ruby/http_methods/basic_methods.rb +108 -0
- data/lib/solana_ruby/http_methods/block_methods.rb +89 -0
- data/lib/solana_ruby/http_methods/blockhash_methods.rb +30 -0
- data/lib/solana_ruby/http_methods/lookup_table_methods.rb +55 -0
- data/lib/solana_ruby/http_methods/signature_methods.rb +30 -0
- data/lib/solana_ruby/http_methods/slot_methods.rb +44 -0
- data/lib/solana_ruby/http_methods/token_methods.rb +32 -0
- data/lib/solana_ruby/http_methods/transaction_methods.rb +85 -0
- data/lib/solana_ruby/version.rb +5 -0
- data/lib/solana_ruby/web_socket_client.rb +93 -0
- data/lib/solana_ruby/web_socket_handlers.rb +34 -0
- data/lib/solana_ruby/web_socket_methods/account_methods.rb +37 -0
- data/lib/solana_ruby/web_socket_methods/log_methods.rb +27 -0
- data/lib/solana_ruby/web_socket_methods/root_methods.rb +16 -0
- data/lib/solana_ruby/web_socket_methods/signature_methods.rb +25 -0
- data/lib/solana_ruby/web_socket_methods/slot_methods.rb +20 -0
- data/lib/solana_ruby.rb +10 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4347561fb0649ad1967e7900b9b0d918324d0b54d41c151073e179ffc062efbc
|
4
|
+
data.tar.gz: 777a7663b8c1c8f986748bcd2ef2e4b18a57244d4b14c3734ea5385f35d640b4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d70fbb66c1467ca8c0d913072c1085ca231515a7b9dc0ee918dd5ab4976f42a7513534566bc70485e3a3103d9faa31573161a171cbd528d859192ff1700974cc
|
7
|
+
data.tar.gz: a82cfa020893598eda4e95faef76b50a10eb3df871020997ac7ac2fb50f36e53625cc9f9550907331d2e086992a38edd2f049535e6aa1916edee1e4fd51cdabc
|
data/.DS_Store
ADDED
Binary file
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.1
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at gmudumuntala@navaratan.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in solana.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "rake", "~> 13.0"
|
9
|
+
|
10
|
+
gem "rubocop", "~> 1.21"
|
11
|
+
|
12
|
+
group :development, :test do
|
13
|
+
gem 'rspec'
|
14
|
+
gem 'webmock'
|
15
|
+
gem 'simplecov', require: false
|
16
|
+
gem 'ed25519'
|
17
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,184 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
solana_ruby (2.0.0)
|
5
|
+
brakeman (~> 6.1.2)
|
6
|
+
pry (~> 0.14.2)
|
7
|
+
rubycritic (~> 4.9.0)
|
8
|
+
simplecov (~> 0.22.0)
|
9
|
+
websocket-client-simple (~> 0.8.0)
|
10
|
+
|
11
|
+
GEM
|
12
|
+
remote: https://rubygems.org/
|
13
|
+
specs:
|
14
|
+
addressable (2.8.7)
|
15
|
+
public_suffix (>= 2.0.2, < 7.0)
|
16
|
+
ast (2.4.2)
|
17
|
+
axiom-types (0.1.1)
|
18
|
+
descendants_tracker (~> 0.0.4)
|
19
|
+
ice_nine (~> 0.11.0)
|
20
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
21
|
+
bigdecimal (3.1.8)
|
22
|
+
brakeman (6.1.2)
|
23
|
+
racc
|
24
|
+
childprocess (5.0.0)
|
25
|
+
coderay (1.1.3)
|
26
|
+
coercible (1.0.0)
|
27
|
+
descendants_tracker (~> 0.0.1)
|
28
|
+
concurrent-ruby (1.3.3)
|
29
|
+
crack (1.0.0)
|
30
|
+
bigdecimal
|
31
|
+
rexml
|
32
|
+
descendants_tracker (0.0.4)
|
33
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
34
|
+
diff-lcs (1.5.1)
|
35
|
+
docile (1.4.1)
|
36
|
+
dry-configurable (1.2.0)
|
37
|
+
dry-core (~> 1.0, < 2)
|
38
|
+
zeitwerk (~> 2.6)
|
39
|
+
dry-core (1.0.1)
|
40
|
+
concurrent-ruby (~> 1.0)
|
41
|
+
zeitwerk (~> 2.6)
|
42
|
+
dry-inflector (1.1.0)
|
43
|
+
dry-initializer (3.1.1)
|
44
|
+
dry-logic (1.5.0)
|
45
|
+
concurrent-ruby (~> 1.0)
|
46
|
+
dry-core (~> 1.0, < 2)
|
47
|
+
zeitwerk (~> 2.6)
|
48
|
+
dry-schema (1.13.4)
|
49
|
+
concurrent-ruby (~> 1.0)
|
50
|
+
dry-configurable (~> 1.0, >= 1.0.1)
|
51
|
+
dry-core (~> 1.0, < 2)
|
52
|
+
dry-initializer (~> 3.0)
|
53
|
+
dry-logic (>= 1.4, < 2)
|
54
|
+
dry-types (>= 1.7, < 2)
|
55
|
+
zeitwerk (~> 2.6)
|
56
|
+
dry-types (1.7.2)
|
57
|
+
bigdecimal (~> 3.0)
|
58
|
+
concurrent-ruby (~> 1.0)
|
59
|
+
dry-core (~> 1.0)
|
60
|
+
dry-inflector (~> 1.0)
|
61
|
+
dry-logic (~> 1.4)
|
62
|
+
zeitwerk (~> 2.6)
|
63
|
+
ed25519 (1.3.0)
|
64
|
+
erubi (1.13.0)
|
65
|
+
event_emitter (0.2.6)
|
66
|
+
flay (2.13.3)
|
67
|
+
erubi (~> 1.10)
|
68
|
+
path_expander (~> 1.0)
|
69
|
+
ruby_parser (~> 3.0)
|
70
|
+
sexp_processor (~> 4.0)
|
71
|
+
flog (4.8.0)
|
72
|
+
path_expander (~> 1.0)
|
73
|
+
ruby_parser (~> 3.1, > 3.1.0)
|
74
|
+
sexp_processor (~> 4.8)
|
75
|
+
hashdiff (1.1.1)
|
76
|
+
ice_nine (0.11.2)
|
77
|
+
json (2.7.2)
|
78
|
+
language_server-protocol (3.17.0.3)
|
79
|
+
launchy (3.0.1)
|
80
|
+
addressable (~> 2.8)
|
81
|
+
childprocess (~> 5.0)
|
82
|
+
method_source (1.1.0)
|
83
|
+
parallel (1.25.1)
|
84
|
+
parser (3.3.4.0)
|
85
|
+
ast (~> 2.4.1)
|
86
|
+
racc
|
87
|
+
path_expander (1.1.2)
|
88
|
+
pry (0.14.2)
|
89
|
+
coderay (~> 1.1)
|
90
|
+
method_source (~> 1.0)
|
91
|
+
public_suffix (6.0.1)
|
92
|
+
racc (1.8.1)
|
93
|
+
rainbow (3.1.1)
|
94
|
+
rake (13.2.1)
|
95
|
+
reek (6.3.0)
|
96
|
+
dry-schema (~> 1.13.0)
|
97
|
+
parser (~> 3.3.0)
|
98
|
+
rainbow (>= 2.0, < 4.0)
|
99
|
+
rexml (~> 3.1)
|
100
|
+
regexp_parser (2.9.2)
|
101
|
+
rexml (3.3.2)
|
102
|
+
strscan
|
103
|
+
rspec (3.13.0)
|
104
|
+
rspec-core (~> 3.13.0)
|
105
|
+
rspec-expectations (~> 3.13.0)
|
106
|
+
rspec-mocks (~> 3.13.0)
|
107
|
+
rspec-core (3.13.0)
|
108
|
+
rspec-support (~> 3.13.0)
|
109
|
+
rspec-expectations (3.13.1)
|
110
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
111
|
+
rspec-support (~> 3.13.0)
|
112
|
+
rspec-mocks (3.13.1)
|
113
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
114
|
+
rspec-support (~> 3.13.0)
|
115
|
+
rspec-support (3.13.1)
|
116
|
+
rubocop (1.65.0)
|
117
|
+
json (~> 2.3)
|
118
|
+
language_server-protocol (>= 3.17.0)
|
119
|
+
parallel (~> 1.10)
|
120
|
+
parser (>= 3.3.0.2)
|
121
|
+
rainbow (>= 2.2.2, < 4.0)
|
122
|
+
regexp_parser (>= 2.4, < 3.0)
|
123
|
+
rexml (>= 3.2.5, < 4.0)
|
124
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
125
|
+
ruby-progressbar (~> 1.7)
|
126
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
127
|
+
rubocop-ast (1.31.3)
|
128
|
+
parser (>= 3.3.1.0)
|
129
|
+
ruby-progressbar (1.13.0)
|
130
|
+
ruby_parser (3.21.1)
|
131
|
+
racc (~> 1.5)
|
132
|
+
sexp_processor (~> 4.16)
|
133
|
+
rubycritic (4.9.0)
|
134
|
+
flay (~> 2.13)
|
135
|
+
flog (~> 4.7)
|
136
|
+
launchy (>= 2.5.2)
|
137
|
+
parser (>= 3.2.2.1)
|
138
|
+
rainbow (~> 3.1.1)
|
139
|
+
reek (~> 6.0, < 7.0)
|
140
|
+
rexml
|
141
|
+
ruby_parser (~> 3.20)
|
142
|
+
simplecov (>= 0.22.0)
|
143
|
+
tty-which (~> 0.5.0)
|
144
|
+
virtus (~> 2.0)
|
145
|
+
sexp_processor (4.17.2)
|
146
|
+
simplecov (0.22.0)
|
147
|
+
docile (~> 1.1)
|
148
|
+
simplecov-html (~> 0.11)
|
149
|
+
simplecov_json_formatter (~> 0.1)
|
150
|
+
simplecov-html (0.12.3)
|
151
|
+
simplecov_json_formatter (0.1.4)
|
152
|
+
strscan (3.1.0)
|
153
|
+
thread_safe (0.3.6)
|
154
|
+
tty-which (0.5.0)
|
155
|
+
unicode-display_width (2.5.0)
|
156
|
+
virtus (2.0.0)
|
157
|
+
axiom-types (~> 0.1)
|
158
|
+
coercible (~> 1.0)
|
159
|
+
descendants_tracker (~> 0.0, >= 0.0.3)
|
160
|
+
webmock (3.23.1)
|
161
|
+
addressable (>= 2.8.0)
|
162
|
+
crack (>= 0.3.2)
|
163
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
164
|
+
websocket (1.2.11)
|
165
|
+
websocket-client-simple (0.8.0)
|
166
|
+
event_emitter
|
167
|
+
websocket
|
168
|
+
zeitwerk (2.6.17)
|
169
|
+
|
170
|
+
PLATFORMS
|
171
|
+
arm64-darwin-23
|
172
|
+
ruby
|
173
|
+
|
174
|
+
DEPENDENCIES
|
175
|
+
ed25519
|
176
|
+
rake (~> 13.0)
|
177
|
+
rspec
|
178
|
+
rubocop (~> 1.21)
|
179
|
+
simplecov
|
180
|
+
solana_ruby!
|
181
|
+
webmock
|
182
|
+
|
183
|
+
BUNDLED WITH
|
184
|
+
2.5.16
|
data/README.md
ADDED
@@ -0,0 +1,273 @@
|
|
1
|
+
# SolanaRuby
|
2
|
+
|
3
|
+
`SolanaRuby` is a lightweight Ruby client for interacting with the Solana blockchain through its JSON-RPC API. It allows developers to perform various queries on the Solana network such as fetching solana balance, acccount information, and more.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'solana-ruby-web3js'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install solana-ruby-web3js
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
To start using the Solana RPC client, initialize it with or without the RPC URL. The default URL points to the Solana Mainnet. If you wish to connect to another network like Devnet or Testnet, you can specify the URL.
|
24
|
+
|
25
|
+
require 'solana_ruby'
|
26
|
+
|
27
|
+
# Initialize the client (defaults to Mainnet(https://api.mainnet-beta.solana.com))
|
28
|
+
client = SolanaRuby::HttpClient.new()
|
29
|
+
|
30
|
+
# Optionally, provide a custom RPC URL
|
31
|
+
# client = SolanaRuby::HttpClient.new("https://api.devnet.solana.com")
|
32
|
+
|
33
|
+
### Fetch Solana Account Balance
|
34
|
+
|
35
|
+
Once the client is initialized, you can make API calls to the Solana network. For example, to get the solana balance of a given account:
|
36
|
+
|
37
|
+
# Replace 'pubkey' with the actual public key of the solana account
|
38
|
+
|
39
|
+
pubkey = 'Fg6PaFpoGXkYsidMpWxTWqSKJf6KJkUxX92cnv7WMd2J'
|
40
|
+
|
41
|
+
result = client.get_balance(pubkey)
|
42
|
+
|
43
|
+
puts result
|
44
|
+
|
45
|
+
### Fetch Parsed Account Info
|
46
|
+
|
47
|
+
# Replace 'pubkey' with the actual public key of the account
|
48
|
+
pubkey = 'Fg6PaFpoGXkYsidMpWxTWqSKJf6KJkUxX92cnv7WMd2J'
|
49
|
+
|
50
|
+
# Example of options that can be passed:
|
51
|
+
options = {
|
52
|
+
commitment: 'finalized', # Specifies the level of commitment for querying state (e.g., 'finalized', 'confirmed', 'processed')
|
53
|
+
encoding: 'jsonParsed' # Specifies the encoding format (e.g., 'jsonParsed', 'base64', etc.)
|
54
|
+
}
|
55
|
+
|
56
|
+
result = client.get_parsed_account_info(pubkey, options)
|
57
|
+
|
58
|
+
puts result
|
59
|
+
|
60
|
+
### Options Parameter
|
61
|
+
|
62
|
+
The options parameter is a hash that can include the following fields:
|
63
|
+
|
64
|
+
commitment: Specifies the level of commitment desired when querying state.
|
65
|
+
|
66
|
+
Options include:
|
67
|
+
|
68
|
+
'finalized': Query the most recent block confirmed by supermajority of the cluster.
|
69
|
+
'confirmed': Query the most recent block that has been voted on by supermajority of the cluster.
|
70
|
+
'processed': Query the most recent block regardless of cluster voting.
|
71
|
+
|
72
|
+
encoding: Defines the format of the returned account data. Possible values include:
|
73
|
+
|
74
|
+
'jsonParsed': Returns data in a JSON-parsed format.
|
75
|
+
'base64': Returns raw account data in Base64 encoding.
|
76
|
+
'base64+zstd': Returns compressed Base64 data.
|
77
|
+
|
78
|
+
By providing options, you can control the nature of the returned data and the reliability of the query.
|
79
|
+
|
80
|
+
### Filters Parameter
|
81
|
+
|
82
|
+
The filters parameter allows you to specify conditions for querying token accounts. Some common filter types include:
|
83
|
+
|
84
|
+
# Mint Filter: Filter by a specific token mint. This retrieves accounts holding tokens of that mint.
|
85
|
+
filters = { mint: 'TokenMintPublicKey' }
|
86
|
+
|
87
|
+
# Program Filter: Filter by a specific program (e.g., the token program).
|
88
|
+
filters = { programId: 'TokenProgramPublicKey' }
|
89
|
+
|
90
|
+
## WebSocket Methods
|
91
|
+
|
92
|
+
The SolanaRuby gem also provides WebSocket methods to handle real-time notifications and updates from the Solana blockchain. To use the WebSocket client:
|
93
|
+
|
94
|
+
# Initialize the WebSocket client
|
95
|
+
ws_client = SolanaRuby::WebSocketClient.new("wss://api.mainnet-beta.solana.com")
|
96
|
+
|
97
|
+
# Subscribe to slot change notifications
|
98
|
+
subscription_id = ws_client.on_slot_change do |slot_info|
|
99
|
+
puts "Slot changed: #{slot_info}"
|
100
|
+
end
|
101
|
+
|
102
|
+
# Sleep to hold the process and show updates
|
103
|
+
sleep 60 # Adjust the duration as needed to view updates
|
104
|
+
|
105
|
+
# Unsubscribe from slot change notifications
|
106
|
+
ws_client.remove_slot_change_listener(subscription_id)
|
107
|
+
puts "Unsubscribed from slot change notifications."
|
108
|
+
|
109
|
+
The following methods are supported by the WebSocketClient:
|
110
|
+
|
111
|
+
- **Account Change**: Subscribe to changes in an account's state.
|
112
|
+
|
113
|
+
```ws_client.on_account_change(pubkey) { |account_info| puts account_info }```
|
114
|
+
|
115
|
+
- **Program Account Change**: Subscribe to changes in accounts owned by a specific program.
|
116
|
+
|
117
|
+
```ws_client.on_program_account_change(program_id, filters) { |program_account_info| puts program_account_info }```
|
118
|
+
|
119
|
+
- **Logs**: Subscribe to transaction logs.
|
120
|
+
|
121
|
+
```ws_client.on_logs { |logs_info| puts logs_info }```
|
122
|
+
|
123
|
+
- **Logs for a Specific Account**: Subscribe to logs related to a specific account.
|
124
|
+
|
125
|
+
```ws_client.on_logs_for_account(account_pubkey) { |logs_info| puts logs_info }```
|
126
|
+
|
127
|
+
- **Logs for a Specific Program**: Subscribe to logs related to a specific program.
|
128
|
+
|
129
|
+
```ws_client.on_logs_for_program(program_id) { |logs_info| puts logs_info }```
|
130
|
+
|
131
|
+
- **Root Change**: Subscribe to root changes.
|
132
|
+
|
133
|
+
ws_client.on_root_change { |root_info| puts root_info }
|
134
|
+
|
135
|
+
- **Signature**: Subscribe to a signature notification.
|
136
|
+
|
137
|
+
```ws_client.on_signature(signature) { |signature_info| puts signature_info }```
|
138
|
+
|
139
|
+
- **Slot Change**: Subscribe to slot changes.
|
140
|
+
|
141
|
+
```ws_client.on_slot_change { |slot_info| puts slot_info }```
|
142
|
+
|
143
|
+
- **Unsubscribe Methods**: Each WebSocket method has a corresponding unsubscribe method:
|
144
|
+
|
145
|
+
- remove_account_change_listener(subscription_id)
|
146
|
+
- remove_program_account_listener(subscription_id)
|
147
|
+
- remove_logs_listener(subscription_id)
|
148
|
+
- remove_root_listener(subscription_id)
|
149
|
+
- remove_signature_listener(subscription_id)
|
150
|
+
- remove_slot_change_listener(subscription_id)
|
151
|
+
|
152
|
+
|
153
|
+
## Complete List of Available Methods
|
154
|
+
|
155
|
+
### HTTP Methods
|
156
|
+
|
157
|
+
The following methods are supported by the SolanaRuby::HttpClient:
|
158
|
+
|
159
|
+
#### Basic
|
160
|
+
get_balance(pubkey)
|
161
|
+
get_balance_and_context(pubkey)
|
162
|
+
get_slot()
|
163
|
+
get_epoch_info(options)
|
164
|
+
get_epoch_schedule()
|
165
|
+
get_genesis_hash()
|
166
|
+
get_inflation_governor()
|
167
|
+
get_inflation_rate()
|
168
|
+
get_inflation_reward(addresses, options)
|
169
|
+
get_leader_schedule(options)
|
170
|
+
get_minimum_balance_for_rent_exemption(account_data_size, options)
|
171
|
+
get_stake_activation(account_pubkey, options)
|
172
|
+
get_stake_minimum_delegation(options)
|
173
|
+
get_supply(options)
|
174
|
+
get_version()
|
175
|
+
get_total_supply(options)
|
176
|
+
get_health()
|
177
|
+
get_identity()
|
178
|
+
get_recent_performance_samples(limit)
|
179
|
+
get_recent_prioritization_fees(addresses)
|
180
|
+
|
181
|
+
#### Account
|
182
|
+
get_account_info(pubkey)
|
183
|
+
get_parsed_account_info(pubkey, options)
|
184
|
+
get_account_info_and_context(pubkey, options)
|
185
|
+
get_multiple_account_info(pubkeys, options)
|
186
|
+
get_multiple_account_info_and_context(pubkeys, options)
|
187
|
+
get_multiple_parsed_accounts(pubkeys, options)
|
188
|
+
get_largest_accounts(options)
|
189
|
+
get_program_accounts(program_id, options)
|
190
|
+
get_parsed_program_accounts(program_id, options)
|
191
|
+
get_vote_accounts(options)
|
192
|
+
get_parsed_token_accounts_by_owner(owner_pubkey, filters, options)
|
193
|
+
get_nonce_and_context(pubkey)
|
194
|
+
get_nonce(pubkey)
|
195
|
+
|
196
|
+
#### Block
|
197
|
+
get_nonce(pubkey)
|
198
|
+
get_block(slot, options)
|
199
|
+
get_block_production()
|
200
|
+
get_block_time(slot)
|
201
|
+
get_block_signatures(slot, options)
|
202
|
+
get_cluster_nodes()
|
203
|
+
get_confirmed_block(slot, options)
|
204
|
+
get_confirmed_block_signatures(slot)
|
205
|
+
get_parsed_block(slot, options)
|
206
|
+
get_first_available_block()
|
207
|
+
get_blocks_with_limit(start_slot, limit)
|
208
|
+
get_block_height()
|
209
|
+
get_block_commitment(block_slot)
|
210
|
+
|
211
|
+
#### Blockhash
|
212
|
+
get_latest_blockhash()
|
213
|
+
get_latest_blockhash()
|
214
|
+
get_fee_for_message(blockhash, options)
|
215
|
+
is_blockhash_valid?(blockhash, options)
|
216
|
+
|
217
|
+
#### Lookup Table
|
218
|
+
get_address_lookup_table(pubkey)
|
219
|
+
|
220
|
+
#### Signature
|
221
|
+
get_signature_statuses(signatures)
|
222
|
+
get_signature_status(signature, options)
|
223
|
+
get_signatures_for_address(address, options)
|
224
|
+
|
225
|
+
#### Slot
|
226
|
+
get_slot()
|
227
|
+
get_slot_leader(options)
|
228
|
+
get_slot_leaders(start_slot, limit)
|
229
|
+
get_highest_snapshot_slot()
|
230
|
+
get_minimum_ladger_slot()
|
231
|
+
get_max_retransmit_slot()
|
232
|
+
get_max_shred_insert_slot()
|
233
|
+
|
234
|
+
#### Token
|
235
|
+
get_token_balance(pubkey, options)
|
236
|
+
get_token_supply(pubkey)
|
237
|
+
get_token_accounts_by_owner(owner_pubkey, filters, options)
|
238
|
+
get_token_largest_accounts(mint_pubkey, options)
|
239
|
+
|
240
|
+
#### Transaction
|
241
|
+
send_transaction(signed_transaction, options)
|
242
|
+
confirm_transaction(signature, commitment, timeout)
|
243
|
+
get_transaction(signature, options)
|
244
|
+
get_transaction_count(options)
|
245
|
+
get_transactions(signatures, options)
|
246
|
+
request_airdrop(pubkey, lamports, options)
|
247
|
+
simulate_transaction(transaction, options)
|
248
|
+
send_encoded_transaction(encoded_transaction, options)
|
249
|
+
send_raw_transaction(raw_transaction, options)
|
250
|
+
|
251
|
+
### WebSocket Methods
|
252
|
+
|
253
|
+
The following methods are supported by the SolanaRuby::WebSocketClient:
|
254
|
+
|
255
|
+
on_account_change(pubkey, options)
|
256
|
+
on_program_account_change(program_id, options, filters)
|
257
|
+
on_logs(options=['all'])
|
258
|
+
on_logs_for_account(public_key)
|
259
|
+
on_logs_for_program(program_id)
|
260
|
+
on_root_change()
|
261
|
+
on_signature(signature)
|
262
|
+
on_signature_with_options(signature, options)
|
263
|
+
remove_account_change_listener(subscription_id)
|
264
|
+
remove_program_account_listener(subscription_id)
|
265
|
+
remove_logs_listener(subscription_id)
|
266
|
+
remove_root_listener(subscription_id)
|
267
|
+
remove_signature_listener(subscription_id)
|
268
|
+
remove_slot_change_listener(subscription_id)
|
269
|
+
|
270
|
+
## Default Options
|
271
|
+
|
272
|
+
Several methods have optional parameters where default options are defined in the client. These options can be customized or overridden when calling the methods, but if left unspecified, the client will use its internal defaults.
|
273
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "solana_ruby"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/.DS_Store
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SolanaRuby
|
4
|
+
class BaseClient
|
5
|
+
require 'active_support/core_ext/string/inflections'
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def handle_http_response(response)
|
10
|
+
body = JSON.parse(response.body)
|
11
|
+
# puts "body:==== #{body}"
|
12
|
+
if response.is_a?(Net::HTTPSuccess)
|
13
|
+
if body['error']
|
14
|
+
raise "API Error: #{body['error']['code']} - #{body['error']['message']}"
|
15
|
+
else
|
16
|
+
return body
|
17
|
+
end
|
18
|
+
else
|
19
|
+
raise "HTTP Error: #{response.code} - #{body['error']['message']}"
|
20
|
+
end
|
21
|
+
rescue JSON::ParserError
|
22
|
+
raise "Invalid JSON response: #{response.body}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def handle_error(error)
|
26
|
+
case error
|
27
|
+
when Timeout::Error
|
28
|
+
raise SolanaError.new('Request timed out')
|
29
|
+
when SocketError
|
30
|
+
raise SolanaError.new('Failed to connect to the server')
|
31
|
+
else
|
32
|
+
raise SolanaError.new("An unexpected error occurred: #{error.message}")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class SolanaError < StandardError
|
38
|
+
def initialize(message)
|
39
|
+
super(message)
|
40
|
+
end
|
41
|
+
|
42
|
+
def backtrace
|
43
|
+
[]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|