Skip to content

Commit

Permalink
Merge pull request #15 from celo-org/master
Browse files Browse the repository at this point in the history
master
  • Loading branch information
aaitor authored Jan 20, 2020
2 parents eb7c7d8 + 6c6b604 commit 90df5e3
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule BlockScoutWeb.AddressSignedController do
paging_options(params)
)

blocks_plus_one = Chain.get_blocks_handled_by_address(full_options, address_hash)
blocks_plus_one = Chain.get_downtime_by_address(full_options, address_hash)
{blocks, next_page} = split_list_by_page(blocks_plus_one)

next_page_path =
Expand Down
15 changes: 12 additions & 3 deletions apps/block_scout_web/lib/block_scout_web/resolvers/celo_util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@ defmodule BlockScoutWeb.Resolvers.CeloUtil do
alias Explorer.Chain.{CeloAccount, CeloValidator}

def get_usd(%CeloAccount{address: hash}, _, _) do
Chain.get_token_balance(hash, "cUSD")
case Chain.get_token_balance(hash, "cUSD") do
{:error, :not_found} -> {:ok, %{value: Decimal.new(0)}}
{:ok, _} = result -> result
end
end

def get_elected(%CeloValidator{address: hash}, _, _) do
Chain.get_latest_validating_block(hash)
case Chain.get_latest_validating_block(hash) do
{:error, :not_found} -> {:ok, %{value: 0}}
{:ok, _} = result -> result
end
end

def get_latest_block(_, _, _) do
Chain.get_latest_history_block()
end

def get_online(%CeloValidator{address: hash}, _, _) do
Chain.get_latest_active_block(hash)
case Chain.get_latest_active_block(hash) do
{:error, :not_found} -> {:ok, %{value: 0}}
{:ok, _} = result -> result
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ defmodule BlockScoutWeb.Resolvers.CeloValidator do
end

