|
|
@ -171,6 +171,12 @@ defmodule Indexer.Block.Reward.Fetcher do |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp add_gas_payments(beneficiaries_params) do |
|
|
|
defp add_gas_payments(beneficiaries_params) do |
|
|
|
|
|
|
|
beneficiaries_params |
|
|
|
|
|
|
|
|> add_validator_rewards() |
|
|
|
|
|
|
|
|> reduce_uncle_rewards() |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp add_validator_rewards(beneficiaries_params) do |
|
|
|
gas_payment_by_block_hash = |
|
|
|
gas_payment_by_block_hash = |
|
|
|
beneficiaries_params |
|
|
|
beneficiaries_params |
|
|
|
|> Stream.filter(&(&1.address_type == :validator)) |
|
|
|
|> Stream.filter(&(&1.address_type == :validator)) |
|
|
@ -193,6 +199,38 @@ defmodule Indexer.Block.Reward.Fetcher do |
|
|
|
end) |
|
|
|
end) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp reduce_uncle_rewards(beneficiaries_params) do |
|
|
|
|
|
|
|
beneficiaries_params |
|
|
|
|
|
|
|
|> Enum.reduce([], fn %{address_type: address_type} = beneficiary, acc -> |
|
|
|
|
|
|
|
current = |
|
|
|
|
|
|
|
if address_type == :uncle do |
|
|
|
|
|
|
|
reward = |
|
|
|
|
|
|
|
Enum.reduce(beneficiaries_params, %Wei{value: 0}, fn %{ |
|
|
|
|
|
|
|
address_type: address_type, |
|
|
|
|
|
|
|
address_hash: address_hash, |
|
|
|
|
|
|
|
block_hash: block_hash |
|
|
|
|
|
|
|
} = current_beneficiary, |
|
|
|
|
|
|
|
reward_acc -> |
|
|
|
|
|
|
|
if address_type == beneficiary.address_type && address_hash == beneficiary.address_hash && |
|
|
|
|
|
|
|
block_hash == beneficiary.block_hash do |
|
|
|
|
|
|
|
{:ok, minted} = Wei.cast(current_beneficiary.reward) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Wei.sum(reward_acc, minted) |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
reward_acc |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%{beneficiary | reward: reward} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
beneficiary |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[current | acc] |
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
|> Enum.uniq() |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp import_block_reward_params(block_rewards_params) when is_list(block_rewards_params) do |
|
|
|
defp import_block_reward_params(block_rewards_params) when is_list(block_rewards_params) do |
|
|
|
addresses_params = AddressExtraction.extract_addresses(%{block_reward_contract_beneficiaries: block_rewards_params}) |
|
|
|
addresses_params = AddressExtraction.extract_addresses(%{block_reward_contract_beneficiaries: block_rewards_params}) |
|
|
|
address_coin_balances_params_set = CoinBalances.params_set(%{beneficiary_params: block_rewards_params}) |
|
|
|
address_coin_balances_params_set = CoinBalances.params_set(%{beneficiary_params: block_rewards_params}) |
|
|
|