Fix fields/variables names

staking
Vadim 5 years ago committed by Victor Baranov
parent 227d3857fd
commit 954d3dc96d
  1. 2
      apps/block_scout_web/lib/block_scout_web/chain.ex
  2. 2
      apps/block_scout_web/lib/block_scout_web/channels/stakes_channel.ex
  3. 2
      apps/block_scout_web/lib/block_scout_web/templates/stakes/_rows.html.eex
  4. 4
      apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_modal_pool_info.html.eex
  5. 2
      apps/block_scout_web/lib/block_scout_web/templates/stakes/_stakes_progress.html.eex
  6. 6
      apps/explorer/lib/explorer/chain.ex
  7. 2
      apps/explorer/lib/explorer/chain/import/runner/staking_pools.ex
  8. 6
      apps/explorer/lib/explorer/chain/staking_pool.ex
  9. 14
      apps/explorer/lib/explorer/staking/contract_reader.ex
  10. 4
      apps/explorer/lib/explorer/staking/contract_state.ex
  11. 22
      apps/explorer/lib/explorer/staking/stake_snapshotting.ex
  12. 2
      apps/explorer/priv/repo/migrations/20190521104412_create_staking_pools.exs

@ -283,7 +283,7 @@ defmodule BlockScoutWeb.Chain do
%{"block_number" => block_number} %{"block_number" => block_number}
end end
defp paging_params(%StakingPool{staking_address_hash: address_hash, staked_ratio: value}) do defp paging_params(%StakingPool{staking_address_hash: address_hash, stakes_ratio: value}) do
%{"address_hash" => address_hash, "value" => Decimal.to_string(value)} %{"address_hash" => address_hash, "value" => Decimal.to_string(value)}
end end

