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

Leaderboard query #29

Merged
merged 43 commits into from
Nov 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
1ae9425
read celo accounts using absinthe
mrsmkl Oct 24, 2019
3e5d325
added some kind of connections
mrsmkl Oct 25, 2019
93ee8d6
reading epoch rewards
mrsmkl Nov 12, 2019
5130b2f
add bogus transaction and address
mrsmkl Nov 12, 2019
a3cf8c7
working
mrsmkl Nov 12, 2019
d2203bd
updated abis
mrsmkl Nov 13, 2019
ded4396
added reading validator history
mrsmkl Nov 13, 2019
a53ca03
format
mrsmkl Nov 14, 2019
3f0cd0a
merge
mrsmkl Nov 14, 2019
43f2100
merge
mrsmkl Nov 14, 2019
4ce3984
starting
mrsmkl Nov 14, 2019
7733944
Merge branch 'absinthe-test' of github.com:mrsmkl/blockscout into lea…
mrsmkl Nov 14, 2019
2173c0a
format
mrsmkl Nov 14, 2019
4557cbf
first version working
mrsmkl Nov 14, 2019
d07684a
added account name to the leaderboard query
mrsmkl Nov 14, 2019
5b34904
reading contract addresses from registry
mrsmkl Nov 18, 2019
6f4c748
keeping track of attestation events
mrsmkl Nov 19, 2019
41da01a
merge
mrsmkl Nov 19, 2019
b945ebd
merge
mrsmkl Nov 19, 2019
da410b3
fix dialyzer
mrsmkl Nov 19, 2019
77666f6
fix credo
mrsmkl Nov 19, 2019
bc086b2
fixing unit tests
mrsmkl Nov 19, 2019
ccc0231
fixing unit tests
mrsmkl Nov 19, 2019
748e050
format
mrsmkl Nov 19, 2019
639e2e2
some flakiness
mrsmkl Nov 19, 2019
caacf71
format
mrsmkl Nov 19, 2019
c33a33f
disabled validator history for tests
mrsmkl Nov 19, 2019
1ed914b
format
mrsmkl Nov 19, 2019
042c53d
reading extra receipts
mrsmkl Nov 20, 2019
6ebd45e
working on getting all balance changes
mrsmkl Nov 20, 2019
12f624a
changing db structure to handle logs with no associated tx
mrsmkl Nov 21, 2019
a024e67
format
mrsmkl Nov 21, 2019
1c9f81f
credo
mrsmkl Nov 21, 2019
1d607fc
unit tests are going to take some time to fix
mrsmkl Nov 21, 2019
aa89f84
fixing unit tests
mrsmkl Nov 21, 2019
9a5ea3d
unit tests working?
mrsmkl Nov 21, 2019
3754783
handling changes from monorepo and blockchain
mrsmkl Nov 22, 2019
7857786
gateway fee numric
mrsmkl Nov 22, 2019
c355b9f
fixing unit tests
mrsmkl Nov 22, 2019
0ec8434
format
mrsmkl Nov 22, 2019
b43f9f1
cleaning up
mrsmkl Nov 24, 2019
3957558
Merge pull request #36 from celo-org/mrsmkl/leaderboard
mrsmkl Nov 24, 2019
16093af
Merge pull request #35 from celo-org/mrsmkl/leaderboard-2
mrsmkl Nov 24, 2019
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ screenshots/
*.iml
.idea/

tmpbriefly*

# mix phx.gen.cert self-signed certs for dev
/apps/block_scout_web/priv/cert

