Merge branch 'master' into ab-smart-contract-constructor-arguments-

pull/1414/head
Ayrat Badykov 6 years ago committed by GitHub
commit 9b25183788
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      apps/explorer/lib/explorer/chain.ex
  2. 22
      apps/explorer/test/explorer/chain_test.exs
  3. 10
      apps/indexer/lib/indexer/block/catchup/fetcher.ex
  4. 38
      apps/indexer/lib/indexer/block/reward/fetcher.ex
  5. 17
      apps/indexer/test/indexer/token_transfer/uncataloged/worker_test.exs

@ -2170,6 +2170,7 @@ defmodule Explorer.Chain do
on: tf.transaction_hash == l.transaction_hash and tf.log_index == l.index, on: tf.transaction_hash == l.transaction_hash and tf.log_index == l.index,
where: l.first_topic == unquote(TokenTransfer.constant()), where: l.first_topic == unquote(TokenTransfer.constant()),
where: is_nil(tf.transaction_hash) and is_nil(tf.log_index), where: is_nil(tf.transaction_hash) and is_nil(tf.log_index),
where: not is_nil(t.block_number),
select: t.block_number, select: t.block_number,
distinct: t.block_number distinct: t.block_number
) )

@ -3477,10 +3477,30 @@ defmodule Explorer.ChainTest do
describe "uncataloged_token_transfer_block_numbers/0" do describe "uncataloged_token_transfer_block_numbers/0" do
test "returns a list of block numbers" do test "returns a list of block numbers" do
log = insert(:token_transfer_log) block = insert(:block)
address = insert(:address)
log =
insert(:token_transfer_log,
transaction:
insert(:transaction,
block_number: block.number,
block_hash: block.hash,
cumulative_gas_used: 0,
gas_used: 0,
index: 0
),
address_hash: address.hash
)
block_number = log.transaction.block_number block_number = log.transaction.block_number
assert {:ok, [^block_number]} = Chain.uncataloged_token_transfer_block_numbers() assert {:ok, [^block_number]} = Chain.uncataloged_token_transfer_block_numbers()
end end
test "does not include transactions without a block_number" do
insert(:token_transfer_log)
assert {:ok, []} = Chain.uncataloged_token_transfer_block_numbers()
end
end end
describe "address_to_balances_by_day/1" do describe "address_to_balances_by_day/1" do

@ -349,9 +349,13 @@ defmodule Indexer.Block.Catchup.Fetcher do
def push_front(block_numbers) do def push_front(block_numbers) do
if Process.whereis(@sequence_name) do if Process.whereis(@sequence_name) do
Enum.reduce_while(block_numbers, :ok, fn block_number, :ok -> Enum.reduce_while(block_numbers, :ok, fn block_number, :ok ->
case Sequence.push_front(@sequence_name, block_number..block_number) do if is_integer(block_number) do
:ok -> {:cont, :ok} case Sequence.push_front(@sequence_name, block_number..block_number) do
{:error, _} = error -> {:halt, error} :ok -> {:cont, :ok}
{:error, _} = error -> {:halt, error}
end
else
Logger.warn(fn -> ["Received a non-integer block number: ", inspect(block_number)] end)
end end
end) end)
else else

@ -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})

@ -28,7 +28,22 @@ defmodule Indexer.TokenTransfer.Uncataloged.WorkerTest do
end end
test "sends message to self when uncataloged token transfers are found" do test "sends message to self when uncataloged token transfers are found" do
log = insert(:token_transfer_log) block = insert(:block)
address = insert(:address)
log =
insert(:token_transfer_log,
transaction:
insert(:transaction,
block_number: block.number,
block_hash: block.hash,
cumulative_gas_used: 0,
gas_used: 0,
index: 0
),
address_hash: address.hash
)
block_number = log.transaction.block_number block_number = log.transaction.block_number
expected_state = %{task_ref: nil, block_numbers: [block_number], retry_interval: 1} expected_state = %{task_ref: nil, block_numbers: [block_number], retry_interval: 1}

Loading…
Cancel
Save