def get_usd(%CeloAccount{address: hash}, _, _) do
Chain.get_token_balance(hash, "cUSD")
case Chain.get_token_balance(hash, "cUSD") do
{:error, :not_found} -> {:ok, %{value: Decimal.new(0)}}
{:ok, _} = result -> result
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
to: address_logs_path(@conn, :index, @address.hash)
) %>
<%= link(
gettext("Blocks Signed"),
gettext("Downtime"),
class: "card-tab #{tab_status("signed", @conn.request_path)}",
"data-test": "signed_tab_link",
to: address_signed_path(@conn, :index, @address.hash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
<a href="#" class="alert-link"><%= gettext "Connection Lost, click to load newer blocks" %></a>
</div>
</div>
<h2 class="card-title"><%=gettext("Blocks Signed")%></h2>
<h2 class="card-title"><%=gettext("Downtime")%></h2>

<%= render BlockScoutWeb.CommonComponentsView, "_pagination_container.html", position: "top", cur_page_number: "1", show_pagination_limit: true, data_next_page_button: true, data_prev_page_button: true %>

<div data-empty-response-message class="tile tile-muted text-center" style="display: none;">
<span><%= gettext "There are no blocks signed by this address." %></span>
<span><%= gettext "There are no downtime blocks for this address." %></span>
</div>
<button data-error-message class="alert alert-danger col-12 text-left" style="display: none;">
<span class="alert-link">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ defmodule BlockScoutWeb.AddressView do
defp tab_name(["validations"]), do: gettext("Blocks Validated")
defp tab_name(["logs"]), do: gettext("Logs")
defp tab_name(["celo"]), do: "Celo Info"
defp tab_name(["signed"]), do: "Blocks Signed"
defp tab_name(["signed"]), do: "Downtime"

def short_hash(%Address{hash: hash}) do
<<
Expand Down
12 changes: 4 additions & 8 deletions apps/block_scout_web/priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -1922,10 +1922,6 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:31
#: lib/block_scout_web/templates/address_signed/index.html.eex:13
msgid "Blocks Signed"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/_tile.html.eex:52
#: lib/block_scout_web/templates/block_signers/index.html.eex:37
msgid "Downtime"
Expand All @@ -1945,11 +1941,11 @@ msgid "Signers"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_signed/index.html.eex:18
msgid "There are no blocks signed by this address."
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:27
msgid "There is no decompiled contracts for this address."
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:27
msgid "There is no decompiled contracts for this address."
#: lib/block_scout_web/templates/address_signed/index.html.eex:18
msgid "There are no downtime blocks for this address."
msgstr ""
12 changes: 4 additions & 8 deletions apps/block_scout_web/priv/gettext/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -1923,10 +1923,6 @@ msgstr ""
#, elixir-format
#: lib/block_scout_web/templates/address/_tabs.html.eex:31
#: lib/block_scout_web/templates/address_signed/index.html.eex:13
msgid "Blocks Signed"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/block/_tile.html.eex:52
#: lib/block_scout_web/templates/block_signers/index.html.eex:37
msgid "Downtime"
Expand All @@ -1946,11 +1942,11 @@ msgid "Signers"
msgstr ""

#, elixir-format
#: lib/block_scout_web/templates/address_signed/index.html.eex:18
msgid "There are no blocks signed by this address."
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:27
msgid "There is no decompiled contracts for this address."
msgstr ""

#, elixir-format, fuzzy
#: lib/block_scout_web/templates/address_decompiled_contract/index.html.eex:27
msgid "There is no decompiled contracts for this address."
#: lib/block_scout_web/templates/address_signed/index.html.eex:18
msgid "There are no downtime blocks for this address."
msgstr ""
8 changes: 7 additions & 1 deletion apps/explorer/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,13 @@ config :explorer, Explorer.Celo.AbiHandler, enabled: true

config :explorer, Explorer.ChainSpec.GenesisData,
enabled: true,
chain_spec_path: System.get_env("CHAIN_SPEC_PATH"),
chain_spec_path:
System.get_env(
"CHAIN_SPEC_PATH",
"https://www.googleapis.com/storage/v1/b/genesis_blocks/o/#{
String.downcase(System.get_env("SUBNETWORK", "Baklava"))
}?alt=media"
),
emission_format: System.get_env("EMISSION_FORMAT", "DEFAULT"),
rewards_contract_address: System.get_env("REWARDS_CONTRACT_ADDRESS", "0xeca443e8e1ab29971a45a9c57a6a9875701698a5")

Expand Down
29 changes: 29 additions & 0 deletions apps/explorer/lib/explorer/chain.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,35 @@ defmodule Explorer.Chain do
|> Repo.all()
end

def get_downtime_by_address(options \\ [], address_hash) when is_list(options) do
necessity_by_association = Keyword.get(options, :necessity_by_association, %{})
paging_options = Keyword.get(options, :paging_options, @default_paging_options)

query =
from(b in Block,
join: h in CeloValidatorHistory,
where: b.number == h.block_number,
where: h.address == ^address_hash,
where: h.online == false,
select: b
)

online_query =
from(
h in CeloValidatorHistory,
where: h.address == ^address_hash,
select: h.online
)

query
|> join_associations(necessity_by_association)
|> page_blocks(paging_options)
|> limit(^paging_options.page_size)
|> order_by(desc: :number)
|> preload(online: ^online_query)
|> Repo.all()
end

@doc """
Counts all of the block validations and groups by the `miner_hash`.
"""
Expand Down
3 changes: 3 additions & 0 deletions apps/explorer/lib/explorer/chain/celo_account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ defmodule Explorer.Chain.CeloAccount do
@validator_group_member_removed "0xc7666a52a66ff601ff7c0d4d6efddc9ac20a34792f6aa003d1804c9d4d5baa57"
@validator_group_member_reordered "0x38819cc49a343985b478d72f531a35b15384c398dd80fd191a14662170f895c6"

@validator_group_epoch_rewards_distributed "0x91ba34d62474c14d6c623cd322f4256666c7a45b7fdaa3378e009d39dfcec2a7"

@validator_epoch_payment_distributed "0x6f5937add2ec38a0fa4959bccd86e3fcc2aafb706cd3e6c0565f87a7b36b9975"

# Events for updating account
Expand Down Expand Up @@ -109,6 +111,7 @@ defmodule Explorer.Chain.CeloAccount do
# Events for updating validator group
def validator_group_events,
do: [
@validator_group_epoch_rewards_distributed,
@validator_group_registered,
@validator_group_deregistered
]
Expand Down
22 changes: 17 additions & 5 deletions apps/explorer/lib/explorer/chain_spec/parity/importer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ defmodule Explorer.ChainSpec.Parity.Importer do
end

def genesis_coin_balances(chain_spec) do
accounts = chain_spec["accounts"]
accounts =
if Map.has_key?(chain_spec, "alloc") do
chain_spec["alloc"]
else
chain_spec["accounts"]
end

if accounts do
parse_accounts(accounts)
Expand Down Expand Up @@ -102,11 +107,18 @@ defmodule Explorer.ChainSpec.Parity.Importer do
|> Stream.filter(fn {_address, map} ->
!is_nil(map["balance"])
end)
|> Stream.map(fn {address, %{"balance" => value}} ->
{:ok, address_hash} = AddressHash.cast(address)
balance = parse_number(value)
|> Stream.map(fn
{"0x" <> address, %{"balance" => value}} ->
{:ok, address_hash} = AddressHash.cast("0x" <> address)
balance = parse_number(value)

%{address_hash: address_hash, value: balance}
%{address_hash: address_hash, value: balance}

{address, %{"balance" => value}} ->
{:ok, address_hash} = AddressHash.cast("0x" <> address)
balance = parse_number(value)

%{address_hash: address_hash, value: balance}
end)
|> Enum.to_list()
end
Expand Down
4 changes: 2 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ config :logger,
backends: [
# all applications and all levels
# :console,
{LoggerJSON, level: :warn},
{LoggerJSON, level: :info},
# all applications, but only errors
{LoggerFileBackend, :error},
# only :ecto, but all levels
Expand All @@ -38,7 +38,7 @@ config :logger_json, :console,
block_number step count error_count shrunk import_id transaction_id)a

config :logger_json, :ecto,
level: :warn,
level: :info,
metadata:
~w(application fetcher request_id first_block_number last_block_number missing_block_range_count missing_block_count
block_number step count error_count shrunk import_id transaction_id)a
Expand Down

0 comments on commit 90df5e3

Please sign in to comment.