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.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SolanaRpcRuby
4
- VERSION = '1.1.1'
4
+ VERSION = '1.2.0'
5
5
  end
@@ -27,7 +27,6 @@ module SolanaRpcRuby
27
27
  @client = websocket_client
28
28
  @cluster = cluster || SolanaRpcRuby.ws_cluster
29
29
  @retries = 0
30
- @subscription_info = nil
31
30
 
32
31
  message = 'Websocket cluster is missing. Please provide default cluster in config or pass it to the client directly.'
33
32
  raise ArgumentError, message unless @cluster
@@ -59,11 +58,6 @@ module SolanaRpcRuby
59
58
  end
60
59
  end
61
60
 
62
- # Uncomment to disconnect websocket.
63
- # EM::Timer.new(2) do
64
- # ws.send(unsubscribe_body(body))
65
- # end
66
-
67
61
  ws.on :open do |event|
68
62
  p [:open]
69
63
  p "Status: #{ws.status}"
@@ -79,7 +73,6 @@ module SolanaRpcRuby
79
73
  # result = block_given? ? block.call(event.data) : event.data
80
74
  # return result
81
75
  # end
82
- @subscription_info = event.data unless @subscription_info
83
76
 
84
77
  if block_given?
85
78
  block.call(event.data)
@@ -114,16 +107,5 @@ module SolanaRpcRuby
114
107
  message = "#{e.class} #{e.message}\n Backtrace: \n #{e.backtrace}"
115
108
  fail ApiError.new(message: message)
116
109
  end
117
-
118
- def unsubscribe_body(body)
119
- method = JSON.parse(body)['method']
120
- info = JSON.parse(@subscription_info)
121
-
122
- subscription_id = info['result']
123
- id = info['id']
124
- unsubscribe_method = method.gsub('Sub', 'Unsub')
125
-
126
- create_json_body(unsubscribe_method, method_params: [subscription_id], id: id)
127
- end
128
110
  end
129
111
  end
@@ -29,7 +29,7 @@ module SolanaRpcRuby
29
29
  # @param cluster [String] cluster where requests will be sent.
30
30
  # @param id [Integer] unique client-generated identifying integer.
31
31
  def initialize(
32
- websocket_client: WebsocketClient,
32
+ websocket_client: WebsocketClient,
33
33
  cluster: SolanaRpcRuby.ws_cluster,
34
34
  id: rand(1...99_999)
35
35
  )
@@ -47,7 +47,7 @@ module SolanaRpcRuby
47
47
  #
48
48
  # @return [Integer] Subscription id (needed to unsubscribe)
49
49
  def account_subscribe(account_pubkey, commitment: nil, encoding: '', &block)
50
- method = create_method_name(__method__)
50
+ method = create_method_name(__method__)
51
51
 
52
52
  params = []
53
53
  params_hash = {}
@@ -56,7 +56,7 @@ module SolanaRpcRuby
56
56
 
57
57
  params << account_pubkey
58
58
  params << params_hash if params_hash.any?
59
-
59
+
60
60
  subscribe(method, method_params: params, &block)
61
61
  end
62
62
 
@@ -71,6 +71,57 @@ module SolanaRpcRuby
71
71
  unsubscribe(method, subscription_id: subscription_id)
72
72
  end
73
73
 
