From d17917ce304e5352227c96a62df9452272446bb5 Mon Sep 17 00:00:00 2001 From: Nam Chu Hoai Date: Wed, 3 Oct 2018 17:29:58 -0700 Subject: [PATCH] Allow unsecure WebSocket connections Some setup like ours will have the WebSocket connection in a private network to a local node and thus do not require a secure connection. This change allows to specify ws:// instead of wss:// endpoints as well as reading from the ENV var for the geth config of the indexer Co-authored-by: Luke Imhoff --- .../web_socket/web_socket_client.ex | 16 ++++++++++++++++ apps/indexer/config/dev/geth.exs | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/web_socket/web_socket_client.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/web_socket/web_socket_client.ex index 2d7739942c..469c339804 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/web_socket/web_socket_client.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/web_socket/web_socket_client.ex @@ -55,6 +55,22 @@ defmodule EthereumJSONRPC.WebSocket.WebSocketClient do ) end + def start_link(["ws://" <> _ = url, gen_fsm_options]) when is_list(gen_fsm_options) do + fsm_name = + case Keyword.fetch(gen_fsm_options, :name) do + {:ok, name} when is_atom(name) -> {:local, name} + :error -> :undefined + end + + :websocket_client.start_link( + fsm_name, + url, + __MODULE__, + url, + [] + ) + end + # Client interface @impl WebSocket diff --git a/apps/indexer/config/dev/geth.exs b/apps/indexer/config/dev/geth.exs index 8cb882ec38..5d77bd550a 100644 --- a/apps/indexer/config/dev/geth.exs +++ b/apps/indexer/config/dev/geth.exs @@ -15,6 +15,6 @@ config :indexer, transport: EthereumJSONRPC.WebSocket, transport_options: [ web_socket: EthereumJSONRPC.WebSocket.WebSocketClient, - url: "wss://mainnet.infura.io/ws/8lTvJTKmHPCHazkneJsY" + url: System.get_env("ETHEREUM_JSONRPC_WEB_SOCKET_URL") || "wss://mainnet.infura.io/ws/8lTvJTKmHPCHazkneJsY" ] ]