Skip to content

Commit

Permalink
Merge pull request blockscout#36 from celo-org/mrsmkl/leaderboard
Browse files Browse the repository at this point in the history
Update to handle new transaction fields
  • Loading branch information
mrsmkl committed Nov 24, 2019
2 parents 9a5ea3d + b43f9f1 commit 3957558
Show file tree
Hide file tree
Showing 29 changed files with 114 additions and 121 deletions.
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
7 changes: 2 additions & 5 deletions apps/block_scout_web/lib/block_scout_web/resolvers/address.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ defmodule BlockScoutWeb.Resolvers.Address do

def get_by(_, %{hash: hash}, _) do
case Chain.hash_to_address(hash) do
{:error, :not_found} ->
{:error, "Address not found."}

{:ok, _} = result ->
result
{:error, :not_found} -> {:error, "Address not found."}
{:ok, _} = result -> result
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ defmodule BlockScoutWeb.Resolvers.Competitor do
@moduledoc false

alias Explorer.Chain
# alias Explorer.Chain.Hash
# alias Explorer.Chain.Hash.Address

def get_by(_, _, _) do
case Chain.query_leaderboard() do
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 @@ -2568,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 @@ -2629,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
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ defmodule BlockScoutWeb.API.RPC.ContractControllerTest do
})
end

defp resolve_schema(result \\ %{}) do
defp resolve_schema(result) do
%{
"type" => "object",
"properties" => %{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,9 @@ defmodule BlockScoutWeb.API.RPC.LogsControllerTest do
"timeStamp" => datetime_to_hex(block.timestamp),
"gasPrice" => decimal_to_hex(transaction.gas_price.value),
"gasUsed" => decimal_to_hex(transaction.gas_used),
"feeRecipient" => "",
"gasCurrency" => "",
"gatewayFeeRecipient" => "",
"gatewayFee" => "0",
"feeCurrency" => "",
"logIndex" => integer_to_hex(log.index),
"transactionHash" => "#{transaction.hash}",
"transactionIndex" => integer_to_hex(transaction.index)
Expand Down Expand Up @@ -448,8 +449,9 @@ defmodule BlockScoutWeb.API.RPC.LogsControllerTest do
"gasPrice" => decimal_to_hex(transaction.gas_price.value),
"gasUsed" => decimal_to_hex(transaction.gas_used),
"logIndex" => integer_to_hex(log1.index),
"feeRecipient" => "",
"gasCurrency" => "",
"gatewayFeeRecipient" => "",
"gatewayFee" => "0",
"feeCurrency" => "",
"transactionHash" => "#{transaction.hash}",
"transactionIndex" => integer_to_hex(transaction.index)
}
Expand Down Expand Up @@ -811,8 +813,9 @@ defmodule BlockScoutWeb.API.RPC.LogsControllerTest do
"blockNumber" => %{"type" => "string"},
"timeStamp" => %{"type" => "string"},
"gasPrice" => %{"type" => "string"},
"gasCurrency" => %{"type" => "string"},
"gasFeeRecipient" => %{"type" => "string"},
"feeCurrency" => %{"type" => "string"},
"gatewayFeeRecipient" => %{"type" => "string"},
"gatewayFee" => %{"type" => "string"},
"gasUsed" => %{"type" => "string"},
"logIndex" => %{"type" => "string"},
"transactionHash" => %{"type" => "string"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ defmodule BlockScoutWeb.API.RPC.StatsControllerTest do
})
end

