Skip to content

Commit

Permalink
fix: smart contract csv
Browse files Browse the repository at this point in the history
  • Loading branch information
DenSmolonski committed Sep 11, 2024
1 parent b8308e8 commit eee89bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,36 +304,8 @@ defmodule BlockScoutWeb.API.V2.SmartContractController do
defp items_csv(
conn,
%{
"from_period" => from_period,
"to_period" => to_period,
},
csv_export_module
) do
with true <- Application.get_env(:block_scout_web, :recaptcha)[:is_disabled] do
csv_export_module.export(from_period, to_period)
|> Enum.reduce_while(put_resp_params(conn), fn chunk, conn ->
case Conn.chunk(conn, chunk) do
{:ok, conn} ->
{:cont, conn}

{:error, :closed} ->
{:halt, conn}
end
end)
else
:error ->
unprocessable_entity(conn)

false ->
not_found(conn)
end
end

defp items_csv(
conn,
%{
"from_period" => from_period,
"to_period" => to_period,
"from_period" => from_period,
"to_period" => to_period,
"recaptcha_response" => recaptcha_response
},
csv_export_module
Expand All @@ -354,6 +326,7 @@ defmodule BlockScoutWeb.API.V2.SmartContractController do
unprocessable_entity(conn)

{:recaptcha, false} ->
IO.puts("Failed to export CSV due to invalid recaptcha response.")
not_found(conn)
end
end
Expand Down
6 changes: 4 additions & 2 deletions apps/explorer/lib/explorer/chain/smart_contract.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1297,12 +1297,14 @@ defmodule Explorer.Chain.SmartContract do
def verified_contracts_by_date_range(from_period, to_period) do
query = from(contract in __MODULE__)
date_format = "%Y-%m-%d"
from_date = Timex.parse!(from_period, date_format, :strftime) |> Timex.beginning_of_day()
to_date = Timex.parse!(to_period, date_format, :strftime) |> Timex.end_of_day()

query
|> where(
[contract],
contract.inserted_at >= ^Timex.parse!(from_period, date_format, :strftime) and
contract.inserted_at <= ^Timex.parse!(to_period, date_format, :strftime)
contract.inserted_at >= ^from_date and
contract.inserted_at <= ^to_date
)
|> order_by(desc: :id)
|> Chain.select_repo([]).all()
Expand Down

0 comments on commit eee89bc

Please sign in to comment.