Merge pull request #3273 from poanetwork/vb-update-token-metadata-at-tt-parsing

Update token metadata at burn/mint events
pull/3276/head
Victor Baranov 4 years ago committed by GitHub
commit 63af87e4cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 11
      apps/explorer/lib/explorer/chain/address.ex
  3. 8
      apps/explorer/lib/explorer/chain/bridged_token.ex
  4. 8
      apps/explorer/lib/explorer/chain/token.ex
  5. 19
      apps/explorer/lib/explorer/chain/transaction.ex
  6. 34
      apps/indexer/lib/indexer/transform/token_transfers.ex

@ -1,6 +1,7 @@
## Current ## Current
### Features ### Features
- [#3273](https://github.com/poanetwork/blockscout/pull/3273) - Update token metadata at burn/mint events
- [#3268](https://github.com/poanetwork/blockscout/pull/3268) - Token total supply on-demand fetcher - [#3268](https://github.com/poanetwork/blockscout/pull/3268) - Token total supply on-demand fetcher
- [#3261](https://github.com/poanetwork/blockscout/pull/3261) - Bridged tokens table - [#3261](https://github.com/poanetwork/blockscout/pull/3261) - Bridged tokens table

@ -71,6 +71,17 @@ defmodule Explorer.Chain.Address do
:names :names
]} ]}
@derive {Jason.Encoder,
except: [
:__meta__,
:smart_contract,
:decompiled_smart_contracts,
:token,
:contracts_creation_internal_transaction,
:contracts_creation_transaction,
:names
]}
@primary_key {:hash, Hash.Address, autogenerate: false} @primary_key {:hash, Hash.Address, autogenerate: false}
schema "addresses" do schema "addresses" do
field(:fetched_coin_balance, Wei) field(:fetched_coin_balance, Wei)

@ -31,6 +31,14 @@ defmodule Explorer.Chain.BridgedToken do
:updated_at :updated_at
]} ]}
@derive {Jason.Encoder,
except: [
:__meta__,
:home_token_contract_address,
:inserted_at,
:updated_at
]}
@primary_key false @primary_key false
schema "bridged_tokens" do schema "bridged_tokens" do
field(:foreign_chain_id, :decimal) field(:foreign_chain_id, :decimal)

@ -57,6 +57,14 @@ defmodule Explorer.Chain.Token do
:updated_at :updated_at
]} ]}
@derive {Jason.Encoder,
except: [
:__meta__,
:contract_address,
:inserted_at,
:updated_at
]}
@primary_key false @primary_key false
schema "tokens" do schema "tokens" do
field(:name, :string) field(:name, :string)

@ -185,6 +185,25 @@ defmodule Explorer.Chain.Transaction do
:value :value
]} ]}
@derive {Jason.Encoder,
only: [
:block_number,
:cumulative_gas_used,
:error,
:gas,
:gas_price,
:gas_used,
:index,
:created_contract_code_indexed_at,
:input,
:nonce,
:r,
:s,
:v,
:status,
:value
]}
@primary_key {:hash, Hash.Full, autogenerate: false} @primary_key {:hash, Hash.Full, autogenerate: false}
schema "transactions" do schema "transactions" do
field(:block_number, :integer) field(:block_number, :integer)

@ -6,7 +6,11 @@ defmodule Indexer.Transform.TokenTransfers do
require Logger require Logger
alias ABI.TypeDecoder alias ABI.TypeDecoder
alias Explorer.Chain.TokenTransfer alias Explorer.{Chain, Repo}
alias Explorer.Chain.{Token, TokenTransfer}
alias Explorer.Token.MetadataRetriever
@burn_address "0x0000000000000000000000000000000000000000"
@doc """ @doc """
Returns a list of token transfers given a list of logs. Returns a list of token transfers given a list of logs.
@ -54,6 +58,8 @@ defmodule Indexer.Transform.TokenTransfers do
type: "ERC-20" type: "ERC-20"
} }
update_token(log.address_hash, token_transfer)
{token, token_transfer} {token, token_transfer}
end end
@ -79,6 +85,8 @@ defmodule Indexer.Transform.TokenTransfers do
type: "ERC-721" type: "ERC-721"
} }
update_token(log.address_hash, token_transfer)
{token, token_transfer} {token, token_transfer}
end end
@ -104,9 +112,33 @@ defmodule Indexer.Transform.TokenTransfers do
type: "ERC-721" type: "ERC-721"
} }
update_token(log.address_hash, token_transfer)
{token, token_transfer} {token, token_transfer}
end 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)
token_params =
address_hash_string
|> MetadataRetriever.get_functions_of()
token = Repo.get_by(Token, contract_address_hash: address_hash)
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
end
:ok
end
defp truncate_address_hash(nil), do: "0x0000000000000000000000000000000000000000" defp truncate_address_hash(nil), do: "0x0000000000000000000000000000000000000000"
defp truncate_address_hash("0x000000000000000000000000" <> truncated_hash) do defp truncate_address_hash("0x000000000000000000000000" <> truncated_hash) do

Loading…
Cancel
Save