fix credo case warnings

pull/2432/head
Ayrat Badykov 5 years ago
parent 798bffea01
commit 964cb4f6cb
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 16
      apps/block_scout_web/lib/block_scout_web/chain.ex
  2. 8
      apps/block_scout_web/lib/block_scout_web/controllers/api/v1/health_controller.ex
  3. 28
      apps/block_scout_web/lib/block_scout_web/controllers/block_transaction_controller.ex
  4. 10
      apps/explorer/lib/explorer/chain.ex
  5. 16
      apps/explorer/lib/explorer/chain/wei.ex

@ -246,18 +246,22 @@ defmodule BlockScoutWeb.Chain do
end
defp transaction_from_param(param) do
with {:ok, hash} <- string_to_transaction_hash(param) do
case string_to_transaction_hash(param) do
{:ok, hash} ->
hash_to_transaction(hash)
else
:error -> {:error, :not_found}
:error ->
{:error, :not_found}
end
end
defp hash_string_to_block(hash_string) do
with {:ok, hash} <- string_to_block_hash(hash_string) do
case string_to_block_hash(hash_string) do
{:ok, hash} ->
hash_to_block(hash)
else
:error -> {:error, :not_found}
:error ->
{:error, :not_found}
end
end
end

@ -4,10 +4,12 @@ defmodule BlockScoutWeb.API.V1.HealthController do
alias Explorer.Chain
def health(conn, _) do
with {:ok, number, timestamp} <- Chain.last_block_status() do
case Chain.last_block_status() do
{:ok, number, timestamp} ->
send_resp(conn, :ok, result(number, timestamp))
else
status -> send_resp(conn, :internal_server_error, error(status))
status ->
send_resp(conn, :internal_server_error, error(status))
end
end

@ -11,8 +11,8 @@ defmodule BlockScoutWeb.BlockTransactionController do
alias Phoenix.View
def index(conn, %{"block_hash_or_number" => formatted_block_hash_or_number, "type" => "JSON"} = params) do
with {:ok, block} <-
param_block_hash_or_number_to_block(formatted_block_hash_or_number, []) do
case param_block_hash_or_number_to_block(formatted_block_hash_or_number, []) do
{:ok, block} ->
full_options =
Keyword.merge(
[
@ -61,7 +61,7 @@ defmodule BlockScoutWeb.BlockTransactionController do
next_page_path: next_page_path
}
)
else
{:error, {:invalid, :hash}} ->
not_found(conn)
@ -80,8 +80,7 @@ defmodule BlockScoutWeb.BlockTransactionController do
end
def index(conn, %{"block_hash_or_number" => formatted_block_hash_or_number}) do
with {:ok, block} <-
param_block_hash_or_number_to_block(formatted_block_hash_or_number,
case param_block_hash_or_number_to_block(formatted_block_hash_or_number,
necessity_by_association: %{
[miner: :names] => :required,
:uncles => :optional,
@ -89,6 +88,7 @@ defmodule BlockScoutWeb.BlockTransactionController do
:rewards => :optional
}
) do
{:ok, block} ->
block_transaction_count = Chain.block_to_transaction_count(block.hash)
render(
@ -98,7 +98,7 @@ defmodule BlockScoutWeb.BlockTransactionController do
block_transaction_count: block_transaction_count,
current_path: current_path(conn)
)
else
{:error, {:invalid, :hash}} ->
not_found(conn)
@ -117,19 +117,23 @@ defmodule BlockScoutWeb.BlockTransactionController do
end
defp param_block_hash_or_number_to_block("0x" <> _ = param, options) do
with {:ok, hash} <- string_to_block_hash(param) do
case string_to_block_hash(param) do
{:ok, hash} ->
hash_to_block(hash, options)
else
:error -> {:error, {:invalid, :hash}}
:error ->
{:error, {:invalid, :hash}}
end
end
defp param_block_hash_or_number_to_block(number_string, options)
when is_binary(number_string) do
with {:ok, number} <- BlockScoutWeb.Chain.param_to_block_number(number_string) do
case BlockScoutWeb.Chain.param_to_block_number(number_string) do
{:ok, number} ->
number_to_block(number, options)
else
{:error, :invalid} -> {:error, {:invalid, :number}}
{:error, :invalid} ->
{:error, {:invalid, :number}}
end
end

@ -2447,9 +2447,10 @@ defmodule Explorer.Chain do
|> Multi.run(:set_address_verified, &set_address_verified/2)
|> Repo.transaction()
with {:ok, %{smart_contract: smart_contract}} <- insert_result do
case insert_result do
{:ok, %{smart_contract: smart_contract}} ->
{:ok, smart_contract}
else
{:error, :smart_contract, changeset, _} ->
{:error, changeset}
@ -2919,9 +2920,10 @@ defmodule Explorer.Chain do
)
|> Repo.transaction()
with {:ok, %{token: token}} <- insert_result do
case insert_result do
{:ok, %{token: token}} ->
{:ok, token}
else
{:error, :token, changeset, _} ->
{:error, changeset}
end

@ -31,21 +31,25 @@ defmodule Explorer.Chain.Wei do
@impl Ecto.Type
def cast("0x" <> hex_wei) do
with {int_wei, ""} <- Integer.parse(hex_wei, 16) do
case Integer.parse(hex_wei, 16) do
{int_wei, ""} ->
decimal = Decimal.new(int_wei)
{:ok, %__MODULE__{value: decimal}}
else
_ -> :error
_ ->
:error
end
end
@impl Ecto.Type
def cast(string_wei) when is_binary(string_wei) do
with {int_wei, ""} <- Integer.parse(string_wei) do
case Integer.parse(string_wei) do
{int_wei, ""} ->
decimal = Decimal.new(int_wei)
{:ok, %__MODULE__{value: decimal}}
else
_ -> :error
_ ->
:error
end
end

Loading…
Cancel
Save