diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex index 75e1972f17..814496b469 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex @@ -372,8 +372,9 @@ defmodule EthereumJSONRPC do # We can only depend on implementations supporting 64-bit integers: # * Parity only supports u64 (https://github.com/paritytech/jsonrpc-core/blob/f2c61edb817e344d92ab3baf872fa77d1602430a/src/id.rs#L13) + # * Ganache only supports u32 (https://github.com/trufflesuite/ganache-core/issues/190) def unique_request_id do - <> = :crypto.strong_rand_bytes(8) + <> = :crypto.strong_rand_bytes(4) unique_request_id end diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transaction.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transaction.ex index 7d04df023d..4cd2f0191d 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transaction.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transaction.ex @@ -137,6 +137,38 @@ defmodule EthereumJSONRPC.Transaction do } end + # Ganache bug. it return `to: "0x0"` except of `to: null` + def elixir_to_params( + %{ + "to" => "0x0" + } = transaction + ) do + %{transaction | "to" => nil} + |> elixir_to_params() + end + + # Ganache bug. It don't send `r,s,v` transaction fields. + # Fix is in sources but not released yet + def elixir_to_params( + %{ + "blockHash" => _, + "blockNumber" => _, + "from" => _, + "gas" => _, + "gasPrice" => _, + "hash" => _, + "input" => _, + "nonce" => _, + "to" => _, + "transactionIndex" => _, + "value" => _ + } = transaction + ) do + transaction + |> Map.merge(%{"r" => 0, "s" => 0, "v" => 0}) + |> elixir_to_params() + end + @doc """ Extracts `t:EthereumJSONRPC.hash/0` from transaction `params` diff --git a/apps/explorer/config/dev/ganache.exs b/apps/explorer/config/dev/ganache.exs new file mode 100644 index 0000000000..2e66b814ef --- /dev/null +++ b/apps/explorer/config/dev/ganache.exs @@ -0,0 +1,20 @@ +use Mix.Config + +config :explorer, + json_rpc_named_arguments: [ + transport: EthereumJSONRPC.HTTP, + transport_options: [ + http: EthereumJSONRPC.HTTP.HTTPoison, + url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545", + http_options: [recv_timeout: 60_000, timeout: 60_000, hackney: [pool: :ethereum_jsonrpc]] + ], + variant: EthereumJSONRPC.Geth + ], + subscribe_named_arguments: [ + transport: EthereumJSONRPC.WebSocket, + transport_options: [ + web_socket: EthereumJSONRPC.WebSocket.WebSocketClient, + url: System.get_env("ETHEREUM_JSONRPC_WEB_SOCKET_URL") || "ws://localhost:7545" + ], + variant: EthereumJSONRPC.Geth + ] diff --git a/apps/indexer/config/dev/ganache.exs b/apps/indexer/config/dev/ganache.exs new file mode 100644 index 0000000000..eb133dd9d2 --- /dev/null +++ b/apps/indexer/config/dev/ganache.exs @@ -0,0 +1,20 @@ +use Mix.Config + +config :indexer, + block_interval: 5_000, + json_rpc_named_arguments: [ + transport: EthereumJSONRPC.HTTP, + transport_options: [ + http: EthereumJSONRPC.HTTP.HTTPoison, + url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "http://localhost:7545", + http_options: [recv_timeout: 60_000, timeout: 60_000, hackney: [pool: :ethereum_jsonrpc]] + ], + variant: EthereumJSONRPC.Geth + ], + subscribe_named_arguments: [ + transport: EthereumJSONRPC.WebSocket, + transport_options: [ + web_socket: EthereumJSONRPC.WebSocket.WebSocketClient, + url: System.get_env("ETHEREUM_JSONRPC_WEB_SOCKET_URL") || "ws://localhost:7545" + ] + ]