From d95a217f75b02313b9acc1afa7475be1e46a83cb Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 21 Feb 2019 15:50:57 +0300 Subject: [PATCH] add temporary module to fix failed internal transactions --- .../temporary/failed_created_addresses.ex | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 apps/indexer/lib/indexer/temporary/failed_created_addresses.ex diff --git a/apps/indexer/lib/indexer/temporary/failed_created_addresses.ex b/apps/indexer/lib/indexer/temporary/failed_created_addresses.ex new file mode 100644 index 0000000000..3514ec1430 --- /dev/null +++ b/apps/indexer/lib/indexer/temporary/failed_created_addresses.ex @@ -0,0 +1,42 @@ +defmodule Indexer.Temporary.FailedCreatedAddresses do + @moduledoc """ + Temporary module to fix internal transactions and their created transactions if a parent transaction has failed. + """ + + import Ecto.Query + + alias Explorer.Chain.{InternalTransaction, Transaction} + alias Explorer.Repo + + def run(json_rpc_named_arguments) do + query = + from(it in InternalTransaction, + left_join: t in assoc(it, :transaction), + where: t.error == 0 and not is_nil(it.created_contract_address_hash), + preload: :transaction + ) + + query + |> Repo.all() + |> Enum.each(fn internal_transaction -> + internal_transaction + |> code_entry() + |> Indexer.Code.Fetcher.run(json_rpc_named_arguments) + + internal_transaction.transaction_index + |> transaction_entry() + |> Indexer.InternalTransaction.Fetcher.run(json_rpc_named_arguments) + end) + end + + def code_entry(%InternalTransaction{ + block_number: block_number, + created_contract_address_hash: %{bytes: created_contract_bytes} + }) do + [{block_number, created_contract_bytes}] + end + + def transaction_entry(%Transaction{hash: %{bytes: bytes}, index: index, block_number: block_number}) do + [{block_number, bytes, index}] + end +end