Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

on-fly fetching of token instances #2762

Merged
merged 6 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [#2665](https://github.com/poanetwork/blockscout/pull/2665) - new menu layout for mobile devices
- [#2663](https://github.com/poanetwork/blockscout/pull/2663) - Fetch address counters in parallel
- [#2642](https://github.com/poanetwork/blockscout/pull/2642) - add ERC721 coin instance page
- [#2762](https://github.com/poanetwork/blockscout/pull/2762) - on-fly fetching of token instances

### Fixes
- [#2767](https://github.com/poanetwork/blockscout/pull/2767) - fix websocket subscriptions with token instances
Expand Down
2 changes: 2 additions & 0 deletions apps/indexer/lib/indexer/block/catchup/fetcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ defmodule Indexer.Block.Catchup.Fetcher do
async_import_replaced_transactions: 1,
async_import_tokens: 1,
async_import_token_balances: 1,
async_import_token_instances: 1,
async_import_uncles: 1,
fetch_and_import_range: 2
]
Expand Down Expand Up @@ -164,6 +165,7 @@ defmodule Indexer.Block.Catchup.Fetcher do
async_import_token_balances(imported)
async_import_uncles(imported)
async_import_replaced_transactions(imported)
async_import_token_instances(imported)
end

defp stream_fetch_and_import(%__MODULE__{blocks_concurrency: blocks_concurrency} = state, sequence)
Expand Down
7 changes: 7 additions & 0 deletions apps/indexer/lib/indexer/block/fetcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ defmodule Indexer.Block.Fetcher do
StakingPools,
Token,
TokenBalance,
TokenInstance,
UncleBlock
}

Expand Down Expand Up @@ -229,6 +230,12 @@ defmodule Indexer.Block.Fetcher do
callback_module.import(state, options_with_broadcast)
end

def async_import_token_instances(%{token_transfers: token_transfers}) do
TokenInstance.async_fetch(token_transfers)
end

def async_import_token_instances(_), do: :ok

def async_import_block_rewards([]), do: :ok

def async_import_block_rewards(errors) when is_list(errors) do
Expand Down
2 changes: 2 additions & 0 deletions apps/indexer/lib/indexer/block/realtime/fetcher.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule Indexer.Block.Realtime.Fetcher do
async_import_replaced_transactions: 1,
async_import_tokens: 1,
async_import_token_balances: 1,
async_import_token_instances: 1,
async_import_uncles: 1,
fetch_and_import_range: 2,
async_import_staking_pools: 0
Expand Down Expand Up @@ -358,6 +359,7 @@ defmodule Indexer.Block.Realtime.Fetcher do
async_import_internal_transactions(imported, Keyword.get(json_rpc_named_arguments, :variant))
async_import_tokens(imported)
async_import_token_balances(imported)
async_import_token_instances(imported)
async_import_uncles(imported)
async_import_replaced_transactions(imported)
async_import_staking_pools()
Expand Down
12 changes: 12 additions & 0 deletions apps/indexer/lib/indexer/fetcher/token_instance.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ defmodule Indexer.Fetcher.TokenInstance do
@doc """
Fetches token instance data asynchronously.
"""
def async_fetch(token_transfers) when is_list(token_transfers) do
data =
token_transfers
|> Enum.reject(fn token_transfer -> is_nil(token_transfer.token_id) end)
|> Enum.map(fn token_transfer ->
%{contract_address_hash: token_transfer.token_contract_address_hash, token_id: token_transfer.token_id}
end)
|> Enum.uniq()

BufferedTask.buffer(__MODULE__, data)
end

def async_fetch(data) do
BufferedTask.buffer(__MODULE__, data)
end
Expand Down