From 1f108d767329b38f6c5178cc6ea13437d48b9b41 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 21 Nov 2019 10:46:25 +0300 Subject: [PATCH] set block_hash in logs params --- apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/log.ex | 1 + .../lib/explorer/chain/import/runner/blocks.ex | 2 +- .../lib/explorer/chain/import/runner/logs.ex | 2 +- apps/explorer/lib/explorer/chain/log.ex | 14 ++++++++++++-- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/log.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/log.ex index 52cdae96bd..7eb0ee5bd7 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/log.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/log.ex @@ -98,6 +98,7 @@ defmodule EthereumJSONRPC.Log do block_number: block_number, block_hash: block_hash, data: data, + block_hash: block_hash, index: index, transaction_hash: transaction_hash } diff --git a/apps/explorer/lib/explorer/chain/import/runner/blocks.ex b/apps/explorer/lib/explorer/chain/import/runner/blocks.ex index 444c5a7241..36b426e9ca 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/blocks.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/blocks.ex @@ -9,7 +9,7 @@ defmodule Explorer.Chain.Import.Runner.Blocks do alias Ecto.{Changeset, Multi, Repo} - alias Explorer.Chain.{Address, Block, Import, Log, PendingBlockOperation, Transaction} + alias Explorer.Chain.{Address, Block, Import, PendingBlockOperation, Transaction} alias Explorer.Chain.Block.Reward alias Explorer.Chain.Import.Runner alias Explorer.Chain.Import.Runner.Address.CurrentTokenBalances diff --git a/apps/explorer/lib/explorer/chain/import/runner/logs.ex b/apps/explorer/lib/explorer/chain/import/runner/logs.ex index ddac92a647..0cc8a92b71 100644 --- a/apps/explorer/lib/explorer/chain/import/runner/logs.ex +++ b/apps/explorer/lib/explorer/chain/import/runner/logs.ex @@ -65,7 +65,7 @@ defmodule Explorer.Chain.Import.Runner.Logs do Import.insert_changes_list( repo, ordered_changes_list, - conflict_target: [:transaction_hash, :index], + conflict_target: [:transaction_hash, :index, :block_hash], on_conflict: on_conflict, for: Log, returning: true, diff --git a/apps/explorer/lib/explorer/chain/log.ex b/apps/explorer/lib/explorer/chain/log.ex index 7916b56fb3..7c4daf9692 100644 --- a/apps/explorer/lib/explorer/chain/log.ex +++ b/apps/explorer/lib/explorer/chain/log.ex @@ -6,14 +6,15 @@ defmodule Explorer.Chain.Log do require Logger alias ABI.{Event, FunctionSelector} - alias Explorer.Chain.{Address, ContractMethod, Data, Hash, Transaction} + alias Explorer.Chain.{Address, Block, ContractMethod, Data, Hash, Transaction} alias Explorer.Repo - @required_attrs ~w(address_hash data index transaction_hash)a + @required_attrs ~w(address_hash data block_hash index transaction_hash)a @optional_attrs ~w(first_topic second_topic third_topic fourth_topic type)a @typedoc """ * `address` - address of contract that generate the event + * `block_hash` - hash of the block * `address_hash` - foreign key for `address` * `data` - non-indexed log parameters. * `first_topic` - `topics[0]` @@ -28,6 +29,7 @@ defmodule Explorer.Chain.Log do @type t :: %__MODULE__{ address: %Ecto.Association.NotLoaded{} | Address.t(), address_hash: Hash.Address.t(), + block_hash: Hash.Full.t(), data: Data.t(), first_topic: String.t(), second_topic: String.t(), @@ -59,6 +61,14 @@ defmodule Explorer.Chain.Log do references: :hash, type: Hash.Full ) + + + belongs_to(:block, Block, + foreign_key: :block_hash, + primary_key: true, + references: :hash, + type: Hash.Full + ) end @doc """