74
+ # @see https://docs.solana.com/developing/clients/jsonrpc-api#blocksubscribe---unstable-disabled-by-default
75
+ # This subscription is unstable and only available if the validator was started with the --rpc-pubsub-enable-block-subscription flag. The format of this subscription may change in the future
76
+ #
77
+ # Subscribe to receive notification anytime a new block is Confirmed or Finalized.
78
+ #
79
+ # @param filter [String] # 'all' or public key as base-58 endcoded string
80
+ # @param commitment [String]
81
+ # @param encoding [String]
82
+ # @param transaction_details [String]
83
+ # @param show_rewards [Boolean]
84
+ # @param &block [Proc]
85
+ #
86
+ # @return [Integer] Subscription id (needed to unsubscribe)
87
+ def block_subscribe(
88
+ filter,
89
+ commitment: nil,
90
+ encoding: '',
91
+ transaction_details: '',
92
+ show_rewards: nil,
93
+ &block
94
+ )
95
+ method = create_method_name(__method__)
96
+
97
+ params = []
98
+ param_filter = nil
99
+ params_hash = {}
100
+
101
+ param_filter = filter == 'all' ? filter : { 'mentionsAccountOrProgram': filter}
102
+
103
+ params_hash['commitment'] = commitment unless blank?(commitment)
104
+ params_hash['encoding'] = encoding unless blank?(encoding)
105
+ params_hash['transactionDetails'] = transaction_details unless blank?(transaction_details)
106
+ params_hash['showRewards'] = show_rewards unless blank?(show_rewards)
107
+
108
+ params << param_filter
109
+ params << params_hash if params_hash.any?
110
+
111
+ subscribe(method, method_params: params, &block)
112
+ end
113
+
114
+ # @see https://docs.solana.com/developing/clients/jsonrpc-api#blockunsubscribe
115
+ # Unsubscribe from block notifications
116
+ #
117
+ # @param subscription_id [Integer]
118
+ #
119
+ # @return [Bool] unsubscribe success message
120
+ def block_unsubscribe(subscription_id)
121
+ method = create_method_name(__method__)
122
+ unsubscribe(method, subscription_id: subscription_id)
123
+ end
124
+
74
125
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#logssubscribe
75
126
  # Subscribe to transaction logging
76
127
  #
@@ -81,15 +132,15 @@ module SolanaRpcRuby
81
132
  #
82
133
  # @return [Integer] Subscription id (needed to unsubscribe)
83
134
  def logs_subscribe(filter, commitment: nil, &block)
84
- method = create_method_name(__method__)
135
+ method = create_method_name(__method__)
85
136
 
86
137
  params = []
87
138
  params_hash = {}
88
139
  params_hash['commitment'] = commitment unless blank?(commitment)
89
-
140
+
90
141
  params << filter
91
142
  params << params_hash
92
-
143
+
93
144
  subscribe(method, method_params: params, &block)
94
145
  end
95
146
 
@@ -107,7 +158,7 @@ module SolanaRpcRuby
107
158
 
108
159
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#programsubscribe
109
160
  # Subscribe to a program to receive notifications when the lamports or data for a given account owned by the program changes
110
- #
161
+ #
111
162
  # @param account_pubkey [String]
112
163
  # @param commitment [String]
113
164
  # @param encoding [String]
@@ -116,13 +167,13 @@ module SolanaRpcRuby
116
167
  #
117
168
  # @return [Integer] Subscription id (needed to unsubscribe)
118
169
  def program_subscribe(
119
- program_id_pubkey,
120
- commitment: nil,
121
- encoding: '',
170
+ program_id_pubkey,
171
+ commitment: nil,
172
+ encoding: '',
122
173
  filters: [],
123
174
  &block
124
175
  )
125
- method = create_method_name(__method__)
176
+ method = create_method_name(__method__)
126
177
 
127
178
  params = []
128
179
  params_hash = {}
@@ -132,7 +183,7 @@ module SolanaRpcRuby
132
183
 
133
184
  params << program_id_pubkey
134
185
  params << params_hash if params_hash.any?
135
-
186
+
136
187
  subscribe(method, method_params: params, &block)
137
188
  end
138
189
 
@@ -149,7 +200,7 @@ module SolanaRpcRuby
149
200
  end
150
201
 
151
202
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#signaturesubscribe
152
- # Subscribe to a transaction signature to receive notification when the transaction is confirmed
203
+ # Subscribe to a transaction signature to receive notification when the transaction is confirmed
153
204
  # On signatureNotification, the subscription is automatically cancelled
154
205
  #
155
206
  # @param transaction_signature [String]
@@ -158,19 +209,19 @@ module SolanaRpcRuby
158
209
  #
159
210
  # @return [Integer] Subscription id (needed to unsubscribe)
160
211
  def signature_subscribe(
161
- transaction_signature,
212
+ transaction_signature,
162
213
  commitment: nil,
163
214
  &block
164
215
  )
165
- method = create_method_name(__method__)
216
+ method = create_method_name(__method__)
166
217
 
167
218
  params = []
168
219
  params_hash = {}