@ -41,7 +41,7 @@ defmodule BlockScoutWeb.StakesChannel do
token = ContractState.get(:token) token = ContractState.get(:token)
html = html =
View.render_to_string(StakesView, "_stakes_modal_validator_info.html", View.render_to_string(StakesView, "_stakes_modal_pool_info.html",
validator: pool, validator: pool,
delegator: delegator, delegator: delegator,
average_block_time: average_block_time, average_block_time: average_block_time,

@ -23,7 +23,7 @@
<%= if @pools_type == :inactive do %> <%= if @pools_type == :inactive do %>
<%= if @pool.is_banned, do: gettext("Yes"), else: gettext("No") %> <%= if @pool.is_banned, do: gettext("Yes"), else: gettext("No") %>
<% else %> <% else %>
<%= if @pool.staked_ratio, do: "#{@pool.staked_ratio}%" %> <%= if @pool.stakes_ratio, do: "#{@pool.stakes_ratio}%" %>
<% end %> <% end %>
</div> </div>
<div class="col-2 stakes-td stakes-cell"> <div class="col-2 stakes-td stakes-cell">

@ -41,12 +41,12 @@
render BlockScoutWeb.StakesView, render BlockScoutWeb.StakesView,
"_stakes_validator_info_item.html", "_stakes_validator_info_item.html",
title: gettext("Stakes Ratio"), title: gettext("Stakes Ratio"),
value: if(@validator.staked_ratio, do: "#{@validator.staked_ratio}%") value: if(@validator.stakes_ratio, do: "#{@validator.stakes_ratio}%")
%> %>
<%= <%=
render BlockScoutWeb.StakesView, render BlockScoutWeb.StakesView,
"_stakes_validator_info_item.html", "_stakes_validator_info_item.html",
title: gettext("Reward Percent"), title: gettext("Share of Pool’s Reward"),
value: "#{@validator.block_reward_ratio}%" value: "#{@validator.block_reward_ratio}%"
%> %>
<%= <%=

@ -24,7 +24,7 @@
<div class="stakes-progress-info"> <div class="stakes-progress-info">
<h2 class="stakes-progress-info-title"><%= gettext("Stakes Ratio") %></h2> <h2 class="stakes-progress-info-title"><%= gettext("Stakes Ratio") %></h2>
<p class="stakes-progress-info-value"> <p class="stakes-progress-info-value">
<%= @pool.staked_ratio %>% <%= @pool.stakes_ratio %>%
</p> </p>
</div> </div>
<div class="stakes-progress-info"> <div class="stakes-progress-info">

@ -4781,15 +4781,15 @@ defmodule Explorer.Chain do
paging_query = paging_query =
base_query base_query
|> limit(^paging_options.page_size) |> limit(^paging_options.page_size)
|> order_by(desc: :staked_ratio, asc: :staking_address_hash) |> order_by(desc: :stakes_ratio, asc: :staking_address_hash)
case paging_options.key do case paging_options.key do
{value, address_hash} -> {value, address_hash} ->
where( where(
paging_query, paging_query,
[p], [p],
p.staked_ratio < ^value or p.stakes_ratio < ^value or
(p.staked_ratio == ^value and p.staking_address_hash > ^address_hash) (p.stakes_ratio == ^value and p.staking_address_hash > ^address_hash)
) )
_ -> _ ->

@ -131,7 +131,7 @@ defmodule Explorer.Chain.Import.Runner.StakingPools do
are_delegators_banned: fragment("EXCLUDED.are_delegators_banned"), are_delegators_banned: fragment("EXCLUDED.are_delegators_banned"),
likelihood: fragment("EXCLUDED.likelihood"), likelihood: fragment("EXCLUDED.likelihood"),
block_reward_ratio: fragment("EXCLUDED.block_reward_ratio"), block_reward_ratio: fragment("EXCLUDED.block_reward_ratio"),
staked_ratio: fragment("EXCLUDED.staked_ratio"), stakes_ratio: fragment("EXCLUDED.stakes_ratio"),
validator_reward_ratio: fragment("EXCLUDED.validator_reward_ratio"), validator_reward_ratio: fragment("EXCLUDED.validator_reward_ratio"),
snapshotted_validator_reward_ratio: pool.snapshotted_validator_reward_ratio, snapshotted_validator_reward_ratio: pool.snapshotted_validator_reward_ratio,
self_staked_amount: fragment("EXCLUDED.self_staked_amount"), self_staked_amount: fragment("EXCLUDED.self_staked_amount"),

@ -25,7 +25,7 @@ defmodule Explorer.Chain.StakingPool do
are_delegators_banned: boolean, are_delegators_banned: boolean,
likelihood: Decimal.t(), likelihood: Decimal.t(),
block_reward_ratio: Decimal.t(), block_reward_ratio: Decimal.t(),
staked_ratio: Decimal.t(), stakes_ratio: Decimal.t(),
validator_reward_ratio: Decimal.t(), validator_reward_ratio: Decimal.t(),
snapshotted_validator_reward_ratio: Decimal.t(), snapshotted_validator_reward_ratio: Decimal.t(),
self_staked_amount: Decimal.t(), self_staked_amount: Decimal.t(),
@ -41,7 +41,7 @@ defmodule Explorer.Chain.StakingPool do
@attrs ~w( @attrs ~w(
is_active delegators_count total_staked_amount self_staked_amount snapshotted_total_staked_amount snapshotted_self_staked_amount is_validator is_active delegators_count total_staked_amount self_staked_amount snapshotted_total_staked_amount snapshotted_self_staked_amount is_validator
was_validator_count is_banned are_delegators_banned ban_reason was_banned_count banned_until banned_delegators_until likelihood was_validator_count is_banned are_delegators_banned ban_reason was_banned_count banned_until banned_delegators_until likelihood
staked_ratio validator_reward_ratio snapshotted_validator_reward_ratio staking_address_hash mining_address_hash block_reward_ratio stakes_ratio validator_reward_ratio snapshotted_validator_reward_ratio staking_address_hash mining_address_hash block_reward_ratio
is_unremovable is_unremovable
)a )a
@req_attrs ~w( @req_attrs ~w(
@ -61,7 +61,7 @@ defmodule Explorer.Chain.StakingPool do
field(:are_delegators_banned, :boolean, default: false) field(:are_delegators_banned, :boolean, default: false)
field(:likelihood, :decimal) field(:likelihood, :decimal)
field(:block_reward_ratio, :decimal) field(:block_reward_ratio, :decimal)
field(:staked_ratio, :decimal) field(:stakes_ratio, :decimal)
field(:validator_reward_ratio, :decimal) field(:validator_reward_ratio, :decimal)
field(:snapshotted_validator_reward_ratio, :decimal) field(:snapshotted_validator_reward_ratio, :decimal)
field(:self_staked_amount, :decimal) field(:self_staked_amount, :decimal)

@ -16,7 +16,7 @@ defmodule Explorer.Staking.ContractReader do
staking_allowed: {:staking, "areStakeAndWithdrawAllowed", []}, staking_allowed: {:staking, "areStakeAndWithdrawAllowed", []},
active_pools: {:staking, "getPools", []}, active_pools: {:staking, "getPools", []},
inactive_pools: {:staking, "getPoolsInactive", []}, inactive_pools: {:staking, "getPoolsInactive", []},
pools_likely: {:staking, "getPoolsToBeElected", []}, pools_to_be_elected: {:staking, "getPoolsToBeElected", []},
pools_likelihood: {:staking, "getPoolsLikelihood", []}, pools_likelihood: {:staking, "getPoolsLikelihood", []},
validators: {:validator_set, "getValidators", []}, validators: {:validator_set, "getValidators", []},
unremovable_validator: {:validator_set, "unremovableValidator", []}, unremovable_validator: {:validator_set, "unremovableValidator", []},
@ -50,13 +50,13 @@ defmodule Explorer.Staking.ContractReader do
] ]
end end
def delegator_requests(pool_address, delegator_address) do def delegator_requests(pool_staking_address, delegator_address) do
[ [
stake_amount: {:staking, "stakeAmount", [pool_address, delegator_address]}, stake_amount: {:staking, "stakeAmount", [pool_staking_address, delegator_address]},
ordered_withdraw: {:staking, "orderedWithdrawAmount", [pool_address, delegator_address]}, ordered_withdraw: {:staking, "orderedWithdrawAmount", [pool_staking_address, delegator_address]},
max_withdraw_allowed: {:staking, "maxWithdrawAllowed", [pool_address, delegator_address]}, max_withdraw_allowed: {:staking, "maxWithdrawAllowed", [pool_staking_address, delegator_address]},
max_ordered_withdraw_allowed: {:staking, "maxWithdrawOrderAllowed", [pool_address, delegator_address]}, max_ordered_withdraw_allowed: {:staking, "maxWithdrawOrderAllowed", [pool_staking_address, delegator_address]},
ordered_withdraw_epoch: {:staking, "orderWithdrawEpoch", [pool_address, delegator_address]} ordered_withdraw_epoch: {:staking, "orderWithdrawEpoch", [pool_staking_address, delegator_address]}
] ]
end end

@ -173,7 +173,7 @@ defmodule Explorer.Staking.ContractState do
[likelihood_values, total_likelihood] = global_responses.pools_likelihood [likelihood_values, total_likelihood] = global_responses.pools_likelihood
likelihood = likelihood =
global_responses.pools_likely global_responses.pools_to_be_elected # array of pool addresses (staking addresses)
|> Enum.zip(likelihood_values) |> Enum.zip(likelihood_values)
|> Enum.into(%{}) |> Enum.into(%{})
@ -217,7 +217,7 @@ defmodule Explorer.Staking.ContractState do
%{ %{
staking_address_hash: staking_address, staking_address_hash: staking_address,
delegators_count: length(staking_response.active_delegators), delegators_count: length(staking_response.active_delegators),
staked_ratio: stakes_ratio:
if staking_response.is_active do if staking_response.is_active do
ratio(staking_response.total_staked_amount, staked_total) ratio(staking_response.total_staked_amount, staked_total)
end, end,

@ -26,7 +26,7 @@ defmodule Explorer.Staking.StakeSnapshotting do
pool_staking_addresses = pool_staking_addresses =
pool_mining_addresses pool_mining_addresses
|> Enum.map(&transform_requests/1) |> Enum.map(&staking_by_mining_requests/1)
|> ContractReader.perform_grouped_requests(pool_mining_addresses, contracts, abi) |> ContractReader.perform_grouped_requests(pool_mining_addresses, contracts, abi)
|> Enum.flat_map(fn {_, value} -> value end) |> Enum.flat_map(fn {_, value} -> value end)
|> Enum.map(fn {_key, staking_address_hash} -> decode_data(staking_address_hash) end) |> Enum.map(fn {_key, staking_address_hash} -> decode_data(staking_address_hash) end)
@ -134,9 +134,9 @@ defmodule Explorer.Staking.StakeSnapshotting do
}) })
end end
def transform_requests(minig_address) do def staking_by_mining_requests(mining_address) do
[ [
staking_address: {:validator_set, "stakingByMiningAddress", [minig_address]} staking_address: {:validator_set, "stakingByMiningAddress", [mining_address]}
] ]
end end
@ -152,14 +152,14 @@ defmodule Explorer.Staking.StakeSnapshotting do
] ]
end end
defp delegator_requests(pool_address, delegator_address, block_number) do defp delegator_requests(pool_staking_address, delegator_address, block_number) do
[ [
stake_amount: {:staking, "stakeAmount", [pool_address, delegator_address]}, stake_amount: {:staking, "stakeAmount", [pool_staking_address, delegator_address]},
snapshotted_stake_amount: {:staking, "stakeAmount", [pool_address, delegator_address], block_number - 1}, snapshotted_stake_amount: {:staking, "stakeAmount", [pool_staking_address, delegator_address], block_number - 1},
ordered_withdraw: {:staking, "orderedWithdrawAmount", [pool_address, delegator_address]}, ordered_withdraw: {:staking, "orderedWithdrawAmount", [pool_staking_address, delegator_address]},
max_withdraw_allowed: {:staking, "maxWithdrawAllowed", [pool_address, delegator_address]}, max_withdraw_allowed: {:staking, "maxWithdrawAllowed", [pool_staking_address, delegator_address]},
max_ordered_withdraw_allowed: {:staking, "maxWithdrawOrderAllowed", [pool_address, delegator_address]}, max_ordered_withdraw_allowed: {:staking, "maxWithdrawOrderAllowed", [pool_staking_address, delegator_address]},
ordered_withdraw_epoch: {:staking, "orderWithdrawEpoch", [pool_address, delegator_address]} ordered_withdraw_epoch: {:staking, "orderWithdrawEpoch", [pool_staking_address, delegator_address]}
] ]
end end
@ -182,7 +182,7 @@ defmodule Explorer.Staking.StakeSnapshotting do
are_delegators_banned: pool.are_delegators_banned, are_delegators_banned: pool.are_delegators_banned,
likelihood: pool.likelihood, likelihood: pool.likelihood,
block_reward_ratio: pool.block_reward_ratio, block_reward_ratio: pool.block_reward_ratio,
staked_ratio: pool.staked_ratio, stakes_ratio: pool.stakes_ratio,
validator_reward_ratio: pool.validator_reward_ratio, validator_reward_ratio: pool.validator_reward_ratio,
ban_reason: pool.ban_reason, ban_reason: pool.ban_reason,
was_banned_count: pool.was_banned_count, was_banned_count: pool.was_banned_count,

@ -14,7 +14,7 @@ defmodule Explorer.Repo.Migrations.CreateStakingPools do
add(:was_banned_count, :integer) add(:was_banned_count, :integer)
add(:banned_until, :bigint) add(:banned_until, :bigint)
add(:likelihood, :decimal, precision: 5, scale: 2) add(:likelihood, :decimal, precision: 5, scale: 2)
add(:staked_ratio, :decimal, precision: 5, scale: 2) add(:stakes_ratio, :decimal, precision: 5, scale: 2)
add(:staking_address_hash, :bytea) add(:staking_address_hash, :bytea)
add(:mining_address_hash, :bytea) add(:mining_address_hash, :bytea)

Loading…
Cancel
Save