@ -18,9 +18,24 @@ defmodule Indexer.Transform.TokenTransfers do
def parse ( logs ) do
initial_acc = %{ tokens : [ ] , token_transfers : [ ] }
logs
|> Enum . filter ( & ( &1 . first_topic == unquote ( TokenTransfer . constant ( ) ) ) )
|> Enum . reduce ( initial_acc , & do_parse / 2 )
token_transfers_from_logs =
logs
|> Enum . filter ( & ( &1 . first_topic == unquote ( TokenTransfer . constant ( ) ) ) )
|> Enum . reduce ( initial_acc , & do_parse / 2 )
token_transfers = token_transfers_from_logs . token_transfers
token_transfers
|> Enum . filter ( fn token_transfer ->
token_transfer . to_address_hash == @burn_address || token_transfer . from_address_hash == @burn_address
end )
|> Enum . map ( fn token_transfer ->
token_transfer . token_contract_address_hash
end )
|> Enum . dedup ( )
|> Enum . each ( & update_token / 1 )
token_transfers_from_logs
end
defp do_parse ( log , %{ tokens : tokens , token_transfers : token_transfers } = acc ) do
@ -58,8 +73,6 @@ defmodule Indexer.Transform.TokenTransfers do
type : " ERC-20 "
}
update_token ( log . address_hash , token_transfer )
{ token , token_transfer }
end
@ -85,8 +98,6 @@ defmodule Indexer.Transform.TokenTransfers do
type : " ERC-721 "
}
update_token ( log . address_hash , token_transfer )
{ token , token_transfer }
end
@ -112,28 +123,26 @@ defmodule Indexer.Transform.TokenTransfers do
type : " ERC-721 "
}
update_token ( log . address_hash , token_transfer )
{ token , token_transfer }
end
defp update_token ( address_hash_string , token_transfer ) do
if token_transfer . to_address_hash == @burn_address || token_transfer . from_address_hash == @burn_address do
{ :ok , address_hash } = Chain . string_to_address_hash ( address_hash_string )
defp update_token ( nil ) , do : :ok
defp update_token ( address_hash_string ) do
{ :ok , address_hash } = Chain . string_to_address_hash ( address_hash_string )
token_params =
address_hash_string
|> MetadataRetriever . get_functions_of ( )
token_params =
address_hash_string
|> MetadataRetriever . get_functions_of ( )
token = Repo . get_by ( Token , contract_address_hash : address_hash )
token = Repo . get_by ( Token , contract_address_hash : address_hash )
if token do
token_to_update =
token
|> Repo . preload ( [ :contract_address ] )
if token do
token_to_update =
token
|> Repo . preload ( [ :contract_address ] )
{ :ok , _ } = Chain . update_token ( %{ token_to_update | updated_at : DateTime . utc_now ( ) } , token_params )
end
{ :ok , _ } = Chain . update_token ( %{ token_to_update | updated_at : DateTime . utc_now ( ) } , token_params )
end
:ok