Skip to content

Commit

Permalink
Merge pull request blockscout#27 from celo-org/mrsmkl/fix-ci
Browse files Browse the repository at this point in the history
Fixing CI
  • Loading branch information
diminator committed Nov 18, 2019
2 parents 1a92f71 + c3c9465 commit 9fcacb1
Show file tree
Hide file tree
Showing 20 changed files with 116 additions and 73 deletions.
1 change: 1 addition & 0 deletions apps/explorer/lib/explorer/celo/abi_handler.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule Explorer.Celo.AbiHandler do
@moduledoc """
Caching the Celo contract ABIs
"""

use GenServer
Expand Down
96 changes: 55 additions & 41 deletions apps/explorer/lib/explorer/celo/account_reader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ defmodule Explorer.Celo.AccountReader do
"""

require Logger
alias Explorer.Celo.AbiHandler
alias Explorer.SmartContract.Reader

def account_data(%{address: account_address}) do
with data = fetch_account_data(account_address),
{:ok, [name]} <- data["getName"],
data = fetch_account_data(account_address)

with {:ok, [name]} <- data["getName"],
{:ok, [url]} <- data["getMetadataURL"],
{:ok, [is_validator]} <- data["isValidator"],
{:ok, [is_validator_group]} <- data["isValidatorGroup"],
Expand All @@ -32,56 +34,68 @@ defmodule Explorer.Celo.AccountReader do
end

def validator_data(%{address: address}) do
with data = fetch_validator_data(address),
{:ok, [_, affiliation, score]} <- data["getValidator"] do
{:ok,
%{
address: address,
group_address_hash: affiliation,
score: score
}}
else
_ -> :error
data = fetch_validator_data(address)

case data["getValidator"] do
{:ok, [_, affiliation, score]} ->
{:ok,
%{
address: address,
group_address_hash: affiliation,
score: score
}}

_ ->
:error
end
end

def validator_group_data(%{address: address}) do
with data = fetch_validator_group_data(address),
{:ok, [_members, commission, _size_history]} <- data["getValidatorGroup"] do
{:ok,
%{
address: address,
commission: commission
}}
else
_ -> :error
data = fetch_validator_group_data(address)

case data["getValidatorGroup"] do
{:ok, [_members, commission, _size_history]} ->
{:ok,
%{
address: address,
commission: commission
}}

_ ->
:error
end
end

# how to delete them from the table?
def withdrawal_data(%{address: address}) do
with data = fetch_withdrawal_data(address),
{:ok, [values, timestamps]} <- data["getPendingWithdrawals"] do
{:ok,
%{
address: address,
withdrawals:
Enum.map(Enum.zip(values, timestamps), fn {v, t} -> %{address: address, amount: v, timestamp: t} end)
}}
else
_ -> :error
data = fetch_withdrawal_data(address)

case data["getPendingWithdrawals"] do
{:ok, [values, timestamps]} ->
{:ok,
%{
address: address,
withdrawals:
Enum.map(Enum.zip(values, timestamps), fn {v, t} -> %{address: address, amount: v, timestamp: t} end)
}}

_ ->
:error
end
end

def validator_history(%{block_number: _block_number}) do
with data = fetch_validators(),
{:ok, [validators]} <- data["currentValidators"] do
{:ok,
%{
validators: validators
}}
else
_ -> :error
data = fetch_validators()

case data["currentValidators"] do
{:ok, [validators]} ->
{:ok,
%{
validators: validators
}}

_ ->
:error
end
end

Expand Down Expand Up @@ -117,7 +131,7 @@ defmodule Explorer.Celo.AccountReader do
data
end

defp fetch_validators() do
defp fetch_validators do
data =
call_methods([
{:validators, "currentValidators", []}
Expand All @@ -137,7 +151,7 @@ defmodule Explorer.Celo.AccountReader do
end

defp call_methods(methods) do
contract_abi = Explorer.Celo.AbiHandler.get_abi()
contract_abi = AbiHandler.get_abi()

methods
|> Enum.map(&format_request/1)
Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/lib/explorer/chain/celo_account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Explorer.Chain.CeloAccount do

use Explorer.Schema

alias Explorer.Chain.{Hash, Wei, Address}
alias Explorer.Chain.{Address, Hash, Wei}

# @type account_type :: %__MODULE__{ :regular | :validator | :group }

Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/lib/explorer/chain/celo_validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Explorer.Chain.CeloValidator do

use Explorer.Schema

alias Explorer.Chain.{Hash, Wei, Address}
alias Explorer.Chain.{Address, Hash, Wei}

@typedoc """
* `address` - address of the validator.
Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/lib/explorer/chain/celo_validator_group.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Explorer.Chain.CeloValidatorGroup do