Expand Down
19 changes: 13 additions & 6 deletions apps/block_scout_web/lib/block_scout_web/etherscan.ex
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ defmodule BlockScoutWeb.Etherscan do
"timeStamp" => "0x561d688c",
"gasPrice" => "0xba43b7400",
"gasUsed" => "0x10682",
"gasFeeRecipient" => "0xe7c7177b6e5418f27e435f96dbf3f7edae41c133",
"gasCurrency" => "0x88f24de331525cf6cfd7455eb96a9e4d49b7f292",
"gatewayFee" => "0x0",
"gatewayFeeRecipient" => "0xe7c7177b6e5418f27e435f96dbf3f7edae41c133",
"feeCurrency" => "0x88f24de331525cf6cfd7455eb96a9e4d49b7f292",
"logIndex" => "0x",
"transactionHash" => "0x0b03498648ae2da924f961dda00dc6bb0a8df15519262b7e012b7d67f4bb7e83",
"transactionIndex" => "0x"
Expand Down Expand Up @@ -452,8 +453,9 @@ defmodule BlockScoutWeb.Etherscan do
"gasLimit" => "91966",
"gasUsed" => "95123",
"gasPrice" => "100000",
"gasFeeRecipient" => "0xe7c7177b6e5418f27e435f96dbf3f7edae41c133",
"gasCurrency" => "0x88f24de331525cf6cfd7455eb96a9e4d49b7f292",
"gatewayFeeRecipient" => "0xe7c7177b6e5418f27e435f96dbf3f7edae41c133",
"feeCurrency" => "0x88f24de331525cf6cfd7455eb96a9e4d49b7f292",
"gatewayFee" => "0x0",
"hash" => "0x0000000000000000000000000000000000000000000000000000000000000004",
"input" => "0x04",
"logs" => [
Expand Down Expand Up @@ -796,16 +798,21 @@ defmodule BlockScoutWeb.Etherscan do
definition: "A nonnegative number roughly equivalent to computational steps.",
example: ~s("0x10682")
},
gasCurrency: %{
feeCurrency: %{
type: "address hash",
definition: "A 160-bit code used for identifying accounts or contracts.",
example: ~s("0x88f24de331525cf6cfd7455eb96a9e4d49b7f292")
},
feeRecipeint: %{
gatewayFeeRecipient: %{
type: "address hash",
definition: "A 160-bit code used for identifying accounts or contracts.",
example: ~s("0xbbae99f0e1ee565404465638d40827b54d343638")
},
gatewayFee: %{
type: "wei",
definition: &__MODULE__.wei_type_definition/1,
example: ~s("0x0")
},
logIndex: %{
type: "hexadecimal",
example: ~s("0x")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
defmodule BlockScoutWeb.Resolvers.Address do
@moduledoc false

alias Explorer.Chain
alias Absinthe.Relay.Connection
alias Explorer.{Chain, GraphQL, Repo}
alias Explorer.Chain.CeloAccount

def get_by(_, %{hashes: hashes}, _) do
case Chain.hashes_to_addresses(hashes) do
Expand All @@ -16,4 +18,10 @@ defmodule BlockScoutWeb.Resolvers.Address do
{:ok, _} = result -> result
end
end

def get_by(%CeloAccount{address: hash}, args, _) do
hash
|> GraphQL.address_query()
|> Connection.from_query(&Repo.all/1, args, [])
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
defmodule BlockScoutWeb.Resolvers.CeloAccount do
@moduledoc false

alias Absinthe.Relay.Connection
alias Explorer.{Chain, GraphQL, Repo}
alias Explorer.Chain.Address

def get_by(_, %{hash: hash}, _) do
case Chain.get_celo_account(hash) do
{:error, :not_found} -> {:error, "Celo account not found."}
{:ok, _} = result -> result
end
end

def get_by(%Address{hash: hash}, args, _) do
hash
|> GraphQL.address_to_account_query()
|> Connection.from_query(&Repo.all/1, args, [])
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule BlockScoutWeb.Resolvers.Competitor do
@moduledoc false

alias Explorer.Chain

def get_by(_, _, _) do
case Chain.query_leaderboard() do
{:error, :not_found} ->
{:error, "Leaderboard broken."}

{:ok, lst} ->
{:ok,
Enum.map(lst, fn [address, name, score] ->
%{address: "0x" <> Base.encode16(address), identity: name, points: score}
end)}
end
end
end
13 changes: 13 additions & 0 deletions apps/block_scout_web/lib/block_scout_web/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ defmodule BlockScoutWeb.Schema do
alias BlockScoutWeb.Resolvers.{
Address,
Block,
CeloAccount,
Competitor,
InternalTransaction,
TokenTransfer,
Transaction
Expand Down Expand Up @@ -66,6 +68,17 @@ defmodule BlockScoutWeb.Schema do
resolve(&Address.get_by/3)
end

@desc "Gets the leaderboard"
field :leaderboard, list_of(:competitor) do
resolve(&Competitor.get_by/3)
end

@desc "Gets an account by address hash."
field :celo_account, :celo_account do
arg(:hash, non_null(:address_hash))
resolve(&CeloAccount.get_by/3)
end

@desc "Gets addresses by address hash."
field :addresses, list_of(:address) do
arg(:hashes, non_null(list_of(non_null(:address_hash))))
Expand Down
35 changes: 35 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 @@ -7,13 +7,18 @@ defmodule BlockScoutWeb.Schema.Types do
import Absinthe.Resolution.Helpers

alias BlockScoutWeb.Resolvers.{
Address,
CeloAccount,
InternalTransaction,
Transaction
}

import_types(Absinthe.Type.Custom)
import_types(BlockScoutWeb.Schema.Scalars)

connection(node_type: :celo_account)
connection(node_type: :competitor)
connection(node_type: :address)
connection(node_type: :transaction)
connection(node_type: :internal_transaction)
connection(node_type: :token_transfer)
Expand All @@ -31,6 +36,10 @@ defmodule BlockScoutWeb.Schema.Types do
resolve(dataloader(:db, :smart_contract))
end

connection field(:celo_account, node_type: :celo_account) do
resolve(&CeloAccount.get_by/3)
end

connection field(:transactions, node_type: :transaction) do
arg(:count, :integer)
resolve(&Transaction.get_by/3)
Expand All @@ -45,6 +54,22 @@ defmodule BlockScoutWeb.Schema.Types do
end
end

@desc """
Celo account information
"""
object :celo_account do
field(:address, :address_hash)
field(:account_type, :string)
field(:nonvoting_locked_gold, :wei)
field(:locked_gold, :wei)
field(:attestations_requested, :integer)
field(:attestations_fulfilled, :integer)

connection field(:address_info, node_type: :address) do
resolve(&Address.get_by/3)
end
end

@desc """
A package of data that contains zero or more transactions, the hash of the previous block ("parent"), and optionally
other data. Because each block (except for the initial "genesis block") points to the previous block, the data
Expand All @@ -65,6 +90,15 @@ defmodule BlockScoutWeb.Schema.Types do
field(:parent_hash, :full_hash)
end

@desc """
Leaderboard entry
"""
object :competitor do
field(:address, :address_hash)
field(:points, :float)
field(:identity, :string)
end

@desc """
Models internal transactions.
"""
Expand Down Expand Up @@ -118,6 +152,7 @@ defmodule BlockScoutWeb.Schema.Types do
field(:to_address_hash, :address_hash)
field(:token_contract_address_hash, :address_hash)
field(:transaction_hash, :full_hash)
field(:block_hash, :full_hash)
end

@desc """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ defmodule BlockScoutWeb.API.RPC.LogsView do
"timeStamp" => datetime_to_hex(log.block_timestamp),
"gasPrice" => decimal_to_hex(log.gas_price.value),
"gasUsed" => decimal_to_hex(log.gas_used),
"gasCurrency" => "#{log.gas_currency_hash}",
"feeRecipient" => "#{log.gas_fee_recipient_hash}",
"feeCurrency" => "#{log.gas_currency_hash}",
"gatewayFeeRecipient" => "#{log.gas_fee_recipient_hash}",
"gatewayFee" => "#{0}",
"logIndex" => integer_to_hex(log.index),
"transactionHash" => "#{log.transaction_hash}",
"transactionIndex" => integer_to_hex(log.transaction_index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ defmodule BlockScoutWeb.API.RPC.TransactionView do
"gasLimit" => "#{transaction.gas}",
"gasUsed" => "#{transaction.gas_used}",
"gasPrice" => "#{transaction.gas_price.value}",
"gasCurrency" => "#{transaction.gas_currency_hash}",
"gasFeeRecipient" => "#{transaction.gas_fee_recipient_hash}",
"feeCurrency" => "#{transaction.gas_currency_hash}",
"gatewayFeeRecipient" => "#{transaction.gas_fee_recipient_hash}",
"gatewayFee" => "#{0}",
"logs" => Enum.map(logs, &prepare_log/1),
"next_page_params" => next_page_params
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ defmodule BlockScoutWeb.AddressTokenControllerTest do

test "returns tokens that have balance for the address", %{conn: conn} do
address = insert(:address)
block = insert(:block)

token1 =
:token
Expand Down Expand Up @@ -47,12 +48,14 @@ defmodule BlockScoutWeb.AddressTokenControllerTest do
:token_transfer,
token_contract_address: token1.contract_address,
from_address: address,
block: block,
to_address: build(:address)
)

insert(
:token_transfer,
token_contract_address: token2.contract_address,
block: block,
from_address: build(:address),
to_address: address
)
Expand Down Expand Up @@ -128,7 +131,9 @@ defmodule BlockScoutWeb.AddressTokenControllerTest do
value: 1000
)

insert(:token_transfer, token_contract_address: token.contract_address, from_address: address)
block = insert(:block)

insert(:token_transfer, token_contract_address: token.contract_address, from_address: address, block: block)
end)

conn = get(conn, address_token_path(BlockScoutWeb.Endpoint, :index, address.hash), type: "JSON")
Expand All @@ -143,7 +148,8 @@ defmodule BlockScoutWeb.AddressTokenControllerTest do
test "next_page_params are empty if on last page", %{conn: conn} do
address = insert(:address)
token = insert(:token)
insert(:token_transfer, token_contract_address: token.contract_address, from_address: address)
block = insert(:block)
insert(:token_transfer, token_contract_address: token.contract_address, from_address: address, block: block)

conn = get(conn, address_token_path(BlockScoutWeb.Endpoint, :index, address.hash), type: "JSON")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do
:token_transfer,
to_address: address,
transaction: transaction,
block: transaction.block,
token_contract_address: token.contract_address
)

Expand Down Expand Up @@ -116,6 +117,7 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do
:token_transfer,
to_address: address,
transaction: transaction,
block: block,
token_contract_address: token.contract_address
)

