class SolanaRpcRuby::WebsocketsMethodsWrapper

WebsocketsMethodsWrapper class serves as a wrapper for solana JSON RPC API websocket methods. All informations about params: @see docs.solana.com/developing/clients/jsonrpc-api#subscription-websocket

Attributes

cluster[RW]

Cluster where requests will be sent. @return [String]

id[RW]

Unique client-generated identifying integer. @return [Integer]

websocket_client[RW]

Determines which cluster will be used to send requests. @return [SolanaRpcRuby::WebsocketClient]

Public Class Methods

new( websocket_client: WebsocketClient, cluster: SolanaRpcRuby.ws_cluster, id: rand(1...99_999) ) click to toggle source

Initialize object with cluster address where requests will be sent.

@param api_client [ApiClient] @param cluster [String] cluster where requests will be sent. @param id [Integer] unique client-generated identifying integer.

# 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

Public Instance Methods

account_subscribe(account_pubkey, commitment: nil, encoding: '', &block) click to toggle source

@see docs.solana.com/developing/clients/jsonrpc-api#accountsubscribe Subscribe to an account to receive notifications when the lamports or data for a given account public key changes

@param account_pubkey [String] @param commitment [String] @param encoding [String] @param &block [Proc]

@return [Integer] Subscription id (needed to unsubscribe)

# 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) click to toggle source

@see docs.solana.com/developing/clients/jsonrpc-api#accountunsubscribe Unsubscribe from account change notifications

@param subscription_id [Integer]

@return [Bool] unsubscribe success message

# 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
logs_subscribe(filter, commitment: nil, &block) click to toggle source

@see docs.solana.com/developing/clients/jsonrpc-api#logssubscribe Subscribe to transaction logging

@param filter [String]| @option filter [Array] :mentions @param commitment [String] @param &block [Proc]

@return [Integer] Subscription id (needed to unsubscribe)

# File lib/solana_rpc_ruby/websocket_methods_wrapper.rb, line 83
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) click to toggle source

@see docs.solana.com/developing/clients/jsonrpc-api#logsunsubscribe Unsubscribe from transaction logging

@param subscription_id [Integer]

@return [Bool] unsubscribe success message

# File lib/solana_rpc_ruby/websocket_methods_wrapper.rb, line 103
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 ) click to toggle source

@see docs.solana.com/developing/clients/jsonrpc-api#programsubscribe Subscribe to a program to receive notifications when the lamports or data for a given account owned by the program changes

@param account_pubkey [String] @param commitment [String] @param encoding [String] @param filters [Array] @param &block [Proc]

@return [Integer] Subscription id (needed to unsubscribe)

# File lib/solana_rpc_ruby/websocket_methods_wrapper.rb, line 118
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) click to toggle source

@see docs.solana.com/developing/clients/jsonrpc-api#programunsubscribe Unsubscribe from program-owned account change notifications

@param subscription_id [Integer]

@return [Bool] unsubscribe success message

# File lib/solana_rpc_ruby/websocket_methods_wrapper.rb, line 146
def program_unsubscribe(subscription_id)
  method = create_method_name(__method__)
  unsubscribe(method, subscription_id: subscription_id)
end
root_subscribe(&block) click to toggle source

@see docs.solana.com/developing/clients/jsonrpc-api#rootsubscribe

Subscribe to receive notification anytime a new root is set by the validator.

@param &block [Proc]

@return [Integer] Subscription id (needed to unsubscribe)

# File lib/solana_rpc_ruby/websocket_methods_wrapper.rb, line 243
def root_subscribe(&block)
  method = create_method_name(__method__)
  
  subscribe(method, &block)
end
root_unsubscribe(subscription_id) click to toggle source

@see docs.solana.com/developing/clients/jsonrpc-api#rootunsubscribe Unsubscribe from root notifications

@param subscription_id [Integer]

@return [Bool] unsubscribe success message

# File lib/solana_rpc_ruby/websocket_methods_wrapper.rb, line 255
def root_unsubscribe(subscription_id)
  method = create_method_name(__method__)
  unsubscribe(method, subscription_id: subscription_id)
end
signature_subscribe( transaction_signature, commitment: nil, &block ) click to toggle source

