Class: ERPC::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/erpc_sdk/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, http_adapter: nil, websocket_factory: nil) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/erpc_sdk/client.rb', line 10

def initialize(config, http_adapter: nil, websocket_factory: nil)
  adapter = http_adapter || NetHttpAdapter.new
  solana_transport = HttpJsonRpcTransport.new(
    api_key: config.api_key,
    endpoint: config.endpoint,
    headers: config.headers,
    timeout: config.timeout,
    adapter: adapter
  )
  ethereum_transport = HttpJsonRpcTransport.new(
    api_key: config.api_key,
    endpoint: URLs.with_path(config.endpoint, "/eth"),
    headers: config.headers,
    timeout: config.timeout,
    adapter: adapter
  )
  solana_ws = WebSocketJsonRpcTransport.new(
    URLs.websocket(config.endpoint, config.api_key),
    config.api_key,
    config.timeout,
    connection_factory: websocket_factory
  )
  ethereum_ws = WebSocketJsonRpcTransport.new(
    URLs.websocket(config.endpoint, config.api_key, "/eth"),
    config.api_key,
    config.timeout,
    connection_factory: websocket_factory
  )

  @solana = SolanaClient.new(
    rpc: RpcNamespace.new(
      solana_transport,
      SOLANA_RPC_METHODS,
      parameter_mode: :positional,
      batch_policy: :solana_standard
    ),
    das: RpcNamespace.new(solana_transport, SOLANA_DAS_METHODS, parameter_mode: :named),
    history: RpcNamespace.new(solana_transport, SOLANA_HISTORY_METHODS, parameter_mode: :positional),
    leaders: RpcNamespace.new(
      solana_transport,
      SOLANA_LEADER_METHODS,
      parameter_mode: :positional,
      batch_policy: :unsupported
    ),
    analytics: RpcNamespace.new(
      solana_transport,
      SOLANA_ANALYTICS_METHODS,
      parameter_mode: :positional
    ),
    subscriptions: SolanaSubscriptions.new(solana_ws)
  )
  @ethereum = EthereumClient.new(
    rpc: RpcNamespace.new(ethereum_transport, ETHEREUM_RPC_METHODS, parameter_mode: :positional),
    subscriptions: EthereumSubscriptions.new(ethereum_ws)
  )
  @price = PriceClient.new(
    RestTransport.new(
      credential: config.api_key,
      endpoint: config.endpoint,
      headers: config.headers,
      timeout: config.timeout,
      adapter: adapter
    )
  )
  @account = AccountClient.new(
    RestTransport.new(
      credential: config.api_key,
      endpoint: config.,
      headers: config.headers,
      timeout: config.timeout,
      adapter: adapter
    )
  )
  @usage = UsageClient.new(
    RestTransport.new(
      credential: config.api_key,
      endpoint: config.user_endpoint,
      headers: config.headers,
      timeout: config.timeout,
      adapter: adapter
    )
  )
  @closed = false
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



8
9
10
# File 'lib/erpc_sdk/client.rb', line 8

def 
  @account
end

#ethereumObject (readonly)

Returns the value of attribute ethereum.



8
9
10
# File 'lib/erpc_sdk/client.rb', line 8

def ethereum
  @ethereum
end

#priceObject (readonly)

Returns the value of attribute price.



8
9
10
# File 'lib/erpc_sdk/client.rb', line 8

def price
  @price
end

#solanaObject (readonly)

Returns the value of attribute solana.



8
9
10
# File 'lib/erpc_sdk/client.rb', line 8

def solana
  @solana
end

#usageObject (readonly)

Returns the value of attribute usage.



8
9
10
# File 'lib/erpc_sdk/client.rb', line 8

def usage
  @usage
end

Instance Method Details

#closeObject



95
96
97
98
99
100
101
102
# File 'lib/erpc_sdk/client.rb', line 95

def close
  return if @closed

  @closed = true
  solana.subscriptions.close
  ethereum.subscriptions.close
  nil
end