Merge branch 'master' into ab-fix-contract-created-by-reverted-transactions

pull/1470/head
Ayrat Badykov 6 years ago committed by GitHub
commit 610a3f5d0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      apps/block_scout_web/assets/js/lib/coin_balance_history_chart.js
  2. 22
      apps/indexer/lib/indexer/block/fetcher/receipts.ex
  3. 151
      apps/indexer/test/indexer/block/fetcher/receipts_test.exs

@ -23,7 +23,8 @@ export function createCoinBalanceHistoryChart (el) {
data: { data: {
datasets: [{ datasets: [{
label: 'coin balance', label: 'coin balance',
data: coinBalanceHistoryData data: coinBalanceHistoryData,
lineTension: 0
}] }]
}, },
options: { options: {

@ -29,6 +29,10 @@ defmodule Indexer.Block.Fetcher.Receipts do
{:error, reason}, {:ok, _acc} -> {:error, reason}, {:ok, _acc} ->
{:halt, {:error, reason}} {:halt, {:error, reason}}
end) end)
|> case do
{:ok, receipt_params} -> {:ok, set_block_number_to_logs(receipt_params, transaction_params)}
other -> other
end
end end
def put(transactions_params, receipts_params) when is_list(transactions_params) and is_list(receipts_params) do def put(transactions_params, receipts_params) when is_list(transactions_params) and is_list(receipts_params) do
@ -41,4 +45,22 @@ defmodule Indexer.Block.Fetcher.Receipts do
Map.merge(transaction_params, Map.fetch!(transaction_hash_to_receipt_params, transaction_hash)) Map.merge(transaction_params, Map.fetch!(transaction_hash_to_receipt_params, transaction_hash))
end) end)
end end
defp set_block_number_to_logs(%{logs: logs} = params, transaction_params) do
logs_with_block_numbers =
Enum.map(logs, fn %{transaction_hash: transaction_hash, block_number: block_number} = log_params ->
if is_nil(block_number) do
transaction =
Enum.find(transaction_params, fn transaction ->
transaction[:hash] == transaction_hash
end)
%{log_params | block_number: transaction[:block_number]}
else
log_params
end
end)
%{params | logs: logs_with_block_numbers}
end
end end

