|
|
@ -31,14 +31,14 @@ defmodule Explorer.Chain.AddressTransactionCsvExporter do |
|
|
|
|
|
|
|
|
|
|
|
@paging_options %PagingOptions{page_size: @page_size + 1} |
|
|
|
@paging_options %PagingOptions{page_size: @page_size + 1} |
|
|
|
|
|
|
|
|
|
|
|
@spec export(Address.t()) :: String.t() |
|
|
|
@spec export(Address.t()) :: Enumerable.t() |
|
|
|
def export(address) do |
|
|
|
def export(address) do |
|
|
|
exchange_rate = Market.get_exchange_rate(Explorer.coin()) || Token.null() |
|
|
|
exchange_rate = Market.get_exchange_rate(Explorer.coin()) || Token.null() |
|
|
|
|
|
|
|
|
|
|
|
address |
|
|
|
address |
|
|
|
|> fetch_all_transactions(@paging_options) |
|
|
|
|> fetch_all_transactions(@paging_options) |
|
|
|
|> to_csv_format(address, exchange_rate) |
|
|
|
|> to_csv_format(address, exchange_rate) |
|
|
|
|> dump_data_to_csv() |
|
|
|
|> dump_to_stream() |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp fetch_all_transactions(address, paging_options, acc \\ []) do |
|
|
|
defp fetch_all_transactions(address, paging_options, acc \\ []) do |
|
|
@ -58,61 +58,53 @@ defmodule Explorer.Chain.AddressTransactionCsvExporter do |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp dump_data_to_csv(transactions) do |
|
|
|
defp dump_to_stream(transactions) do |
|
|
|
{:ok, path} = Briefly.create() |
|
|
|
transactions |
|
|
|
|
|
|
|
|> RFC4180.dump_to_stream() |
|
|
|
_ = |
|
|
|
|
|
|
|
transactions |
|
|
|
|
|
|
|
|> RFC4180.dump_to_stream() |
|
|
|
|
|
|
|
|> Stream.into(File.stream!(path)) |
|
|
|
|
|
|
|
|> Enum.to_list() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
path |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp to_csv_format(transactions, address, exchange_rate) do |
|
|
|
defp to_csv_format(transactions, address, exchange_rate) do |
|
|
|
# , "ETHCurrentPrice", "ETHPriceAtTxDate", "TxFee", "Status", "ErrCode"] |
|
|
|
# row_names = [ |
|
|
|
row_names = [ |
|
|
|
# "TxHash", |
|
|
|
"TxHash", |
|
|
|
# "BlockNumber", |
|
|
|
"BlockNumber", |
|
|
|
# "UnixTimestamp", |
|
|
|
"UnixTimestamp", |
|
|
|
# "FromAddress", |
|
|
|
"FromAddress", |
|
|
|
# "ToAddress", |
|
|
|
"ToAddress", |
|
|
|
# "ContractAddress", |
|
|
|
"ContractAddress", |
|
|
|
# "Type", |
|
|
|
"Type", |
|
|
|
# "Value", |
|
|
|
"Value", |
|
|
|
# "Fee", |
|
|
|
"Fee", |
|
|
|
# "Status", |
|
|
|
"Status", |
|
|
|
# "ErrCode", |
|
|
|
"ErrCode", |
|
|
|
# "CurrentPrice", |
|
|
|
"CurrentPrice", |
|
|
|
# "TxDateOpeningPrice", |
|
|
|
"TxDateOpeningPrice", |
|
|
|
# "TxDateClosingPrice" |
|
|
|
"TxDateClosingPrice" |
|
|
|
# ] |
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
# transaction_lists = |
|
|
|
transaction_lists = |
|
|
|
transactions |
|
|
|
transactions |
|
|
|
|> Stream.map(fn transaction -> |
|
|
|
|> Stream.map(fn transaction -> |
|
|
|
{opening_price, closing_price} = price_at_date(transaction.block.timestamp) |
|
|
|
{opening_price, closing_price} = price_at_date(transaction.block.timestamp) |
|
|
|
|
|
|
|
|
|
|
|
[ |
|
|
|
[ |
|
|
|
to_string(transaction.hash), |
|
|
|
to_string(transaction.hash), |
|
|
|
transaction.block_number, |
|
|
|
transaction.block_number, |
|
|
|
transaction.block.timestamp, |
|
|
|
transaction.block.timestamp, |
|
|
|
to_string(transaction.from_address), |
|
|
|
to_string(transaction.from_address), |
|
|
|
to_string(transaction.to_address), |
|
|
|
to_string(transaction.to_address), |
|
|
|
to_string(transaction.created_contract_address), |
|
|
|
to_string(transaction.created_contract_address), |
|
|
|
type(transaction, address), |
|
|
|
type(transaction, address), |
|
|
|
Wei.to(transaction.value, :wei), |
|
|
|
Wei.to(transaction.value, :wei), |
|
|
|
fee(transaction), |
|
|
|
fee(transaction), |
|
|
|
transaction.status, |
|
|
|
transaction.status, |
|
|
|
transaction.error, |
|
|
|
transaction.error, |
|
|
|
exchange_rate.usd_value, |
|
|
|
exchange_rate.usd_value, |
|
|
|
opening_price, |
|
|
|
opening_price, |
|
|
|
closing_price |
|
|
|
closing_price |
|
|
|
] |
|
|
|
] |
|
|
|
end) |
|
|
|
end) |
|
|
|
|
|
|
|
|
|
|
|
# Stream.concat([row_names], transaction_lists) |
|
|
|
Stream.concat([row_names], transaction_lists) |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp type(%Transaction{from_address_hash: from_address}, %Address{hash: from_address}), do: "OUT" |
|
|
|
defp type(%Transaction{from_address_hash: from_address}, %Address{hash: from_address}), do: "OUT" |
|
|
|