Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions lib/exth/provider.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ defmodule Exth.Provider do
### Required Options

* `:transport_type` - The transport type to use (`:http`, `:websocket`, or `:custom`)
* `:rpc_url` - The URL of the Ethereum JSON-RPC endpoint
* `:rpc_url` | `:path` - The URL/path of the Ethereum JSON-RPC endpoint
* `:otp_app` - The application name for config lookup (required when using application config)

## Generated Functions
Expand Down Expand Up @@ -390,7 +390,7 @@ defmodule Exth.Provider do

The client is uniquely identified by the combination of:
* transport_type (e.g., :http)
* rpc_url (the endpoint URL)
* rpc_url | path (the endpoint URL)

## Returns

Expand All @@ -417,15 +417,23 @@ defmodule Exth.Provider do
config = Keyword.merge(app_config, @provider_inline_opts)

transport_type = Keyword.fetch!(config, :transport_type)
rpc_url = Keyword.fetch!(config, :rpc_url)

case ClientCache.get_client(transport_type, rpc_url) do
rpc =
case transport_type do
:ipc ->
Keyword.fetch!(config, :path)

_ ->
Keyword.fetch!(config, :rpc_url)
end

case ClientCache.get_client(transport_type, rpc) do
{:ok, client} ->
client

{:error, :not_found} ->
client = Rpc.new_client(transport_type, config)
ClientCache.create_client(transport_type, rpc_url, client)
ClientCache.create_client(transport_type, rpc, client)
end
end
end
Expand Down
29 changes: 29 additions & 0 deletions test/exth/provider_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,35 @@ defmodule Exth.ProviderTest do
InvalidTransportProvider.get_client()
end
end

test "accepts :path when transport_type is :ipc" do
# Create a provider with invalid transport config
defmodule IpcTestProvider do
use Exth.Provider,
otp_app: :exth,
transport_type: :ipc,
path: "/tmp/valid.sock"
end

# Get the client to force compilation
client = IpcTestProvider.get_client()

assert client.transport.path == "/tmp/valid.sock"
end

test "does not accept :path when transport_type is not :ipc" do
# Create a provider with invalid transport config
defmodule InvalidPathTestProvider do
use Exth.Provider,
otp_app: :exth,
transport_type: :custom,
path: "/tmp/valid.sock"
end

assert_raise KeyError, fn ->
InvalidPathTestProvider.get_client()
end
end
end

describe "RPC method generation" do
Expand Down