Expand Down Expand Up @@ -147,6 +149,7 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do
:token_transfer,
to_address: address,
transaction: transaction,
block: block,
token_contract_address: token.contract_address
)

Expand All @@ -166,6 +169,7 @@ defmodule BlockScoutWeb.AddressTokenTransferControllerTest do
:token_transfer,
to_address: address,
transaction: transaction,
block: block,
token_contract_address: token.contract_address
)
end)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ defmodule BlockScoutWeb.AddressTransactionControllerTest do
|> insert(from_address: address)
|> with_block()

insert(:token_transfer, transaction: transaction, from_address: address)
insert(:token_transfer, transaction: transaction, to_address: address)
insert(:token_transfer, transaction: transaction, from_address: address, block: transaction.block)
insert(:token_transfer, transaction: transaction, to_address: address, block: transaction.block)

conn = get(conn, "/token_transfers_csv", %{"address_id" => to_string(address.hash)})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1787,6 +1787,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
insert(:token_transfer, %{
token_contract_address: token_address,
token_id: 666,
block: transaction.block,
transaction: transaction
})

Expand Down Expand Up @@ -1817,7 +1818,7 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
|> insert()
|> with_block()

token_transfer = insert(:token_transfer, transaction: transaction)
token_transfer = insert(:token_transfer, transaction: transaction, block: block)
{:ok, token} = Chain.token_from_address_hash(token_transfer.token_contract_address_hash)