defp resolve_schema(result \\ %{}) do
defp resolve_schema(result) do
%{
"type" => "object",
"properties" => %{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,4 @@ defmodule BlockScoutWeb.API.RPC.TokenControllerTest do
assert response["message"] == "OK"
end
end

defp gettoken_schema do
ExJsonSchema.Schema.resolve(%{
"type" => "object",
"properties" => %{
"message" => %{"type" => "string"},
"status" => %{"type" => "string"},
"result" => %{
"type" => "object",
"properties" => %{
"name" => %{"type" => "string"},
"symbol" => %{"type" => "string"},
"totalSupply" => %{"type" => "string"},
"decimals" => %{"type" => "string"},
"type" => %{"type" => "string"},
"cataloged" => %{"type" => "string"},
"contractAddress" => %{"type" => "string"}
}
}
}
})
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,9 @@ defmodule BlockScoutWeb.API.RPC.TransactionControllerTest 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}",
"gatewayFee" => "#{0}",
"gatewayFeeRecipient" => "#{transaction.gas_fee_recipient_hash}",
"logs" => [
%{
"address" => "#{address.hash}",
Expand Down
1 change: 0 additions & 1 deletion apps/ethereum_jsonrpc/lib/ethereum_jsonrpc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ defmodule EthereumJSONRPC do
@spec json_rpc(Transport.batch_request(), json_rpc_named_arguments) ::
{:ok, Transport.batch_response()} | {:error, reason :: term()}
def json_rpc(request, named_arguments) when (is_map(request) or is_list(request)) and is_list(named_arguments) do
# IO.inspect(request)
transport = Keyword.fetch!(named_arguments, :transport)
transport_options = Keyword.fetch!(named_arguments, :transport_options)
throttle_timeout = Keyword.get(named_arguments, :throttle_timeout, @default_throttle_timeout)
Expand Down
3 changes: 0 additions & 3 deletions apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/contract.ex
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ defmodule EthereumJSONRPC.Contract do
end
|> Enum.into(%{}, &{&1.id, &1})

# IO.inspect(requests)
# IO.inspect(indexed_responses)

Enum.map(requests_with_index, fn {%{function_name: function_name}, index} ->
selectors = Enum.filter(parsed_abi, fn p_abi -> p_abi.function == function_name end)

Expand Down
40 changes: 24 additions & 16 deletions apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/transaction.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ defmodule EthereumJSONRPC.Transaction do
* `"gas"` - `t:EthereumJSONRPC.quantity/0` of gas provided by the sender. This is the max gas that may be used.
`gas * gasPrice` is the max fee in wei that the sender is willing to pay for the transaction to be executed.
* `"gasPrice"` - `t:EthereumJSONRPC.quantity/0` of wei to pay per unit of gas used.
* `"gasCurrency"` - `t:EthereumJSONRPC.address/0` of token used as currency for transaction gas fee
* `"gasFeeRecipient"` - `t:EthereumJSONRPC.address/0` of the receiver of the transaction gas fee
* `"feeCurrency"` - `t:EthereumJSONRPC.address/0` of token used as currency for transaction gas fee
* `"gatewayFeeRecipient"` - `t:EthereumJSONRPC.address/0` of the receiver of the transaction gas fee
* `"gatewayFee"` - gateway fee
* `"hash"` - `t:EthereumJSONRPC.hash/0` of the transaction
* `"input"` - `t:EthereumJSONRPC.data/0` sent along with the transaction, such as input to the contract.
* `"nonce"` - `t:EthereumJSONRPC.quantity/0` of transactions made by the sender prior to this one.
Expand Down Expand Up @@ -79,8 +80,9 @@ defmodule EthereumJSONRPC.Transaction do
...> "from" => "0xa1e4380a3b1f749673e270229993ee55f35663b4",
...> "gas" => 21000,
...> "gasPrice" => 50000000000000,
...> "gasCurrency" => "0x88f24de331525cf6cfd7455eb96a9e4d49b7f292",
...> "gasFeeRecipient" => "0xa1e4380a3b1f749673e270229993ee55f35663b4",
...> "feeCurrency" => "0x88f24de331525cf6cfd7455eb96a9e4d49b7f292",
...> "gatewayFeeRecipient" => "0xa1e4380a3b1f749673e270229993ee55f35663b4",
...> "gatewayFee" => 0,
...> "hash" => "0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060",
...> "input" => "0x",
...> "nonce" => 0,
Expand Down Expand Up @@ -122,8 +124,9 @@ defmodule EthereumJSONRPC.Transaction do
...> "from" => "0xa1e4380a3b1f749673e270229993ee55f35663b4",
...> "gas" => 21000,
...> "gasPrice" => 50000000000000,
...> "gasCurrency" => "0x88f24de331525cf6cfd7455eb96a9e4d49b7f292",
...> "gasFeeRecipient" => "0xa1e4380a3b1f749673e270229993ee55f35663b4",
...> "feeCurrency" => "0x88f24de331525cf6cfd7455eb96a9e4d49b7f292",
...> "gatewayFeeRecipient" => "0xa1e4380a3b1f749673e270229993ee55f35663b4",
...> "gatewayFee" => "0x0",
...> "hash" => "0x5c504ed432cb51138bcf09aa5e8a410dd4a1e204ef84bfed1be16dfba1b22060",
...> "input" => "0x0",
...> "nonce" => 0,
Expand Down Expand Up @@ -169,8 +172,9 @@ defmodule EthereumJSONRPC.Transaction do
"from" => from_address_hash,
"gas" => gas,
"gasPrice" => gas_price,
"gasCurrency" => gas_currency_hash,
"gasFeeRecipient" => gas_fee_recipient_hash,
"feeCurrency" => gas_currency_hash,
"gatewayFeeRecipient" => gas_fee_recipient_hash,
"gatewayFee" => _,
"hash" => hash,
"input" => input,
"nonce" => nonce,
Expand Down Expand Up @@ -228,8 +232,9 @@ defmodule EthereumJSONRPC.Transaction do
"from" => _,
"gas" => _,
"gasPrice" => _,
"gasCurrency" => _,
"gasFeeRecipient" => _,
"feeCurrency" => _,
"gatewayFeeRecipient" => _,
"gatewayFee" => _,
"hash" => _,
"input" => _,
"nonce" => _,
Expand Down Expand Up @@ -285,8 +290,9 @@ defmodule EthereumJSONRPC.Transaction do
...> "from" => "0x40aa34fb35ef0804a41c2b4be7d3e3d65c7f6d5c",
...> "gas" => "0xcf08",
...> "gasPrice" => "0x0",
...> "gasCurrency" => nil,
...> "gasFeeRecipient" => nil,
...> "feeCurrency" => nil,
...> "gatewayFeeRecipient" => nil,
...> "gatewayFee" => "0x0",
...> "hash" => "0x6b80a90c958fb5791a070929379ed6eb7a33ecdf9f9cafcada2f6803b3f25ec3",
...> "input" => "0x",
...> "nonce" => "0x77",
Expand All @@ -310,8 +316,9 @@ defmodule EthereumJSONRPC.Transaction do
"from" => "0x40aa34fb35ef0804a41c2b4be7d3e3d65c7f6d5c",
"gas" => 53000,
"gasPrice" => 0,
"gasCurrency" => nil,
"gasFeeRecipient" => nil,
"feeCurrency" => nil,
"gatewayFeeRecipient" => nil,
"gatewayFee" => 0,
"hash" => "0x6b80a90c958fb5791a070929379ed6eb7a33ecdf9f9cafcada2f6803b3f25ec3",
"input" => "0x",
"nonce" => 119,
Expand Down Expand Up @@ -343,14 +350,15 @@ defmodule EthereumJSONRPC.Transaction do
#
# "txType": to avoid FunctionClauseError when indexing Wanchain
defp entry_to_elixir({key, value})
when key in ~w(blockHash condition creates from hash input jsonrpc publicKey raw to txType gasCurrency gasFeeRecipient),
when key in ~w(blockHash condition creates from hash input jsonrpc publicKey raw to txType feeCurrency gatewayFeeRecipient),
do: {key, value}

# specific to Nethermind client
defp entry_to_elixir({"data", value}),
do: {"input", value}

defp entry_to_elixir({key, quantity}) when key in ~w(gas gasPrice nonce r s standardV v value) and quantity != nil do
defp entry_to_elixir({key, quantity})
when key in ~w(gas gasPrice nonce r s standardV v value gatewayFee) and quantity != nil do
{key, quantity_to_integer(quantity)}
end

Expand Down

0 comments on commit 3957558

Please sign in to comment.