Class: SolanaRpcRuby::WebsocketsMethodsWrapper
- Inherits:
-
Object
- Object
- SolanaRpcRuby::WebsocketsMethodsWrapper
- Includes:
- HelperMethods, RequestBody
- Defined in:
- lib/solana_rpc_ruby/websocket_methods_wrapper.rb
Overview
WebsocketsMethodsWrapper class serves as a wrapper for solana JSON RPC API websocket methods. All informations about params:
Instance Attribute Summary collapse
-
#cluster ⇒ String
Cluster where requests will be sent.
-
#id ⇒ Integer
Unique client-generated identifying integer.
-
#websocket_client ⇒ SolanaRpcRuby::WebsocketClient
Determines which cluster will be used to send requests.
Instance Method Summary collapse
-
#account_subscribe(account_pubkey, commitment: nil, encoding: '', &block) ⇒ Integer
Subscribe to an account to receive notifications when the lamports or data for a given account public key changes.
-
#account_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from account change notifications.
-
#block_subscribe(filter, commitment: nil, encoding: '', transaction_details: '', show_rewards: nil, &block) ⇒ Integer
This subscription is unstable and only available if the validator was started with the –rpc-pubsub-enable-block-subscription flag.
-
#block_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from block notifications.
-
#initialize(websocket_client: WebsocketClient, cluster: SolanaRpcRuby.ws_cluster, id: rand(1...99_999)) ⇒ WebsocketsMethodsWrapper
constructor
Initialize object with cluster address where requests will be sent.
-
#logs_subscribe(filter, commitment: nil, &block) ⇒ Integer
Subscribe to transaction logging.
-
#logs_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from transaction logging.
-
#program_subscribe(program_id_pubkey, commitment: nil, encoding: '', filters: [], &block) ⇒ Integer
Subscribe to a program to receive notifications when the lamports or data for a given account owned by the program changes.
-
#program_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from program-owned account change notifications.
-
#root_subscribe(&block) ⇒ Integer
Subscribe to receive notification anytime a new root is set by the validator.
-
#root_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from root notifications.
-
#signature_subscribe(transaction_signature, commitment: nil, &block) ⇒ Integer
Subscribe to a transaction signature to receive notification when the transaction is confirmed On signatureNotification, the subscription is automatically cancelled.
-
#signature_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from signature confirmation notification.
-
#slot_subscribe(&block) ⇒ Integer
Subscribe to receive notification anytime a slot is processed by the validator.
-
#slot_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from slot notifications.
-
#slots_updates_subscribe(&block) ⇒ Integer
This subscription is unstable; the format of this subscription may change in the future and it may not always be supported Subscribe to receive a notification from the validator on a variety of updates on every slot.
-
#slots_updates_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from slot-update notifications.
-
#vote_subscribe(&block) ⇒ Integer
This subscription is unstable and only available if the validator was started with the –rpc-pubsub-enable-vote-subscription flag.
-
#vote_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from vote notifications.
Methods included from HelperMethods
Methods included from RequestBody
Constructor Details
#initialize(websocket_client: WebsocketClient, cluster: SolanaRpcRuby.ws_cluster, id: rand(1...99_999)) ⇒ WebsocketsMethodsWrapper
Initialize object with cluster address where requests will be sent.
31 32 33 34 35 36 37 38 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 31 def initialize( websocket_client: WebsocketClient, cluster: SolanaRpcRuby.ws_cluster, id: rand(1...99_999) ) @websocket_client = websocket_client.new(cluster: cluster) @id = id end |
Instance Attribute Details
#cluster ⇒ String
Cluster where requests will be sent.
20 21 22 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 20 def cluster @cluster end |
#id ⇒ Integer
Unique client-generated identifying integer.
24 25 26 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 24 def id @id end |
#websocket_client ⇒ SolanaRpcRuby::WebsocketClient
Determines which cluster will be used to send requests.
16 17 18 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 16 def websocket_client @websocket_client end |
Instance Method Details
#account_subscribe(account_pubkey, commitment: nil, encoding: '', &block) ⇒ Integer
Subscribe to an account to receive notifications when the lamports or data for a given account public key changes
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 49 def account_subscribe(account_pubkey, commitment: nil, encoding: '', &block) method = create_method_name(__method__) params = [] params_hash = {} params_hash['commitment'] = commitment unless blank?(commitment) params_hash['encoding'] = encoding unless blank?(encoding) params << account_pubkey params << params_hash if params_hash.any? subscribe(method, method_params: params, &block) end |
#account_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from account change notifications
69 70 71 72 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 69 def account_unsubscribe(subscription_id) method = create_method_name(__method__) unsubscribe(method, subscription_id: subscription_id) end |
#block_subscribe(filter, commitment: nil, encoding: '', transaction_details: '', show_rewards: nil, &block) ⇒ Integer
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
Subscribe to receive notification anytime a new block is Confirmed or Finalized.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 87 def block_subscribe( filter, commitment: nil, encoding: '', transaction_details: '', show_rewards: nil, &block ) method = create_method_name(__method__) params = [] param_filter = nil params_hash = {} param_filter = filter == 'all' ? filter : { 'mentionsAccountOrProgram': filter} params_hash['commitment'] = commitment unless blank?(commitment) params_hash['encoding'] = encoding unless blank?(encoding) params_hash['transactionDetails'] = transaction_details unless blank?(transaction_details) params_hash['showRewards'] = show_rewards unless blank?(show_rewards) params << param_filter params << params_hash if params_hash.any? subscribe(method, method_params: params, &block) end |
#block_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from block notifications
120 121 122 123 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 120 def block_unsubscribe(subscription_id) method = create_method_name(__method__) unsubscribe(method, subscription_id: subscription_id) end |
#logs_subscribe(filter, commitment: nil, &block) ⇒ Integer
Subscribe to transaction logging
134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 134 def logs_subscribe(filter, commitment: nil, &block) method = create_method_name(__method__) params = [] params_hash = {} params_hash['commitment'] = commitment unless blank?(commitment) params << filter params << params_hash subscribe(method, method_params: params, &block) end |
#logs_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from transaction logging
154 155 156 157 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 154 def logs_unsubscribe(subscription_id) method = create_method_name(__method__) unsubscribe(method, subscription_id: subscription_id) end |
#program_subscribe(program_id_pubkey, commitment: nil, encoding: '', filters: [], &block) ⇒ Integer
Subscribe to a program to receive notifications when the lamports or data for a given account owned by the program changes
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 169 def program_subscribe( program_id_pubkey, commitment: nil, encoding: '', filters: [], &block ) method = create_method_name(__method__) params = [] params_hash = {} params_hash['commitment'] = commitment unless blank?(commitment) params_hash['encoding'] = encoding unless blank?(encoding) params_hash['filters'] = filters unless blank?(filters) params << program_id_pubkey params << params_hash if params_hash.any? subscribe(method, method_params: params, &block) end |
#program_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from program-owned account change notifications
197 198 199 200 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 197 def program_unsubscribe(subscription_id) method = create_method_name(__method__) unsubscribe(method, subscription_id: subscription_id) end |
#root_subscribe(&block) ⇒ Integer
Subscribe to receive notification anytime a new root is set by the validator.
294 295 296 297 298 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 294 def root_subscribe(&block) method = create_method_name(__method__) subscribe(method, &block) end |
#root_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from root notifications
306 307 308 309 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 306 def root_unsubscribe(subscription_id) method = create_method_name(__method__) unsubscribe(method, subscription_id: subscription_id) end |
#signature_subscribe(transaction_signature, commitment: nil, &block) ⇒ Integer
Subscribe to a transaction signature to receive notification when the transaction is confirmed On signatureNotification, the subscription is automatically cancelled
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 211 def signature_subscribe( transaction_signature, commitment: nil, &block ) method = create_method_name(__method__) params = [] params_hash = {} params_hash['commitment'] = commitment unless blank?(commitment) params << transaction_signature params << params_hash subscribe(method, method_params: params, &block) end |
#signature_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from signature confirmation notification
234 235 236 237 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 234 def signature_unsubscribe(subscription_id) method = create_method_name(__method__) unsubscribe(method, subscription_id: subscription_id) end |
#slot_subscribe(&block) ⇒ Integer
Subscribe to receive notification anytime a slot is processed by the validator
245 246 247 248 249 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 245 def slot_subscribe(&block) method = create_method_name(__method__) subscribe(method, &block) end |
#slot_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from slot notifications
257 258 259 260 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 257 def slot_unsubscribe(subscription_id) method = create_method_name(__method__) unsubscribe(method, subscription_id: subscription_id) end |
#slots_updates_subscribe(&block) ⇒ Integer
This subscription is unstable; the format of this subscription may change in the future and it may not always be supported Subscribe to receive a notification from the validator on a variety of updates on every slot
270 271 272 273 274 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 270 def slots_updates_subscribe(&block) method = create_method_name(__method__) subscribe(method, &block) end |
#slots_updates_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from slot-update notifications
282 283 284 285 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 282 def slots_updates_unsubscribe(subscription_id) method = create_method_name(__method__) unsubscribe(method, subscription_id: subscription_id) end |
#vote_subscribe(&block) ⇒ Integer
This subscription is unstable and only available if the validator was started with the –rpc-pubsub-enable-vote-subscription flag. The format of this subscription may change in the future
Subscribe to receive notification anytime a new vote is observed in gossip. These votes are pre-consensus therefore there is no guarantee these votes will enter the ledger.
322 323 324 325 326 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 322 def vote_subscribe(&block) method = create_method_name(__method__) subscribe(method, &block) end |
#vote_unsubscribe(subscription_id) ⇒ Bool
Unsubscribe from vote notifications
334 335 336 337 |
# File 'lib/solana_rpc_ruby/websocket_methods_wrapper.rb', line 334 def vote_unsubscribe(subscription_id) method = create_method_name(__method__) unsubscribe(method, subscription_id: subscription_id) end |