|
|
@ -48,13 +48,16 @@ defmodule Indexer.Block.UncatalogedRewards.Importer do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp add_gas_payments(beneficiaries) do |
|
|
|
defp add_gas_payments(beneficiaries) do |
|
|
|
Enum.map(beneficiaries, fn beneficiary -> |
|
|
|
gas_payment_by_block_hash = |
|
|
|
case beneficiary.address_type do |
|
|
|
beneficiaries |
|
|
|
:validator -> |
|
|
|
|> Stream.filter(&(&1.address_type == :validator)) |
|
|
|
gas_payment = gas_payment(beneficiary) |
|
|
|
|> Enum.map(& &1.block_hash) |
|
|
|
|
|
|
|
|> Chain.gas_payment_by_block_hash() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Enum.map(beneficiaries, fn %{block_hash: block_hash} = beneficiary -> |
|
|
|
|
|
|
|
case gas_payment_by_block_hash do |
|
|
|
|
|
|
|
%{^block_hash => gas_payment} -> |
|
|
|
{:ok, minted} = Wei.cast(beneficiary.reward) |
|
|
|
{:ok, minted} = Wei.cast(beneficiary.reward) |
|
|
|
|
|
|
|
|
|
|
|
%{beneficiary | reward: Wei.sum(minted, gas_payment)} |
|
|
|
%{beneficiary | reward: Wei.sum(minted, gas_payment)} |
|
|
|
|
|
|
|
|
|
|
|
_ -> |
|
|
|
_ -> |
|
|
@ -63,18 +66,6 @@ defmodule Indexer.Block.UncatalogedRewards.Importer do |
|
|
|
end) |
|
|
|
end) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp gas_payment(beneficiary) do |
|
|
|
|
|
|
|
{:ok, initial} = Wei.cast(0) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
beneficiary.block_number |
|
|
|
|
|
|
|
|> Chain.get_transactions_of_block_number() |
|
|
|
|
|
|
|
|> Enum.reduce(initial, fn %Transaction{gas_price: gas_price, gas_used: gas_used}, acc -> |
|
|
|
|
|
|
|
gas_price |
|
|
|
|
|
|
|
|> Wei.mult(gas_used) |
|
|
|
|
|
|
|
|> Wei.sum(acc) |
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp insert_reward_group([]), do: :empty |
|
|
|
defp insert_reward_group([]), do: :empty |
|
|
|
|
|
|
|
|
|
|
|
defp insert_reward_group(rewards) do |
|
|
|
defp insert_reward_group(rewards) do |
|
|
|