add order to response

pull/1933/head
Ayrat Badykov 6 years ago
parent 17a9ee44e7
commit 40f845ad4f
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 38
      apps/block_scout_web/lib/block_scout_web/views/api/rpc/eth_rpc_view.ex

@ -1,19 +1,41 @@
defmodule BlockScoutWeb.API.RPC.EthRPCView do
use BlockScoutWeb, :view
defstruct [:result, :id, :error]
def render("show.json", %{result: result, id: id}) do
%{
"jsonrpc" => "2.0",
"result" => result,
"id" => id
%__MODULE__{
result: result,
id: id
}
end
def render("error.json", %{error: message, id: id}) do
%{
"jsonrpc" => "2.0",
"error" => message,
"id" => id
%__MODULE__{
error: message,
id: id
}
end
defimpl Poison.Encoder, for: BlockScoutWeb.API.RPC.EthRPCView do
def encode(%BlockScoutWeb.API.RPC.EthRPCView{result: result, id: id, error: error}, _options) when is_nil(error) do
"""
{
"jsonrpc": "2.0",
"result": "#{result}",
"id": #{id}
}\n
"""
end
def encode(%BlockScoutWeb.API.RPC.EthRPCView{id: id, error: error}, _options) do
"""
{
"jsonrpc": "2.0",
"error": #{error},
"id": #{id}
}\n
"""
end
end
end

Loading…
Cancel
Save