use Explorer.Schema

alias Explorer.Chain.{Hash, Wei, Address}
alias Explorer.Chain.{Address, Hash, Wei}

@typedoc """
* `address` - address of the validator.
Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/lib/explorer/chain/celo_validator_history.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Explorer.Chain.CeloValidatorHistory do

use Explorer.Schema

alias Explorer.Chain.{Hash, Address}
alias Explorer.Chain.{Address, Hash}

@typedoc """
* `address` - address of the validator.
Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/lib/explorer/chain/celo_withdrawal.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule Explorer.Chain.CeloWithdrawal do

use Explorer.Schema

alias Explorer.Chain.{Hash, Wei, Address}
alias Explorer.Chain.{Address, Hash, Wei}

@typedoc """
* `address` - address of the validator.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Explorer.Chain.Import.Runner.CeloAccounts do
require Ecto.Query

alias Ecto.{Changeset, Multi, Repo}
alias Explorer.Chain.{Import, CeloAccount}
alias Explorer.Chain.{CeloAccount, Import}
alias Explorer.Chain.Import.Runner.Util

import Ecto.Query, only: [from: 2]
Expand Down Expand Up @@ -62,7 +62,7 @@ defmodule Explorer.Chain.Import.Runner.CeloAccounts do
{:ok, accounts}
end

@spec insert(Repo.t(), [map()], Util.insert_option()) :: {:ok, [CeloAccount.t()]} | {:error, [Changeset.t()]}
@spec insert(Repo.t(), [map()], Util.insert_options()) :: {:ok, [CeloAccount.t()]} | {:error, [Changeset.t()]}
defp insert(repo, changes_list, %{timeout: timeout, timestamps: timestamps} = options) when is_list(changes_list) do
on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Explorer.Chain.Import.Runner.CeloValidatorGroups do
require Ecto.Query

alias Ecto.{Changeset, Multi, Repo}
alias Explorer.Chain.{Import, CeloValidatorGroup}
alias Explorer.Chain.{CeloValidatorGroup, Import}
alias Explorer.Chain.Import.Runner.Util

import Ecto.Query, only: [from: 2]
Expand Down Expand Up @@ -63,7 +63,7 @@ defmodule Explorer.Chain.Import.Runner.CeloValidatorGroups do
{:ok, accounts}
end

@spec insert(Repo.t(), [map()], Util.insert_option()) :: {:ok, [CeloValidatorGroup.t()]} | {:error, [Changeset.t()]}
@spec insert(Repo.t(), [map()], Util.insert_options()) :: {:ok, [CeloValidatorGroup.t()]} | {:error, [Changeset.t()]}
defp insert(repo, changes_list, %{timeout: timeout, timestamps: timestamps} = options) when is_list(changes_list) do
on_conflict = Map.get_lazy(options, :on_conflict, &default_on_conflict/0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Explorer.Chain.Import.Runner.CeloValidatorHistory do
require Ecto.Query

alias Ecto.{Changeset, Multi, Repo}
alias Explorer.Chain.{Import, CeloValidatorHistory}
alias Explorer.Chain.{CeloValidatorHistory, Import}
alias Explorer.Chain.Import.Runner.Util

import Ecto.Query, only: [from: 2]
Expand Down Expand Up @@ -53,7 +53,7 @@ defmodule Explorer.Chain.Import.Runner.CeloValidatorHistory do
# Enforce ShareLocks order (see docs: sharelocks.md)
uniq_changes_list =
changes_list
|> Enum.sort_by(changes_list, &{&1.block_number, &1.index})
|> Enum.sort_by(&{&1.block_number, &1.index})
|> Enum.dedup_by(&{&1.block_number, &1.index})

{:ok, _} =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Explorer.Chain.Import.Runner.CeloValidators do
require Ecto.Query

alias Ecto.{Changeset, Multi, Repo}
alias Explorer.Chain.{Import, CeloValidator}
alias Explorer.Chain.{CeloValidator, Import}
alias Explorer.Chain.Import.Runner.Util

import Ecto.Query, only: [from: 2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Explorer.Chain.Import.Runner.CeloWithdrawals do
require Ecto.Query

alias Ecto.{Changeset, Multi, Repo}
alias Explorer.Chain.{Import, CeloWithdrawal}
alias Explorer.Chain.{CeloWithdrawal, Import}
alias Explorer.Chain.Import.Runner.Util

import Ecto.Query, only: [from: 2]
Expand Down
2 changes: 1 addition & 1 deletion apps/explorer/lib/explorer/chain/import/runner/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Explorer.Chain.Import.Runner.Util do
|> Map.put(:timestamps, timestamps)
end

@type insert_option :: %{
@type insert_options :: %{
optional(:on_conflict) => Import.Runner.on_conflict(),
required(:timeout) => timeout,
required(:timestamps) => Import.timestamps()
Expand Down
11 changes: 8 additions & 3 deletions apps/indexer/lib/indexer/fetcher/celo_account.ex
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
defmodule Indexer.Fetcher.CeloAccount do
@moduledoc """
Fetches Celo accounts.
"""
use Indexer.Fetcher
use Spandex.Decorators

require Logger

alias Indexer.Fetcher.CeloAccount.Supervisor, as: CeloAccountSupervisor
alias Explorer.Chain.CeloAccount
alias Explorer.Chain

alias Explorer.Celo.AccountReader
alias Explorer.Chain
alias Explorer.Chain.CeloAccount

alias Indexer.BufferedTask
alias Indexer.Fetcher.Util

@behaviour BufferedTask

Expand All @@ -36,7 +41,7 @@ defmodule Indexer.Fetcher.CeloAccount do

@doc false
def child_spec([init_options, gen_server_options]) do
Indexer.Fetcher.Util.default_child_spec(init_options, gen_server_options, __MODULE__)
Util.default_child_spec(init_options, gen_server_options, __MODULE__)
end

@impl BufferedTask
Expand Down
10 changes: 7 additions & 3 deletions apps/indexer/lib/indexer/fetcher/celo_validator.ex
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
defmodule Indexer.Fetcher.CeloValidator do
@moduledoc """
Fetches Celo validators.
"""
use Indexer.Fetcher
use Spandex.Decorators

require Logger

alias Indexer.Fetcher.CeloValidator.Supervisor, as: CeloValidatorSupervisor
alias Explorer.Chain.CeloValidator
alias Explorer.Chain

alias Explorer.Celo.AccountReader
alias Indexer.Fetcher.Util
alias Explorer.Chain
alias Explorer.Chain.CeloValidator

alias Indexer.BufferedTask
alias Indexer.Fetcher.Util

@behaviour BufferedTask

Expand Down
11 changes: 8 additions & 3 deletions apps/indexer/lib/indexer/fetcher/celo_validator_group.ex
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
defmodule Indexer.Fetcher.CeloValidatorGroup do
@moduledoc """
Fetches Celo validator groups.
"""
use Indexer.Fetcher
use Spandex.Decorators

require Logger

alias Indexer.Fetcher.CeloValidatorGroup.Supervisor, as: CeloValidatorGroupSupervisor
alias Explorer.Chain.CeloValidatorGroup
alias Explorer.Chain

alias Explorer.Celo.AccountReader
alias Explorer.Chain
alias Explorer.Chain.CeloValidatorGroup

alias Indexer.BufferedTask
alias Indexer.Fetcher.Util

@behaviour BufferedTask

Expand All @@ -36,7 +41,7 @@ defmodule Indexer.Fetcher.CeloValidatorGroup do

@doc false
def child_spec([init_options, gen_server_options]) do
Indexer.Fetcher.Util.default_child_spec(init_options, gen_server_options, __MODULE__)
Util.default_child_spec(init_options, gen_server_options, __MODULE__)
end

@impl BufferedTask
Expand Down
11 changes: 8 additions & 3 deletions apps/indexer/lib/indexer/fetcher/celo_validator_history.ex
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
defmodule Indexer.Fetcher.CeloValidatorHistory do
@moduledoc """
Fetches Celo validator history.
"""
use Indexer.Fetcher
use Spandex.Decorators

require Logger

alias Indexer.Fetcher.CeloValidatorHistory.Supervisor, as: CeloValidatorHistorySupervisor
alias Explorer.Chain.CeloValidatorHistory
alias Explorer.Chain

alias Explorer.Celo.AccountReader
alias Explorer.Chain
alias Explorer.Chain.CeloValidatorHistory

alias Indexer.BufferedTask
alias Indexer.Fetcher.Util

@behaviour BufferedTask

Expand All @@ -36,7 +41,7 @@ defmodule Indexer.Fetcher.CeloValidatorHistory do

@doc false
def child_spec([init_options, gen_server_options]) do
Indexer.Fetcher.Util.default_child_spec(init_options, gen_server_options, __MODULE__)
Util.default_child_spec(init_options, gen_server_options, __MODULE__)
end

@impl BufferedTask
Expand Down

0 comments on commit 9fcacb1

Please sign in to comment.