params = %{
Expand Down Expand Up @@ -1894,8 +1895,14 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
|> insert()
|> with_block()

insert(:token_transfer, from_address: address, transaction: transaction)
insert(:token_transfer, from_address: address, token_contract_address: contract_address, transaction: transaction)
insert(:token_transfer, from_address: address, transaction: transaction, block: transaction.block)

insert(:token_transfer,
from_address: address,
token_contract_address: contract_address,
transaction: transaction,
block: transaction.block
)

params = %{
"module" => "account",
Expand Down Expand Up @@ -2561,8 +2568,9 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
"value" => %{"type" => "string"},
"gas" => %{"type" => "string"},
"gasPrice" => %{"type" => "string"},
"gasCurrency" => %{"type" => "string"},
"gasFeeRecipient" => %{"type" => "string"},
"feeCurrency" => %{"type" => "string"},
"gatewayFee" => %{"type" => "string"},
"gatewayFeeRecipient" => %{"type" => "string"},
"isError" => %{"type" => "string"},
"txreceipt_status" => %{"type" => "string"},
"input" => %{"type" => "string"},
Expand Down Expand Up @@ -2622,8 +2630,9 @@ defmodule BlockScoutWeb.API.RPC.AddressControllerTest do
"transactionIndex" => %{"type" => "string"},
"gas" => %{"type" => "string"},
"gasPrice" => %{"type" => "string"},
"gasCurrency" => %{"type" => "string"},
"gasFeeRecipient" => %{"type" => "string"},
"feeCurrency" => %{"type" => "string"},
"gatewayFeeRecipient" => %{"type" => "string"},
"gatewayFee" => %{"type" => "string"},
"gasUsed" => %{"type" => "string"},
"cumulativeGasUsed" => %{"type" => "string"},
"input" => %{"type" => "string"},
Expand Down
Loading