Skip to content

Commit

Permalink
Merge branch 'master' into eruizgar91/w48-upstream-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Enrique Ruiz committed Dec 2, 2021
2 parents 893eab7 + 46897e6 commit 1b65355
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ defmodule BlockScoutWeb.Resolvers.TokenTransfer do
|> Connection.from_query(&Repo.all/1, connection_args, options(args))
end

def get_by(%{transaction_hash: hash}, args, _) do
hash
|> GraphQL.token_tx_transfers_query_by_txhash()
|> Connection.from_query(&Repo.all/1, args, options(args))
end

def get_by(_, %{address_hash: address_hash} = args, _) do
connection_args = Map.take(args, [:after, :before, :first, :last])

address_hash
|> GraphQL.token_tx_transfers_query_by_address()
|> Connection.from_query(&Repo.all/1, connection_args, options(args))
end

def get_by(_, args, _) do
connection_args = Map.take(args, [:after, :before, :first, :last])

GraphQL.token_tx_transfers_query()
|> Connection.from_query(&Repo.all/1, connection_args, options(args))
end

defp options(%{before: _}), do: []

defp options(%{count: count}), do: [count: count]
Expand Down
15 changes: 15 additions & 0 deletions apps/block_scout_web/lib/block_scout_web/schema/types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ defmodule BlockScoutWeb.Schema.Types do
CeloValidator,
CeloValidatorGroup,
InternalTransaction,
TokenTransfer,
Transaction
}

Expand Down Expand Up @@ -326,6 +327,7 @@ defmodule BlockScoutWeb.Schema.Types do
node object(:celo_transfer, id_fetcher: &celo_transfer_id_fetcher/2) do
field(:value, :decimal)
field(:token, :string)
field(:token_address, :string)
field(:block_number, :integer)
field(:from_address_hash, :address_hash)
field(:to_address_hash, :address_hash)
Expand Down Expand Up @@ -371,6 +373,19 @@ defmodule BlockScoutWeb.Schema.Types do
last * child_complexity
end)
end

connection field(:token_transfer, node_type: :celo_transfer) do
arg(:count, :integer)
resolve(&TokenTransfer.get_by/3)

complexity(fn
%{first: first}, child_complexity ->
first * child_complexity

%{last: last}, child_complexity ->
last * child_complexity
end)
end
end

@desc """
Expand Down
55 changes: 54 additions & 1 deletion apps/explorer/lib/explorer/graphql.ex
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,22 @@ defmodule Explorer.GraphQL do
|> order_by([transaction: t], desc: t.block_number, asc: t.nonce)
end

def token_tx_transfers_query_by_txhash(tx_hash) do
query = token_tx_transfers_query()

from(
t in subquery(query),
where: t.transaction_hash == ^tx_hash,
order_by: [t.log_index]
)
end

def token_tx_transfers_query_by_address(address_hash) do
token_tx_transfers_query()
|> where([t], t.from_address_hash == ^address_hash or t.to_address_hash == ^address_hash)
|> order_by([transaction: t], desc: t.block_number, asc: t.nonce)
end

def txtransfers_query do
token_contract_names = Util.get_token_contract_names()

Expand All @@ -270,7 +286,7 @@ defmodule Explorer.GraphQL do
gas_used: tx.gas_used,
gas_price: tx.gas_price,
fee_currency: tx.gas_currency_hash,
fee_token: fragment("coalesce(?, 'cGLD')", token.symbol),
fee_token: fragment("coalesce(?, 'CELO')", token.symbol),
gateway_fee: tx.gateway_fee,
gateway_fee_recipient: tx.gas_fee_recipient_hash,
timestamp: b.timestamp,
Expand All @@ -284,6 +300,42 @@ defmodule Explorer.GraphQL do
)
end

def token_tx_transfers_query do
from(
tt in TokenTransfer,
inner_join: tx in Transaction,
as: :transaction,
on: tx.hash == tt.transaction_hash,
inner_join: b in Block,
on: tt.block_number == b.number,
left_join: wf in CeloWalletAccounts,
on: tt.from_address_hash == wf.wallet_address_hash,
left_join: wt in CeloWalletAccounts,
on: tt.to_address_hash == wt.wallet_address_hash,
left_join: token in Token,
on: tt.token_contract_address_hash == token.contract_address_hash,
select: %{
gas_used: tx.gas_used,
gas_price: tx.gas_price,
timestamp: b.timestamp,
input: tx.input,
transaction_hash: tt.transaction_hash,
from_address_hash: tt.from_address_hash,
to_address_hash: tt.to_address_hash,
from_account_hash: wf.account_address_hash,
to_account_hash: wt.account_address_hash,
log_index: tt.log_index,
value: tt.amount,
comment: tt.comment,
token: token.symbol,
token_address: token.contract_address_hash,
nonce: tx.nonce,
block_number: tt.block_number
},
order_by: [desc: tt.block_number, desc: tt.amount, desc: tt.log_index]
)
end

def celo_tx_transfers_query do
token_contract_names = Util.get_token_contract_names()
token_symbols = Util.get_token_contract_symbols()
Expand Down Expand Up @@ -329,6 +381,7 @@ defmodule Explorer.GraphQL do
value: tt.amount,
comment: tt.comment,
token: tkn.token_symbol,
token_address: tt.token_contract_address_hash,
nonce: tx.nonce,
block_number: tt.block_number
},
Expand Down
7 changes: 6 additions & 1 deletion apps/indexer/lib/indexer/fetcher/celo_epoch_rewards.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ defmodule Indexer.Fetcher.CeloEpochRewards do

@doc false
def child_spec([init_options, gen_server_options]) do
Util.default_child_spec(init_options, gen_server_options, __MODULE__)
init_options_with_polling =
init_options
|> Keyword.put(:poll, true)
|> Keyword.put(:poll_interval, :timer.minutes(60))

Util.default_child_spec(init_options_with_polling, gen_server_options, __MODULE__)
end

@impl BufferedTask
Expand Down

0 comments on commit 1b65355

Please sign in to comment.