@ -158,104 +158,119 @@ defmodule BlockScoutWeb.AddressTransactionController do
end
end
def token_transfers_csv ( conn , %{
" address_id " = > address_hash_string ,
" from_period " = > from_period ,
" to_period " = > to_period
} )
when is_binary ( address_hash_string ) do
defp captcha_helper do
:block_scout_web
|> Application . get_env ( :captcha_helper )
end
defp put_resp_params ( conn , file_name ) do
conn
|> put_resp_content_type ( " application/csv " )
|> put_resp_header ( " content-disposition " , " attachment; filename= #{ file_name } " )
|> put_resp_cookie ( " csv-downloaded " , " true " , max_age : 86_400 , http_only : false )
|> send_chunked ( 200 )
end
defp items_csv (
conn ,
%{
" address_id " = > address_hash_string ,
" from_period " = > from_period ,
" to_period " = > to_period ,
" recaptcha_response " = > recaptcha_response
} ,
csv_export_module ,
file_name
)
when is_binary ( address_hash_string ) do
with { :ok , address_hash } <- Chain . string_to_address_hash ( address_hash_string ) ,
{ :ok , address } <- Chain . hash_to_address ( address_hash ) do
{ :ok , address } <- Chain . hash_to_address ( address_hash ) ,
{ :recaptcha , true } <- { :recaptcha , captcha_helper ( ) . recaptcha_passed? ( recaptcha_response ) } do
address
|> AddressTokenTransferCsvExporter . export ( from_period , to_period )
|> Enum . into (
conn
|> put_resp_content_type ( " application/csv " )
|> put_resp_header ( " content-disposition " , " attachment; filename=token_transfers.csv " )
|> send_chunked ( 200 )
)
|> csv_export_module . export ( from_period , to_period )
|> Enum . into ( put_resp_params ( conn , file_name ) )
else
:error ->
unprocessable_entity ( conn )
{ :error , :not_found } ->
not_found ( conn )
{ :recaptcha , false } ->
not_found ( conn )
end
end
def token_transfers_csv ( conn , _ ) , do : not_found ( conn )
defp items_csv ( conn , _ , _ , _ ) , do : not_found ( conn )
def token_transfers_csv ( conn , params ) do
items_csv (
conn ,
%{
" address_id " = > params [ " address_id " ] ,
" from_period " = > params [ " from_period " ] ,
" to_period " = > params [ " to_period " ] ,
" recaptcha_response " = > params [ " recaptcha_response " ]
} ,
AddressTokenTransferCsvExporter ,
" token_transfers.csv "
)
end
def transactions_csv ( conn , %{
" address_id " = > address_hash_string ,
" from_period " = > from_period ,
" to_period " = > to_period
" to_period " = > to_period ,
" recaptcha_response " = > recaptcha_response
} ) do
with { :ok , address_hash } <- Chain . string_to_address_hash ( address_hash_string ) ,
{ :ok , address } <- Chain . hash_to_address ( address_hash ) do
address
|> AddressTransactionCsvExporter . export ( from_period , to_period )
|> Enum . into (
conn
|> put_resp_content_type ( " application/csv " )
|> put_resp_header ( " content-disposition " , " attachment; filename=transactions.csv " )
|> send_chunked ( 200 )
)
else
:error ->
unprocessable_entity ( conn )
{ :error , :not_found } ->
not_found ( conn )
end
items_csv (
conn ,
%{
" address_id " = > address_hash_string ,
" from_period " = > from_period ,
" to_period " = > to_period ,
" recaptcha_response " = > recaptcha_response
} ,
AddressTransactionCsvExporter ,
" transactions.csv "
)
end
def transactions_csv ( conn , _ ) , do : not_found ( conn )
def internal_transactions_csv ( conn , %{
" address_id " = > address_hash_string ,
" from_period " = > from_period ,
" to_period " = > to_period
" to_period " = > to_period ,
" recaptcha_response " = > recaptcha_response
} ) do
with { :ok , address_hash } <- Chain . string_to_address_hash ( address_hash_string ) ,
{ :ok , address } <- Chain . hash_to_address ( address_hash ) do
address
|> AddressInternalTransactionCsvExporter . export ( from_period , to_period )
|> Enum . into (
conn
|> put_resp_content_type ( " application/csv " )
|> put_resp_header ( " content-disposition " , " attachment; filename=internal_transactions.csv " )
|> send_chunked ( 200 )
)
else
:error ->
unprocessable_entity ( conn )
{ :error , :not_found } ->
not_found ( conn )
end
items_csv (
conn ,
%{
" address_id " = > address_hash_string ,
" from_period " = > from_period ,
" to_period " = > to_period ,
" recaptcha_response " = > recaptcha_response
} ,
AddressInternalTransactionCsvExporter ,
" internal_transactions.csv "
)
end
def internal_transactions_csv ( conn , _ ) , do : not_found ( conn )
def logs_csv ( conn , %{ " address_id " = > address_hash_string , " from_period " = > from_period , " to_period " = > to_period } ) do
with { :ok , address_hash } <- Chain . string_to_address_hash ( address_hash_string ) ,
{ :ok , address } <- Chain . hash_to_address ( address_hash ) do
address
|> AddressLogCsvExporter . export ( from_period , to_period )
|> Enum . into (
conn
|> put_resp_content_type ( " application/csv " )
|> put_resp_header ( " content-disposition " , " attachment; filename=logs.csv " )
|> send_chunked ( 200 )
)
else
:error ->
unprocessable_entity ( conn )
{ :error , :not_found } ->
not_found ( conn )
end
def logs_csv ( conn , %{
" address_id " = > address_hash_string ,
" from_period " = > from_period ,
" to_period " = > to_period ,
" recaptcha_response " = > recaptcha_response
} ) do
items_csv (
conn ,
%{
" address_id " = > address_hash_string ,
" from_period " = > from_period ,
" to_period " = > to_period ,
" recaptcha_response " = > recaptcha_response
} ,
AddressLogCsvExporter ,
" logs.csv "
)
end
def logs_csv ( conn , _ ) , do : not_found ( conn )
end