mana-ethereum/ethereumex

Generic Client Protocol

Closed this issue · 3 comments

It would be great if there was a generic client protocol that could be implemented by specific providers, like http, websocket, and ipc. It seems that a lot of the code for this to happen already exists, but a found a few difficulties when trying to extend this library with a websocket client.

  1. The supervisor tree has the HttpClient hardcoded into it.
  2. When implementing the WebSocketClient module, I wasn't sure where I should put WebSockex.start_link("ws://*url*", __MODULE__, state) since the GenServer details are abstracted away by Ethereumex.Client.Server

This issue probably relates to #8 as well, in that a generic client would allow for a client to simply implement the protocol. Also, I have Ethereumex.HttpClient hardcoded in a bunch of places in ExW3, which isn't ideal.

Ideally the API would be similar to web3.js where the user can manually set the provider url and type.

@hswick yes, it's a known issue. we can make client adapter configurable, for example, with option in config.exs.

defmodule Ethereumex do
  use Application
  @moduledoc File.read!("#{__DIR__}/../README.md")
  
  @adapter Application.get_env(:ethereumex, :adapter)

  def start(_type, _args) do
    import Supervisor.Spec, warn: false

    children = [
      worker(@adapter, [])
    ]

    opts = [strategy: :one_for_one, name: Ethereumex.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

HttpClient is being started by default because currently there are no other adapters.

By the way, you can email me or we can set up a call to discuss this issue, I'm happy to help

@ayrat555 awesome, thank you for the quick response. I have no doubts that we can find a solution.

I'm hoping to have more free time next month. I would love to setup a call and chat about next steps then.

I think this issue is resolved