mimic eth response

pull/1933/head
Ayrat Badykov 6 years ago
parent f46970cab0
commit 70b1a6dd35
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 5
      apps/block_scout_web/lib/block_scout_web/controllers/api/rpc/block_controller.ex
  2. 12
      apps/block_scout_web/lib/block_scout_web/views/api/rpc/block_view.ex

@ -24,9 +24,10 @@ defmodule BlockScoutWeb.API.RPC.BlockController do
end
end
def eth_block_number(conn, _params) do
def eth_block_number(conn, params) do
id = Map.get(params, "id", 1)
max_block_number = Chain.fetch_max_block_number()
render(conn, :eth_block_number, number: max_block_number)
render(conn, :eth_block_number, number: max_block_number, id: id)
end
end

@ -1,7 +1,7 @@
defmodule BlockScoutWeb.API.RPC.BlockView do
use BlockScoutWeb, :view
alias BlockScoutWeb.API.RPC.RPCView
alias BlockScoutWeb.API.RPC.{EthRPCView, RPCView}
alias Explorer.Chain.{Hash, Wei}
def render("block_reward.json", %{block: block, reward: reward}) do
@ -22,15 +22,15 @@ defmodule BlockScoutWeb.API.RPC.BlockView do
RPCView.render("show.json", data: data)
end
def render("eth_block_number.json", %{number: number}) do
data = %{
"blockNumber" => to_string(number)
}
def render("eth_block_number.json", %{number: number, id: id}) do
result = integer_to_hex(number)
RPCView.render("show.json", data: data)
EthRPCView.render("show.json", %{result: result, id: id})
end
def render("error.json", %{error: error}) do
RPCView.render("error.json", error: error)
end
defp integer_to_hex(integer), do: Integer.to_string(integer, 16)
end

Loading…
Cancel
Save