|
|
@ -31,18 +31,18 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
|
Retrieves the query for fetching the number of successful transactions in a week. |
|
|
|
Retrieves the query for fetching the number of successful transactions in a week. |
|
|
|
""" |
|
|
|
""" |
|
|
|
@spec weekly_success_transactions_number_query() :: Ecto.Query.t() |
|
|
|
@spec success_transactions_number_query() :: Ecto.Query.t() |
|
|
|
def weekly_success_transactions_number_query do |
|
|
|
def success_transactions_number_query do |
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
Transaction |
|
|
|
Transaction |
|
|
|
|> where([tx], tx.block_timestamp >= ago(7, "day")) |
|
|
|
|> where([tx], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|> where([tx], tx.block_consensus == true) |
|
|
|
|> where([tx], tx.block_consensus == true) |
|
|
|
|> where([tx], tx.status == ^1) |
|
|
|
|> where([tx], tx.status == ^1) |
|
|
|
|> select([tx], count(tx.hash)) |
|
|
|
|> select([tx], count(tx.hash)) |
|
|
|
else |
|
|
|
else |
|
|
|
Transaction |
|
|
|
Transaction |
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|> where([tx, block], block.timestamp >= ago(7, "day")) |
|
|
|
|> where([tx, block], block.timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|> where([tx, block], block.consensus == true) |
|
|
|
|> where([tx, block], block.consensus == true) |
|
|
|
|> where([tx, block], tx.status == ^1) |
|
|
|
|> where([tx, block], tx.status == ^1) |
|
|
|
|> select([tx, block], count(tx.hash)) |
|
|
|
|> select([tx, block], count(tx.hash)) |
|
|
@ -52,13 +52,13 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
|
Retrieves the query for the number of smart contracts deployed in the current week. |
|
|
|
Retrieves the query for the number of smart contracts deployed in the current week. |
|
|
|
""" |
|
|
|
""" |
|
|
|
@spec weekly_deployed_smart_contracts_number_query() :: Ecto.Query.t() |
|
|
|
@spec deployed_smart_contracts_number_query() :: Ecto.Query.t() |
|
|
|
def weekly_deployed_smart_contracts_number_query do |
|
|
|
def deployed_smart_contracts_number_query do |
|
|
|
transactions_query = |
|
|
|
transactions_query = |
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
Transaction |
|
|
|
Transaction |
|
|
|
|> where([tx], not is_nil(tx.created_contract_address_hash)) |
|
|
|
|> where([tx], not is_nil(tx.created_contract_address_hash)) |
|
|
|
|> where([tx], tx.block_timestamp >= ago(7, "day")) |
|
|
|
|> where([tx], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|> where([tx], tx.block_consensus == true) |
|
|
|
|> where([tx], tx.block_consensus == true) |
|
|
|
|> where([tx], tx.status == ^1) |
|
|
|
|> where([tx], tx.status == ^1) |
|
|
|
|> select([tx], tx.created_contract_address_hash) |
|
|
|
|> select([tx], tx.created_contract_address_hash) |
|
|
@ -67,7 +67,7 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|> where([tx], not is_nil(tx.created_contract_address_hash)) |
|
|
|
|> where([tx], not is_nil(tx.created_contract_address_hash)) |
|
|
|
|> where([tx, block], block.consensus == true) |
|
|
|
|> where([tx, block], block.consensus == true) |
|
|
|
|> where([tx, block], block.timestamp >= ago(7, "day")) |
|
|
|
|> where([tx, block], block.timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|> where([tx, block], tx.status == ^1) |
|
|
|
|> where([tx, block], tx.status == ^1) |
|
|
|
|> select([tx, block], tx.created_contract_address_hash) |
|
|
|
|> select([tx, block], tx.created_contract_address_hash) |
|
|
|
end |
|
|
|
end |
|
|
@ -77,7 +77,7 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
# InternalTransaction |
|
|
|
# InternalTransaction |
|
|
|
# |> join(:inner, [it], transaction in assoc(it, :transaction)) |
|
|
|
# |> join(:inner, [it], transaction in assoc(it, :transaction)) |
|
|
|
# |> where([it, tx], not is_nil(it.created_contract_address_hash)) |
|
|
|
# |> where([it, tx], not is_nil(it.created_contract_address_hash)) |
|
|
|
# |> where([it, tx], tx.block_timestamp >= ago(7, "day")) |
|
|
|
# |> where([it, tx], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
# |> where([it, tx], tx.block_consensus == true) |
|
|
|
# |> where([it, tx], tx.block_consensus == true) |
|
|
|
# |> where([it, tx], tx.status == ^1) |
|
|
|
# |> where([it, tx], tx.status == ^1) |
|
|
|
# |> select([it, tx], it.created_contract_address_hash) |
|
|
|
# |> select([it, tx], it.created_contract_address_hash) |
|
|
@ -97,41 +97,41 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
|
Retrieves the query for the number of verified smart contracts in the current week. |
|
|
|
Retrieves the query for the number of verified smart contracts in the current week. |
|
|
|
""" |
|
|
|
""" |
|
|
|
@spec weekly_verified_smart_contracts_number_query() :: Ecto.Query.t() |
|
|
|
@spec verified_smart_contracts_number_query() :: Ecto.Query.t() |
|
|
|
def weekly_verified_smart_contracts_number_query do |
|
|
|
def verified_smart_contracts_number_query do |
|
|
|
SmartContract |
|
|
|
SmartContract |
|
|
|
|> where([sc], sc.inserted_at >= ago(7, "day")) |
|
|
|
|> where([sc], sc.inserted_at >= ago(^update_period_hours(), "hour")) |
|
|
|
|> select([sc], count(sc.address_hash)) |
|
|
|
|> select([sc], count(sc.address_hash)) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
|
Retrieves the query for the number of new addresses in the current week. |
|
|
|
Retrieves the query for the number of new addresses in the current week. |
|
|
|
""" |
|
|
|
""" |
|
|
|
@spec weekly_new_addresses_number_query() :: Ecto.Query.t() |
|
|
|
@spec new_addresses_number_query() :: Ecto.Query.t() |
|
|
|
def weekly_new_addresses_number_query do |
|
|
|
def new_addresses_number_query do |
|
|
|
Address |
|
|
|
Address |
|
|
|
|> where([a], a.inserted_at >= ago(7, "day")) |
|
|
|
|> where([a], a.inserted_at >= ago(^update_period_hours(), "hour")) |
|
|
|
|> select([a], count(a.hash)) |
|
|
|
|> select([a], count(a.hash)) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
|
Retrieves the query for the number of new tokens detected in the current week. |
|
|
|
Retrieves the query for the number of new tokens detected in the current week. |
|
|
|
""" |
|
|
|
""" |
|
|
|
@spec weekly_new_tokens_number_query() :: Ecto.Query.t() |
|
|
|
@spec new_tokens_number_query() :: Ecto.Query.t() |
|
|
|
def weekly_new_tokens_number_query do |
|
|
|
def new_tokens_number_query do |
|
|
|
Token |
|
|
|
Token |
|
|
|
|> where([token], token.inserted_at >= ago(7, "day")) |
|
|
|
|> where([token], token.inserted_at >= ago(^update_period_hours(), "hour")) |
|
|
|
|> select([token], count(token.contract_address_hash)) |
|
|
|
|> select([token], count(token.contract_address_hash)) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
|
Retrieves the query for the number of new token transfers detected in the current week. |
|
|
|
Retrieves the query for the number of new token transfers detected in the current week. |
|
|
|
""" |
|
|
|
""" |
|
|
|
@spec weekly_new_token_transfers_number_query() :: Ecto.Query.t() |
|
|
|
@spec new_token_transfers_number_query() :: Ecto.Query.t() |
|
|
|
def weekly_new_token_transfers_number_query do |
|
|
|
def new_token_transfers_number_query do |
|
|
|
TokenTransfer |
|
|
|
TokenTransfer |
|
|
|
|> join(:inner, [tt], block in Block, on: block.number == tt.block_number) |
|
|
|
|> join(:inner, [tt], block in Block, on: block.number == tt.block_number) |
|
|
|
|> where([tt, block], block.timestamp >= ago(7, "day")) |
|
|
|
|> where([tt, block], block.timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|> where([tt, block], block.consensus == true) |
|
|
|
|> where([tt, block], block.consensus == true) |
|
|
|
|> select([tt, block], fragment("COUNT(*)")) |
|
|
|
|> select([tt, block], fragment("COUNT(*)")) |
|
|
|
end |
|
|
|
end |
|
|
@ -139,17 +139,17 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
@doc """ |
|
|
|
@doc """ |
|
|
|
Retrieves the query for the number of addresses initiated transactions in the current week. |
|
|
|
Retrieves the query for the number of addresses initiated transactions in the current week. |
|
|
|
""" |
|
|
|
""" |
|
|
|
@spec weekly_simplified_active_addresses_number_query() :: Ecto.Query.t() |
|
|
|
@spec simplified_active_addresses_number_query() :: Ecto.Query.t() |
|
|
|
def weekly_simplified_active_addresses_number_query do |
|
|
|
def simplified_active_addresses_number_query do |
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
Transaction |
|
|
|
Transaction |
|
|
|
|> where([tx], tx.block_timestamp >= ago(7, "day")) |
|
|
|
|> where([tx], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|> where([tx], tx.block_consensus == true) |
|
|
|
|> where([tx], tx.block_consensus == true) |
|
|
|
|> select([tx], fragment("COUNT(DISTINCT(?))", tx.from_address_hash)) |
|
|
|
|> select([tx], fragment("COUNT(DISTINCT(?))", tx.from_address_hash)) |
|
|
|
else |
|
|
|
else |
|
|
|
Transaction |
|
|
|
Transaction |
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|> where([tx, block], block.timestamp >= ago(7, "day")) |
|
|
|
|> where([tx, block], block.timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|> where([tx, block], block.consensus == true) |
|
|
|
|> where([tx, block], block.consensus == true) |
|
|
|
|> select([tx], fragment("COUNT(DISTINCT(?))", tx.from_address_hash)) |
|
|
|
|> select([tx], fragment("COUNT(DISTINCT(?))", tx.from_address_hash)) |
|
|
|
end |
|
|
|
end |
|
|
@ -159,12 +159,12 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
Retrieves the query for the number of active EOA and smart-contract addresses (from/to/contract participated in transactions, internal transactions, token transfers) in the current week. |
|
|
|
Retrieves the query for the number of active EOA and smart-contract addresses (from/to/contract participated in transactions, internal transactions, token transfers) in the current week. |
|
|
|
This query is currently unused since the very low performance: it doesn't return results in 1 hour. |
|
|
|
This query is currently unused since the very low performance: it doesn't return results in 1 hour. |
|
|
|
""" |
|
|
|
""" |
|
|
|
@spec weekly_active_addresses_number_query() :: Ecto.Query.t() |
|
|
|
@spec active_addresses_number_query() :: Ecto.Query.t() |
|
|
|
def weekly_active_addresses_number_query do |
|
|
|
def active_addresses_number_query do |
|
|
|
transactions_query = |
|
|
|
transactions_query = |
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
Transaction |
|
|
|
Transaction |
|
|
|
|> where([tx], tx.block_timestamp >= ago(7, "day")) |
|
|
|
|> where([tx], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|> where([tx], tx.block_consensus == true) |
|
|
|
|> where([tx], tx.block_consensus == true) |
|
|
|
|> distinct(true) |
|
|
|
|> distinct(true) |
|
|
|
|> select([tx], %{ |
|
|
|
|> select([tx], %{ |
|
|
@ -179,7 +179,7 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
else |
|
|
|
else |
|
|
|
Transaction |
|
|
|
Transaction |
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|> where([tx, block], block.timestamp >= ago(7, "day")) |
|
|
|
|> where([tx, block], block.timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|> where([tx, block], block.consensus == true) |
|
|
|
|> where([tx, block], block.consensus == true) |
|
|
|
|> distinct(true) |
|
|
|
|> distinct(true) |
|
|
|
|> select([tx, block], %{ |
|
|
|
|> select([tx, block], %{ |
|
|
@ -197,7 +197,7 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
InternalTransaction |
|
|
|
InternalTransaction |
|
|
|
|> join(:inner, [it], transaction in assoc(it, :transaction)) |
|
|
|
|> join(:inner, [it], transaction in assoc(it, :transaction)) |
|
|
|
|> where([it, tx], tx.block_timestamp >= ago(7, "day")) |
|
|
|
|> where([it, tx], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|> where([it, tx], tx.block_consensus == true) |
|
|
|
|> where([it, tx], tx.block_consensus == true) |
|
|
|
|> where([it, tx], tx.status == ^1) |
|
|
|
|> where([it, tx], tx.status == ^1) |
|
|
|
|> select([it, tx], %{ |
|
|
|
|> select([it, tx], %{ |
|
|
@ -214,7 +214,7 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
InternalTransaction |
|
|
|
InternalTransaction |
|
|
|
|> join(:inner, [it], transaction in assoc(it, :transaction)) |
|
|
|
|> join(:inner, [it], transaction in assoc(it, :transaction)) |
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|> where([it, tx, block], tx.block_timestamp >= ago(7, "day")) |
|
|
|
|> where([it, tx, block], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|> where([it, tx, block], block.consensus == true) |
|
|
|
|> where([it, tx, block], block.consensus == true) |
|
|
|
|> where([it, tx, block], tx.status == ^1) |
|
|
|
|> where([it, tx, block], tx.status == ^1) |
|
|
|
|> select([it, tx, block], %{ |
|
|
|
|> select([it, tx, block], %{ |
|
|
@ -233,7 +233,7 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
if DenormalizationHelper.transactions_denormalization_finished?() do |
|
|
|
TokenTransfer |
|
|
|
TokenTransfer |
|
|
|
|> join(:inner, [tt], transaction in assoc(tt, :transaction)) |
|
|
|
|> join(:inner, [tt], transaction in assoc(tt, :transaction)) |
|
|
|
|> where([tt, tx], tx.block_timestamp >= ago(7, "day")) |
|
|
|
|> where([tt, tx], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|> where([tt, tx], tx.block_consensus == true) |
|
|
|
|> where([tt, tx], tx.block_consensus == true) |
|
|
|
|> where([tt, tx], tx.status == ^1) |
|
|
|
|> where([tt, tx], tx.status == ^1) |
|
|
|
|> select([tt, tx], %{ |
|
|
|
|> select([tt, tx], %{ |
|
|
@ -245,7 +245,7 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
TokenTransfer |
|
|
|
TokenTransfer |
|
|
|
|> join(:inner, [tt], transaction in assoc(tt, :transaction)) |
|
|
|
|> join(:inner, [tt], transaction in assoc(tt, :transaction)) |
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|> join(:inner, [tx], block in assoc(tx, :block)) |
|
|
|
|> where([tt, tx, block], tx.block_timestamp >= ago(7, "day")) |
|
|
|
|> where([tt, tx, block], tx.block_timestamp >= ago(^update_period_hours(), "hour")) |
|
|
|
|> where([tt, tx, block], block.consensus == true) |
|
|
|
|> where([tt, tx, block], block.consensus == true) |
|
|
|
|> where([tt, tx, block], tx.status == ^1) |
|
|
|
|> where([tt, tx, block], tx.status == ^1) |
|
|
|
|> select([tt, tx, block], %{ |
|
|
|
|> select([tt, tx, block], %{ |
|
|
@ -266,4 +266,8 @@ defmodule Explorer.Chain.Metrics.Queries do |
|
|
|
select: fragment("COUNT(DISTINCT ?)", q.address_hash) |
|
|
|
select: fragment("COUNT(DISTINCT ?)", q.address_hash) |
|
|
|
) |
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp update_period_hours do |
|
|
|
|
|
|
|
Application.get_env(:explorer, Explorer.Chain.Metrics)[:update_period_hours] |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|