169
220
  params_hash['commitment'] = commitment unless blank?(commitment)
170
-
221
+
171
222
  params << transaction_signature
172
223
  params << params_hash
173
-
224
+
174
225
  subscribe(method, method_params: params, &block)
175
226
  end
176
227
 
@@ -189,11 +240,11 @@ module SolanaRpcRuby
189
240
  # Subscribe to receive notification anytime a slot is processed by the validator
190
241
  #
191
242
  # @param &block [Proc]
192
- #
243
+ #
193
244
  # @return [Integer] Subscription id (needed to unsubscribe)
194
245
  def slot_subscribe(&block)
195
246
  method = create_method_name(__method__)
196
-
247
+
197
248
  subscribe(method, &block)
198
249
  end
199
250
 
@@ -209,16 +260,16 @@ module SolanaRpcRuby
209
260
  end
210
261
 
211
262
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#slotsupdatessubscribe---unstable
212
- #
263
+ #
213
264
  # This subscription is unstable; the format of this subscription may change in the future and it may not always be supported
214
265
  # Subscribe to receive a notification from the validator on a variety of updates on every slot
215
266
  #
216
267
  # @param &block [Proc]
217
- #
268
+ #
218
269
  # @return [Integer] Subscription id (needed to unsubscribe)
219
270
  def slots_updates_subscribe(&block)
220
271
  method = create_method_name(__method__)
221
-
272
+
222
273
  subscribe(method, &block)
223
274
  end
224
275
 
@@ -234,15 +285,15 @@ module SolanaRpcRuby
234
285
  end
235
286
 
236
287
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#rootsubscribe
237
- #
288
+ #
238
289
  # Subscribe to receive notification anytime a new root is set by the validator.
239
290
  #
240
291
  # @param &block [Proc]
241
- #
292
+ #
242
293
  # @return [Integer] Subscription id (needed to unsubscribe)
243
294
  def root_subscribe(&block)
244
295
  method = create_method_name(__method__)
245
-
296
+
246
297
  subscribe(method, &block)
247
298
  end
248
299
 
@@ -258,19 +309,19 @@ module SolanaRpcRuby
258
309
  end
259
310
 
260
311
  # @see https://docs.solana.com/developing/clients/jsonrpc-api#votesubscribe---unstable-disabled-by-default
261
- #
262
- # This subscription is unstable and only available if the validator was started with the --rpc-pubsub-enable-vote-subscription flag.
312
+ #
313
+ # This subscription is unstable and only available if the validator was started with the --rpc-pubsub-enable-vote-subscription flag.
263
314
  # The format of this subscription may change in the future
264
- #
265
- # Subscribe to receive notification anytime a new vote is observed in gossip.
315
+ #
316
+ # Subscribe to receive notification anytime a new vote is observed in gossip.
266
317
  # These votes are pre-consensus therefore there is no guarantee these votes will enter the ledger.
267
318
  #
268
319
  # @param &block [Proc]
269
- #
320
+ #
270
321
  # @return [Integer] Subscription id (needed to unsubscribe)
271
322
  def vote_subscribe(&block)
272
323
  method = create_method_name(__method__)
273
-
324
+
274
325
  subscribe(method, &block)
275
326
  end
276
327
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: solana_rpc_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Block Logic Team
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-01 00:00:00.000000000 Z
11
+ date: 2022-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faye-websocket
@@ -241,7 +241,7 @@ licenses:
241
241
  metadata:
242
242
  documentation_uri: https://www.rubydoc.info/github/Block-Logic/solana-rpc-ruby
243
243
  source_code_uri: https://github.com/Block-Logic/solana-rpc-ruby
244
- post_install_message:
244
+ post_install_message:
245
245
  rdoc_options: []
246
246
  require_paths:
247
247
  - lib
@@ -256,8 +256,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
256
256
  - !ruby/object:Gem::Version
257
257
  version: '0'
258
258
  requirements: []
259
- rubygems_version: 3.0.9
260
- signing_key:
259
+ rubygems_version: 3.2.2
260
+ signing_key:
261
261
  specification_version: 4
262
262
  summary: Ruby wrapper for solana JSON RPC API.
263
263
  test_files: []