Skip to content

Commit

Permalink
Credo and format.
Browse files Browse the repository at this point in the history
  • Loading branch information
rkachowski committed Oct 16, 2023
1 parent a707186 commit e0d13ea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule BlockScoutWeb.SmartContractController do
use BlockScoutWeb, :controller

alias BlockScoutWeb.AddressView
#alias Explorer.Celo.SanctionCache
# alias Explorer.Celo.SanctionCache
alias Explorer.Chain
alias Explorer.Chain.SmartContract
alias Explorer.SmartContract.{Reader, Writer}
Expand Down Expand Up @@ -86,7 +86,7 @@ defmodule BlockScoutWeb.SmartContractController do
implementation_address: implementation_address_hash_string,
implementation_abi: implementation_abi,
contract_type: contract_type,
sanctions: ["smart_contract_controller.ex","index"],
sanctions: ["smart_contract_controller.ex", "index"],
action: action
)
else
Expand Down Expand Up @@ -140,9 +140,8 @@ defmodule BlockScoutWeb.SmartContractController do
implementation_address: @burn_address,
implementation_abi: [],
contract_type: contract_type,
sanctions: ["smart_contract_controller.ex","index"],

action: action
sanctions: ["smart_contract_controller.ex", "index"],
action: action
)
else
:error ->
Expand Down
27 changes: 15 additions & 12 deletions apps/explorer/lib/explorer/celo/sanction_cache.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,30 @@ defmodule Explorer.Celo.SanctionCache do
{:noreply, %{state | list: sanction_list}}
end

def fetch_list() do
sanctions_url = :explorer
|> Application.get_env(:celo_sanctions)
|> Keyword.get(:url, "https://celo-org.github.io/compliance/ofac.sanctions.json")
def fetch_list do
sanctions_url =
:explorer
|> Application.get_env(:celo_sanctions)
|> Keyword.get(:url, "https://celo-org.github.io/compliance/ofac.sanctions.json")

Logger.info("Fetching sanctioned address list from #{sanctions_url}")

{:ok, response} = case HTTPoison.get(sanctions_url, [], follow_redirect: true, timeout: 5_000) do
{:ok, %HTTPoison.Response{body: body, status_code: 200}} ->
{:ok, body}
{:ok, response} =
case HTTPoison.get(sanctions_url, [], follow_redirect: true, timeout: 5_000) do
{:ok, %HTTPoison.Response{body: body, status_code: 200}} ->
{:ok, body}

e ->
{:error, inspect(e)}
end
e ->
{:error, inspect(e)}
end

sanction_list = response |> Jason.decode!()

Logger.info("Retrieved #{length(sanction_list)} sanctioned addresses (md5 #{hash_list(sanction_list)}")

sanction_list
end

@doc "printable md5 hash of list contents to assert changed values"
def hash_list(list) do
:crypto.hash(:md5, :erlang.term_to_binary(list)) |> Base.encode16()
Expand All @@ -66,11 +69,11 @@ defmodule Explorer.Celo.SanctionCache do
{:noreply, state, {:continue, :update_with_public_list}}
end

def get_sanction_list() do
def get_sanction_list do
GenServer.call(__MODULE__, :get_sanction_list)
end

def add_address(address) do
GenServer.cast(__MODULE__, {:add_address, address})
end
end
end
3 changes: 1 addition & 2 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,8 @@ config :explorer, :token_id_migration,
concurrency: token_id_migration_concurrency,
batch_size: token_id_migration_batch_size


config :explorer, :celo_sanctions,
url: System.get_env("CELO_SANCTIONS_URL", "https://celo-org.github.io/compliance/ofac.sanctions.json")
url: System.get_env("CELO_SANCTIONS_URL", "https://celo-org.github.io/compliance/ofac.sanctions.json")

###############
### Indexer ###
Expand Down

0 comments on commit e0d13ea

Please sign in to comment.