Class: Solace::Utils::RPCClient

Inherits:
Object
  • Object
show all
Defined in:
lib/solace/utils/rpc_client.rb

Overview

RPCClient provides Net::HTTP based HTTP client for sending HTTP requests to a Solana RPC node and parsing responses.

Since:

  • 0.0.8

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, open_timeout:, read_timeout:) ⇒ RPCClient

Initialize the connection with a default or custom RPC URL

Parameters:

  • url (String)

    The URL of the Solana RPC node

  • open_timeout (Integer)

    The timeout for opening an HTTP connection

  • read_timeout (Integer)

    The timeout for reading an HTTP response

Since:

  • 0.0.8



33
34
35
36
37
38
39
40
41
# File 'lib/solace/utils/rpc_client.rb', line 33

def initialize(
  url,
  open_timeout:,
  read_timeout:
)
  @url = url
  @open_timeout = open_timeout
  @read_timeout = read_timeout
end

Instance Attribute Details

#open_timeoutObject (readonly)

Since:

  • 0.0.8



22
23
24
# File 'lib/solace/utils/rpc_client.rb', line 22

def open_timeout
  @open_timeout
end

#read_timeoutObject (readonly)

Since:

  • 0.0.8



26
27
28
# File 'lib/solace/utils/rpc_client.rb', line 26

def read_timeout
  @read_timeout
end

#urlObject (readonly)

Since:

  • 0.0.8



18
19
20
# File 'lib/solace/utils/rpc_client.rb', line 18

def url
  @url
end

Instance Method Details

#rpc_request(method, params = []) ⇒ Hash

Sends a JSON-RPC request to the configured Solana RPC server.

]

Parameters:

  • method (String)

    the JSON-RPC method name

  • params (Array) (defaults to: [])

    the parameters for the RPC method

Returns:

  • (Hash)

    the parsed JSON response

Raises:

Since:

  • 0.0.8



54
55
56
57
58
# File 'lib/solace/utils/rpc_client.rb', line 54

def rpc_request(method, params = [])
  request = build_rpc_request(method, params)
  response = perform_http_request(*request)
  handle_rpc_response(response)
end