@see docs.solana.com/developing/clients/jsonrpc-api#signaturesubscribe Subscribe to a transaction signature to receive notification when the transaction is confirmed On signatureNotification, the subscription is automatically cancelled

@param transaction_signature [String] @param commitment [String] @param &block [Proc]

@return [Integer] Subscription id (needed to unsubscribe)

# File lib/solana_rpc_ruby/websocket_methods_wrapper.rb, line 160
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) click to toggle source

@see docs.solana.com/developing/clients/jsonrpc-api#signatureunsubscribe Unsubscribe from signature confirmation notification

@param subscription_id [Integer]

@return [Bool] unsubscribe success message

# File lib/solana_rpc_ruby/websocket_methods_wrapper.rb, line 183
def signature_unsubscribe(subscription_id)
  method = create_method_name(__method__)
  unsubscribe(method, subscription_id: subscription_id)
end
slot_subscribe(&block) click to toggle source

@see docs.solana.com/developing/clients/jsonrpc-api#slotsubscribe Subscribe to receive notification anytime a slot is processed by the validator

@param &block [Proc]

@return [Integer] Subscription id (needed to unsubscribe)

# File lib/solana_rpc_ruby/websocket_methods_wrapper.rb, line 194
def slot_subscribe(&block)
  method = create_method_name(__method__)
  
  subscribe(method, &block)
end
slot_unsubscribe(subscription_id) click to toggle source

@see docs.solana.com/developing/clients/jsonrpc-api#slotunsubscribe Unsubscribe from slot notifications

@param subscription_id [Integer]

@return [Bool] unsubscribe success message

# File lib/solana_rpc_ruby/websocket_methods_wrapper.rb, line 206
def slot_unsubscribe(subscription_id)
  method = create_method_name(__method__)
  unsubscribe(method, subscription_id: subscription_id)
end
slots_updates_subscribe(&block) click to toggle source

@see docs.solana.com/developing/clients/jsonrpc-api#slotsupdatessubscribe—unstable

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

@param &block [Proc]

@return [Integer] Subscription id (needed to unsubscribe)

# File lib/solana_rpc_ruby/websocket_methods_wrapper.rb, line 219
def slots_updates_subscribe(&block)
  method = create_method_name(__method__)
  
  subscribe(method, &block)
end
slots_updates_unsubscribe(subscription_id) click to toggle source

@see docs.solana.com/developing/clients/jsonrpc-api#slotsupdatesunsubscribe Unsubscribe from slot-update notifications

@param subscription_id [Integer]

@return [Bool] unsubscribe success message

# File lib/solana_rpc_ruby/websocket_methods_wrapper.rb, line 231
def slots_updates_unsubscribe(subscription_id)
  method = create_method_name(__method__)
  unsubscribe(method, subscription_id: subscription_id)
end
vote_subscribe(&block) click to toggle source

@see docs.solana.com/developing/clients/jsonrpc-api#votesubscribe—unstable-disabled-by-default

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.

@param &block [Proc]

@return [Integer] Subscription id (needed to unsubscribe)

# File lib/solana_rpc_ruby/websocket_methods_wrapper.rb, line 271
def vote_subscribe(&block)
  method = create_method_name(__method__)
  
  subscribe(method, &block)
end
vote_unsubscribe(subscription_id) click to toggle source

@see docs.solana.com/developing/clients/jsonrpc-api#rootunsubscribe Unsubscribe from vote notifications

@param subscription_id [Integer]

@return [Bool] unsubscribe success message

# File lib/solana_rpc_ruby/websocket_methods_wrapper.rb, line 283
def vote_unsubscribe(subscription_id)
  method = create_method_name(__method__)
  unsubscribe(method, subscription_id: subscription_id)
end

Private Instance Methods

subscribe(method, method_params: [], &block) click to toggle source
# File lib/solana_rpc_ruby/websocket_methods_wrapper.rb, line 290
def subscribe(method, method_params: [], &block)
  body = create_json_body(method, method_params: method_params)
  @websocket_client.connect(body, &block)
end
unsubscribe(method, subscription_id:) click to toggle source
# File lib/solana_rpc_ruby/websocket_methods_wrapper.rb, line 295
def unsubscribe(method, subscription_id:)
  body = create_json_body(method, method_params: [subscription_id])
  @websocket_client.connect(body)
end