From 18d6488c082e1d23ac8dbe1010c581f33cd459b5 Mon Sep 17 00:00:00 2001 From: Luke Imhoff Date: Wed, 6 Jun 2018 13:12:58 -0500 Subject: [PATCH] Check for required timestamps option as soon as possible Not including timestamps is a developer error, so it should be caught as soon as possible to allow the code to be fixed in development. --- apps/explorer/lib/explorer/chain.ex | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index 4428f45e67..7f0b3c3f13 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -1947,11 +1947,13 @@ defmodule Explorer.Chain do when is_map(ecto_schema_module_to_changes_list) and is_list(options) do case ecto_schema_module_to_changes_list do %{Address => addresses_changes} -> + timestamps = Keyword.fetch!(options, :timestamps) + Multi.run(multi, :addresses, fn _ -> insert_addresses( addresses_changes, timeout: options[:addresses][:timeout] || @insert_addresses_timeout, - timestamps: Keyword.fetch!(options, :timestamps) + timestamps: timestamps ) end) @@ -1964,11 +1966,13 @@ defmodule Explorer.Chain do when is_map(ecto_schema_module_to_changes_list) and is_list(options) do case ecto_schema_module_to_changes_list do %{Block => blocks_changes} -> + timestamps = Keyword.fetch!(options, :timestamps) + Multi.run(multi, :blocks, fn _ -> insert_blocks( blocks_changes, timeout: options[:blocks][:timeout] || @insert_blocks_timeout, - timestamps: Keyword.fetch!(options, :timestamps) + timestamps: timestamps ) end) @@ -1981,11 +1985,13 @@ defmodule Explorer.Chain do when is_map(ecto_schema_module_to_changes_list) and is_list(options) do case ecto_schema_module_to_changes_list do %{Transaction => transactions_changes} -> + timestamps = Keyword.fetch!(options, :timestamps) + Multi.run(multi, :transactions, fn _ -> insert_transactions( transactions_changes, timeout: options[:transations][:timeout] || @insert_transactions_timeout, - timestamps: Keyword.fetch!(options, :timestamps) + timestamps: timestamps ) end) @@ -1998,11 +2004,13 @@ defmodule Explorer.Chain do when is_map(ecto_schema_module_to_changes_list) and is_list(options) do case ecto_schema_module_to_changes_list do %{InternalTransaction => internal_transactions_changes} -> + timestamps = Keyword.fetch!(options, :timestamps) + Multi.run(multi, :internal_transactions, fn _ -> insert_internal_transactions( internal_transactions_changes, timeout: options[:internal_transactions][:timeout] || @insert_internal_transactions_timeout, - timestamps: Keyword.fetch!(options, :timestamps) + timestamps: timestamps ) end) @@ -2015,11 +2023,13 @@ defmodule Explorer.Chain do when is_map(ecto_schema_module_to_changes_list) and is_list(options) do case ecto_schema_module_to_changes_list do %{Log => logs_changes} -> + timestamps = Keyword.fetch!(options, :timestamps) + Multi.run(multi, :logs, fn _ -> insert_logs( logs_changes, timeout: options[:logs][:timeout] || @insert_logs_timeout, - timestamps: Keyword.fetch!(options, :timestamps) + timestamps: timestamps ) end)