Merge pull request #1423 from poanetwork/ab-reward-index

add unique index on address_hash, block_hash and address_type for block_rewards
pull/1439/head
Ayrat Badykov 6 years ago committed by GitHub
commit b6a49bad19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      apps/explorer/priv/repo/migrations/20190208113202_add_unique_index_to_rewards.exs
  2. 20
      apps/indexer/lib/indexer/block/reward/fetcher.ex

@ -0,0 +1,12 @@
defmodule Explorer.Repo.Migrations.AddUniqueIndexToRewards do
use Ecto.Migration
def change do
create(
unique_index(
:block_rewards,
[:address_hash, :block_hash, :address_type]
)
)
end
end

@ -177,14 +177,18 @@ defmodule Indexer.Block.Reward.Fetcher do
|> Enum.map(& &1.block_hash)
|> Chain.gas_payment_by_block_hash()
Enum.map(beneficiaries_params, fn %{block_hash: block_hash} = beneficiary ->
case gas_payment_by_block_hash do
%{^block_hash => gas_payment} ->
{:ok, minted} = Wei.cast(beneficiary.reward)
%{beneficiary | reward: Wei.sum(minted, gas_payment)}
_ ->
beneficiary
Enum.map(beneficiaries_params, fn %{block_hash: block_hash, address_type: address_type} = beneficiary ->
if address_type == :validator do
case gas_payment_by_block_hash do
%{^block_hash => gas_payment} ->
{:ok, minted} = Wei.cast(beneficiary.reward)
%{beneficiary | reward: Wei.sum(minted, gas_payment)}
_ ->
beneficiary
end
else
beneficiary
end
end)
end

Loading…
Cancel
Save