@ -0,0 +1,151 @@
defmodule Indexer.Block.Fetcher.ReceiptsTest do
use EthereumJSONRPC.Case, async: false
import Mox
alias Indexer.Block.Fetcher
alias Indexer.Block.Fetcher.Receipts
@moduletag capture_log: true
setup :set_mox_global
setup :verify_on_exit!
describe "fetch/2" do
setup %{json_rpc_named_arguments: json_rpc_named_arguments} do
%{
block_fetcher: %Fetcher{
json_rpc_named_arguments: json_rpc_named_arguments,
receipts_concurrency: 10
}
}
end
@tag :no_parity
@tag :no_geth
test "fetches logs setting their blocks if they're null", %{
block_fetcher: %Fetcher{json_rpc_named_arguments: json_rpc_named_arguments} = block_fetcher
} do
if json_rpc_named_arguments[:transport] == EthereumJSONRPC.Mox do
EthereumJSONRPC.Mox
|> expect(:json_rpc, fn _json, _options ->
{:ok,
[
%{
id: 0,
jsonrpc: "2.0",
result: %{
"blockHash" => nil,
"blockNumber" => nil,
"contractAddress" => nil,
"cumulativeGasUsed" => "0x5208",
"gasUsed" => "0x5208",
"logs" => [
%{
"address" => "0x8bf38d4764929064f2d4d3a56520a76ab3df415b",
"blockHash" => nil,
"blockNumber" => nil,
"data" => "0x000000000000000000000000862d67cb0773ee3f8ce7ea89b328ffea861ab3ef",
"logIndex" => "0x0",
"topics" => ["0x600bcf04a13e752d1e3670a5a9f1c21177ca2a93c6f5391d4f1298d098097c22"],
"transactionHash" => "0x43bd884872de3e488692881baeec262e7b95234d3965248c39fe992fffd433e5",
"transactionIndex" => "0x0",
"transactionLogIndex" => "0x0",
"type" => "mined"
}
],
"logsBloom" =>
"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"root" => nil,
"status" => "0x1",
"transactionHash" => "0x43bd884872de3e488692881baeec262e7b95234d3965248c39fe992fffd433e5",
"transactionIndex" => "0x0"
}
},
%{
id: 1,
jsonrpc: "2.0",
result: %{
"blockHash" => "0xf6b4b8c88df3ebd252ec476328334dc026cf66606a84fb769b3d3cbccc8471bd",
"blockNumber" => "0x25",
"contractAddress" => nil,
"cumulativeGasUsed" => "0xc512",
"gasUsed" => "0xc512",
"logs" => [
%{
"address" => "0x8bf38d4764929064f2d4d3a56520a76ab3df415b",
"blockHash" => "0xf6b4b8c88df3ebd252ec476328334dc026cf66606a84fb769b3d3cbccc8471bd",
"blockNumber" => "0x25",
"data" => "0x000000000000000000000000862d67cb0773ee3f8ce7ea89b328ffea861ab3ef",
"logIndex" => "0x0",
"topics" => ["0x600bcf04a13e752d1e3670a5a9f1c21177ca2a93c6f5391d4f1298d098097c22"],
"transactionHash" => "0x53bd884872de3e488692881baeec262e7b95234d3965248c39fe992fffd433e5",
"transactionIndex" => "0x0",
"transactionLogIndex" => "0x0",
"type" => "mined"
}
],
"logsBloom" =>
"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000200000000000000000000020000000000000000200000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"root" => nil,
"status" => "0x1",
"transactionHash" => "0x53bd884872de3e488692881baeec262e7b95234d3965248c39fe992fffd433e5",
"transactionIndex" => "0x0"
}
}
]}
end)
end
transaction_params = [
%{
block_hash: "0xf6b4b8c88df3ebd252ec476328334dc026cf66606a84fb769b3d3cbccc8471bd",
block_number: 46147,
from_address_hash: "0xa1e4380a3b1f749673e270229993ee55f35663b4",
gas: 21000,
gas_price: 50_000_000_000_000,
hash: "0x43bd884872de3e488692881baeec262e7b95234d3965248c39fe992fffd433e5",
index: 0,
input: "0x",
nonce: 0,
r: 61_965_845_294_689_009_770_156_372_156_374_760_022_787_886_965_323_743_865_986_648_153_755_601_564_112,
s: 31_606_574_786_494_953_692_291_101_914_709_926_755_545_765_281_581_808_821_704_454_381_804_773_090_106,
to_address_hash: "0x5df9b87991262f6ba471f09758cde1c0fc1de734",
v: 28,
value: 31337,
transaction_index: 0
},
%{
block_hash: "0xf7b4b8c88df3ebd252ec476328334dc026cf66606a84fb769b3d3cbccc8471bd",
block_number: 46148,
from_address_hash: "0xa1e4380a3b1f749673e270229993ee55f35663b4",
gas: 21000,
gas_price: 50_000_000_000_000,
hash: "0x53bd884872de3e488692881baeec262e7b95234d3965248c39fe992fffd433e5",
index: 0,
input: "0x",
nonce: 0,
r: 61_965_845_294_689_009_770_156_372_156_374_760_022_787_886_965_323_743_865_986_648_153_755_601_564_112,
s: 31_606_574_786_494_953_692_291_101_914_709_926_755_545_765_281_581_808_821_704_454_381_804_773_090_106,
to_address_hash: "0x5df9b87991262f6ba471f09758cde1c0fc1de734",
v: 28,
value: 31337,
transaction_index: 0
}
]
{:ok, %{logs: logs}} = Receipts.fetch(block_fetcher, transaction_params)
assert Enum.find(logs, fn log ->
log[:transaction_hash] == "0x53bd884872de3e488692881baeec262e7b95234d3965248c39fe992fffd433e5" &&
log[:block_number] == 37
end)
assert Enum.find(logs, fn log ->
log[:transaction_hash] == "0x43bd884872de3e488692881baeec262e7b95234d3965248c39fe992fffd433e5" &&
log[:block_number] == 46147
end)
end
end
end
Loading…
Cancel
Save