|
|
|
@ -8,8 +8,23 @@ defmodule EthereumJSONRPC.Block do |
|
|
|
|
|
|
|
|
|
alias EthereumJSONRPC.{Transactions, Uncles, Withdrawals} |
|
|
|
|
|
|
|
|
|
if Application.compile_env(:explorer, :chain_type) == "rsk" do |
|
|
|
|
@rootstock_fields quote( |
|
|
|
|
do: [ |
|
|
|
|
bitcoin_merged_mining_header: EthereumJSONRPC.data(), |
|
|
|
|
bitcoin_merged_mining_coinbase_transaction: EthereumJSONRPC.data(), |
|
|
|
|
bitcoin_merged_mining_merkle_proof: EthereumJSONRPC.data(), |
|
|
|
|
hash_for_merged_mining: EthereumJSONRPC.data(), |
|
|
|
|
minimum_gas_price: non_neg_integer() |
|
|
|
|
] |
|
|
|
|
) |
|
|
|
|
else |
|
|
|
|
@rootstock_fields quote(do: []) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@type elixir :: %{String.t() => non_neg_integer | DateTime.t() | String.t() | nil} |
|
|
|
|
@type params :: %{ |
|
|
|
|
unquote_splicing(@rootstock_fields), |
|
|
|
|
difficulty: pos_integer(), |
|
|
|
|
extra_data: EthereumJSONRPC.hash(), |
|
|
|
|
gas_limit: non_neg_integer(), |
|
|
|
@ -69,6 +84,15 @@ defmodule EthereumJSONRPC.Block do |
|
|
|
|
`t:EthereumJSONRPC.hash/0`. |
|
|
|
|
* `"baseFeePerGas"` - `t:EthereumJSONRPC.quantity/0` of wei to denote amount of fee burned per unit gas used. Introduced in [EIP-1559](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md) |
|
|
|
|
* `"withdrawalsRoot"` - `t:EthereumJSONRPC.hash/0` of the root of the withdrawals. |
|
|
|
|
#{if Application.compile_env(:explorer, :chain_type) == "rsk" do |
|
|
|
|
""" |
|
|
|
|
* `"minimumGasPrice"` - `t:EthereumJSONRPC.quantity/0` of the minimum gas price for this block. |
|
|
|
|
* `"bitcoinMergedMiningHeader"` - `t:EthereumJSONRPC.data/0` of the Bitcoin merged mining header. |
|
|
|
|
* `"bitcoinMergedMiningCoinbaseTransaction"` - `t:EthereumJSONRPC.data/0` of the Bitcoin merged mining coinbase transaction. |
|
|
|
|
* `"bitcoinMergedMiningMerkleProof"` - `t:EthereumJSONRPC.data/0` of the Bitcoin merged mining merkle proof. |
|
|
|
|
* `"hashForMergedMining"` - `t:EthereumJSONRPC.data/0` of the hash for merged mining. |
|
|
|
|
""" |
|
|
|
|
end} |
|
|
|
|
""" |
|
|
|
|
@type t :: %{String.t() => EthereumJSONRPC.data() | EthereumJSONRPC.hash() | EthereumJSONRPC.quantity() | nil} |
|
|
|
|
|
|
|
|
@ -119,7 +143,17 @@ defmodule EthereumJSONRPC.Block do |
|
|
|
|
...> "timestamp" => Timex.parse!("2017-12-15T21:03:30Z", "{ISO:Extended:Z}"), |
|
|
|
|
...> "totalDifficulty" => 340282366920938463463374607431465668165, |
|
|
|
|
...> "transactions" => [], |
|
|
|
|
...> "transactionsRoot" => "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|
|
|
|
...> "transactionsRoot" => "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",\ |
|
|
|
|
#{if Application.compile_env(:explorer, :chain_type) == "rsk" do |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
...> "minimumGasPrice" => 345786, |
|
|
|
|
...> "bitcoinMergedMiningHeader" => "0x00006d20ffd048280094a6ea0851d854036aacaa25ee0f23f0040200000000000000000078d2638fe0b4477c54601e6449051afba8228e0a88ff06b0c91f091fd34d5da57487c76402610517372c2fe9", |
|
|
|
|
...> "bitcoinMergedMiningCoinbaseTransaction" => "0x00000000000000805bf0dc9203da49a3b4e3ec913806e43102cc07db991272dc8b7018da57eb5abe59a32d070000ffffffff03449a4d26000000001976a914536ffa992491508dca0354e52f32a3a7a679a53a88ac00000000000000002b6a2952534b424c4f434b3ad2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a400000000000000000266a24aa21a9ed4ae42ea6dca2687aaed665714bf58b055c4e11f2fb038605930d630b49ad7b9d00000000", |
|
|
|
|
...> "bitcoinMergedMiningMerkleProof" => "0x8e5a4ba74eb4eb2f9ad4cabc2913aeed380a5becf7cd4d513341617efb798002bd83a783c31c66a8a8f6cc56c071c2d471cb610e3dc13054b9d216021d8c7e9112f622564449ebedcedf7d4ccb6fe0ffac861b7ed1446c310813cdf712e1e6add28b1fe1c0ae5e916194ba4f285a9340aba41e91bf847bf31acf37a9623a04a2348a37ab9faa5908122db45596bbc03e9c3644b0d4589471c4ff30fc139f3ba50506e9136fa0df799b487494de3e2b3dec937338f1a2e18da057c1f60590a9723672a4355b9914b1d01af9f582d9e856f6e1744be00f268b0b01d559329f7e0685aa63ffeb7c28486d7462292021d1345cddbf7c920ca34bb7aa4c6cdbe068806e35d0db662e7fcda03cb4d779594638c62a1fdd7ec98d1fb6d240d853958abe57561d9b9d0465cf8b9d6ee3c58b0d8b07d6c4c5d8f348e43fe3c06011b6a0008db4e0b16c77ececc3981f9008201cea5939869d648e59a09bd2094b1196ff61126bffb626153deed2563e1745436247c94a85d2947756b606d67633781c99d7", |
|
|
|
|
...> "hashForMergedMining" => "0xd2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a40",\ |
|
|
|
|
""" |
|
|
|
|
end} |
|
|
|
|
...> "uncles" => [] |
|
|
|
|
...> } |
|
|
|
|
...> ) |
|
|
|
@ -142,7 +176,17 @@ defmodule EthereumJSONRPC.Block do |
|
|
|
|
timestamp: Timex.parse!("2017-12-15T21:03:30Z", "{ISO:Extended:Z}"), |
|
|
|
|
total_difficulty: 340282366920938463463374607431465668165, |
|
|
|
|
transactions_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|
|
|
|
uncles: [], |
|
|
|
|
uncles: [],\ |
|
|
|
|
#{if Application.compile_env(:explorer, :chain_type) == "rsk" do |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
bitcoin_merged_mining_coinbase_transaction: "0x00000000000000805bf0dc9203da49a3b4e3ec913806e43102cc07db991272dc8b7018da57eb5abe59a32d070000ffffffff03449a4d26000000001976a914536ffa992491508dca0354e52f32a3a7a679a53a88ac00000000000000002b6a2952534b424c4f434b3ad2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a400000000000000000266a24aa21a9ed4ae42ea6dca2687aaed665714bf58b055c4e11f2fb038605930d630b49ad7b9d00000000", |
|
|
|
|
bitcoin_merged_mining_header: "0x00006d20ffd048280094a6ea0851d854036aacaa25ee0f23f0040200000000000000000078d2638fe0b4477c54601e6449051afba8228e0a88ff06b0c91f091fd34d5da57487c76402610517372c2fe9", |
|
|
|
|
bitcoin_merged_mining_merkle_proof: "0x8e5a4ba74eb4eb2f9ad4cabc2913aeed380a5becf7cd4d513341617efb798002bd83a783c31c66a8a8f6cc56c071c2d471cb610e3dc13054b9d216021d8c7e9112f622564449ebedcedf7d4ccb6fe0ffac861b7ed1446c310813cdf712e1e6add28b1fe1c0ae5e916194ba4f285a9340aba41e91bf847bf31acf37a9623a04a2348a37ab9faa5908122db45596bbc03e9c3644b0d4589471c4ff30fc139f3ba50506e9136fa0df799b487494de3e2b3dec937338f1a2e18da057c1f60590a9723672a4355b9914b1d01af9f582d9e856f6e1744be00f268b0b01d559329f7e0685aa63ffeb7c28486d7462292021d1345cddbf7c920ca34bb7aa4c6cdbe068806e35d0db662e7fcda03cb4d779594638c62a1fdd7ec98d1fb6d240d853958abe57561d9b9d0465cf8b9d6ee3c58b0d8b07d6c4c5d8f348e43fe3c06011b6a0008db4e0b16c77ececc3981f9008201cea5939869d648e59a09bd2094b1196ff61126bffb626153deed2563e1745436247c94a85d2947756b606d67633781c99d7", |
|
|
|
|
hash_for_merged_mining: "0xd2508d21d28c8f89d495923c0758ec3f64bd6755b4ec416f5601312600542a40", |
|
|
|
|
minimum_gas_price: 345786,\ |
|
|
|
|
""" |
|
|
|
|
end} |
|
|
|
|
withdrawals_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -191,34 +235,49 @@ defmodule EthereumJSONRPC.Block do |
|
|
|
|
timestamp: Timex.parse!("2015-07-30T15:32:07Z", "{ISO:Extended:Z}"), |
|
|
|
|
total_difficulty: 1039309006117, |
|
|
|
|
transactions_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", |
|
|
|
|
uncles: [], |
|
|
|
|
uncles: [],\ |
|
|
|
|
#{if Application.compile_env(:explorer, :chain_type) == "rsk" do |
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
bitcoin_merged_mining_coinbase_transaction: nil, |
|
|
|
|
bitcoin_merged_mining_header: nil, |
|
|
|
|
bitcoin_merged_mining_merkle_proof: nil, |
|
|
|
|
hash_for_merged_mining: nil, |
|
|
|
|
minimum_gas_price: nil,\ |
|
|
|
|
""" |
|
|
|
|
end} |
|
|
|
|
withdrawals_root: "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421" |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
""" |
|
|
|
|
@spec elixir_to_params(elixir) :: params |
|
|
|
|
def elixir_to_params( |
|
|
|
|
%{ |
|
|
|
|
"difficulty" => difficulty, |
|
|
|
|
"extraData" => extra_data, |
|
|
|
|
"gasLimit" => gas_limit, |
|
|
|
|
"gasUsed" => gas_used, |
|
|
|
|
"hash" => hash, |
|
|
|
|
"logsBloom" => logs_bloom, |
|
|
|
|
"miner" => miner_hash, |
|
|
|
|
"number" => number, |
|
|
|
|
"parentHash" => parent_hash, |
|
|
|
|
"receiptsRoot" => receipts_root, |
|
|
|
|
"sha3Uncles" => sha3_uncles, |
|
|
|
|
"size" => size, |
|
|
|
|
"stateRoot" => state_root, |
|
|
|
|
"timestamp" => timestamp, |
|
|
|
|
"totalDifficulty" => total_difficulty, |
|
|
|
|
"transactionsRoot" => transactions_root, |
|
|
|
|
"uncles" => uncles, |
|
|
|
|
"baseFeePerGas" => base_fee_per_gas |
|
|
|
|
} = elixir |
|
|
|
|
) do |
|
|
|
|
def elixir_to_params(elixir) do |
|
|
|
|
elixir |
|
|
|
|
|> do_elixir_to_params() |
|
|
|
|
|> chain_type_fields(elixir) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp do_elixir_to_params( |
|
|
|
|
%{ |
|
|
|
|
"difficulty" => difficulty, |
|
|
|
|
"extraData" => extra_data, |
|
|
|
|
"gasLimit" => gas_limit, |
|
|
|
|
"gasUsed" => gas_used, |
|
|
|
|
"hash" => hash, |
|
|
|
|
"logsBloom" => logs_bloom, |
|
|
|
|
"miner" => miner_hash, |
|
|
|
|
"number" => number, |
|
|
|
|
"parentHash" => parent_hash, |
|
|
|
|
"receiptsRoot" => receipts_root, |
|
|
|
|
"sha3Uncles" => sha3_uncles, |
|
|
|
|
"size" => size, |
|
|
|
|
"stateRoot" => state_root, |
|
|
|
|
"timestamp" => timestamp, |
|
|
|
|
"totalDifficulty" => total_difficulty, |
|
|
|
|
"transactionsRoot" => transactions_root, |
|
|
|
|
"uncles" => uncles, |
|
|
|
|
"baseFeePerGas" => base_fee_per_gas |
|
|
|
|
} = elixir |
|
|
|
|
) do |
|
|
|
|
%{ |
|
|
|
|
difficulty: difficulty, |
|
|
|
|
extra_data: extra_data, |
|
|
|
@ -245,27 +304,27 @@ defmodule EthereumJSONRPC.Block do |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def elixir_to_params( |
|
|
|
|
%{ |
|
|
|
|
"difficulty" => difficulty, |
|
|
|
|
"extraData" => extra_data, |
|
|
|
|
"gasLimit" => gas_limit, |
|
|
|
|
"gasUsed" => gas_used, |
|
|
|
|
"hash" => hash, |
|
|
|
|
"logsBloom" => logs_bloom, |
|
|
|
|
"miner" => miner_hash, |
|
|
|
|
"number" => number, |
|
|
|
|
"parentHash" => parent_hash, |
|
|
|
|
"receiptsRoot" => receipts_root, |
|
|
|
|
"sha3Uncles" => sha3_uncles, |
|
|
|
|
"size" => size, |
|
|
|
|
"stateRoot" => state_root, |
|
|
|
|
"timestamp" => timestamp, |
|
|
|
|
"transactionsRoot" => transactions_root, |
|
|
|
|
"uncles" => uncles, |
|
|
|
|
"baseFeePerGas" => base_fee_per_gas |
|
|
|
|
} = elixir |
|
|
|
|
) do |
|
|
|
|
defp do_elixir_to_params( |
|
|
|
|
%{ |
|
|
|
|
"difficulty" => difficulty, |
|
|
|
|
"extraData" => extra_data, |
|
|
|
|
"gasLimit" => gas_limit, |
|
|
|
|
"gasUsed" => gas_used, |
|
|
|
|
"hash" => hash, |
|
|
|
|
"logsBloom" => logs_bloom, |
|
|
|
|
"miner" => miner_hash, |
|
|
|
|
"number" => number, |
|
|
|
|
"parentHash" => parent_hash, |
|
|
|
|
"receiptsRoot" => receipts_root, |
|
|
|
|
"sha3Uncles" => sha3_uncles, |
|
|
|
|
"size" => size, |
|
|
|
|
"stateRoot" => state_root, |
|
|
|
|
"timestamp" => timestamp, |
|
|
|
|
"transactionsRoot" => transactions_root, |
|
|
|
|
"uncles" => uncles, |
|
|
|
|
"baseFeePerGas" => base_fee_per_gas |
|
|
|
|
} = elixir |
|
|
|
|
) do |
|
|
|
|
%{ |
|
|
|
|
difficulty: difficulty, |
|
|
|
|
extra_data: extra_data, |
|
|
|
@ -291,27 +350,27 @@ defmodule EthereumJSONRPC.Block do |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
def elixir_to_params( |
|
|
|
|
%{ |
|
|
|
|
"difficulty" => difficulty, |
|
|
|
|
"extraData" => extra_data, |
|
|
|
|
"gasLimit" => gas_limit, |
|
|
|
|
"gasUsed" => gas_used, |
|
|
|
|
"hash" => hash, |
|
|
|
|
"logsBloom" => logs_bloom, |
|
|
|
|
"miner" => miner_hash, |
|
|
|
|
"number" => number, |
|
|
|
|
"parentHash" => parent_hash, |
|
|
|
|
"receiptsRoot" => receipts_root, |
|
|
|
|
"sha3Uncles" => sha3_uncles, |
|
|
|
|
"size" => size, |
|
|
|
|
"stateRoot" => state_root, |
|
|
|
|
"timestamp" => timestamp, |
|
|
|
|
"totalDifficulty" => total_difficulty, |
|
|
|
|
"transactionsRoot" => transactions_root, |
|
|
|
|
"uncles" => uncles |
|
|
|
|
} = elixir |
|
|
|
|
) do |
|
|
|
|
defp do_elixir_to_params( |
|
|
|
|
%{ |
|
|
|
|
"difficulty" => difficulty, |
|
|
|
|
"extraData" => extra_data, |
|
|
|
|
"gasLimit" => gas_limit, |
|
|
|
|
"gasUsed" => gas_used, |
|
|
|
|
"hash" => hash, |
|
|
|
|
"logsBloom" => logs_bloom, |
|
|
|
|
"miner" => miner_hash, |
|
|
|
|
"number" => number, |
|
|
|
|
"parentHash" => parent_hash, |
|
|
|
|
"receiptsRoot" => receipts_root, |
|
|
|
|
"sha3Uncles" => sha3_uncles, |
|
|
|
|
"size" => size, |
|
|
|
|
"stateRoot" => state_root, |
|
|
|
|
"timestamp" => timestamp, |
|
|
|
|
"totalDifficulty" => total_difficulty, |
|
|
|
|
"transactionsRoot" => transactions_root, |
|
|
|
|
"uncles" => uncles |
|
|
|
|
} = elixir |
|
|
|
|
) do |
|
|
|
|
%{ |
|
|
|
|
difficulty: difficulty, |
|
|
|
|
extra_data: extra_data, |
|
|
|
@ -338,26 +397,26 @@ defmodule EthereumJSONRPC.Block do |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
# Geth: a response from eth_getblockbyhash for uncle blocks is without `totalDifficulty` param |
|
|
|
|
def elixir_to_params( |
|
|
|
|
%{ |
|
|
|
|
"difficulty" => difficulty, |
|
|
|
|
"extraData" => extra_data, |
|
|
|
|
"gasLimit" => gas_limit, |
|
|
|
|
"gasUsed" => gas_used, |
|
|
|
|
"hash" => hash, |
|
|
|
|
"logsBloom" => logs_bloom, |
|
|
|
|
"miner" => miner_hash, |
|
|
|
|
"number" => number, |
|
|
|
|
"parentHash" => parent_hash, |
|
|
|
|
"receiptsRoot" => receipts_root, |
|
|
|
|
"sha3Uncles" => sha3_uncles, |
|
|
|
|
"size" => size, |
|
|
|
|
"stateRoot" => state_root, |
|
|
|
|
"timestamp" => timestamp, |
|
|
|
|
"transactionsRoot" => transactions_root, |
|
|
|
|
"uncles" => uncles |
|
|
|
|
} = elixir |
|
|
|
|
) do |
|
|
|
|
defp do_elixir_to_params( |
|
|
|
|
%{ |
|
|
|
|
"difficulty" => difficulty, |
|
|
|
|
"extraData" => extra_data, |
|
|
|
|
"gasLimit" => gas_limit, |
|
|
|
|
"gasUsed" => gas_used, |
|
|
|
|
"hash" => hash, |
|
|
|
|
"logsBloom" => logs_bloom, |
|
|
|
|
"miner" => miner_hash, |
|
|
|
|
"number" => number, |
|
|
|
|
"parentHash" => parent_hash, |
|
|
|
|
"receiptsRoot" => receipts_root, |
|
|
|
|
"sha3Uncles" => sha3_uncles, |
|
|
|
|
"size" => size, |
|
|
|
|
"stateRoot" => state_root, |
|
|
|
|
"timestamp" => timestamp, |
|
|
|
|
"transactionsRoot" => transactions_root, |
|
|
|
|
"uncles" => uncles |
|
|
|
|
} = elixir |
|
|
|
|
) do |
|
|
|
|
%{ |
|
|
|
|
difficulty: difficulty, |
|
|
|
|
extra_data: extra_data, |
|
|
|
@ -382,6 +441,23 @@ defmodule EthereumJSONRPC.Block do |
|
|
|
|
} |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp chain_type_fields(params, elixir) do |
|
|
|
|
case Application.get_env(:explorer, :chain_type) do |
|
|
|
|
"rsk" -> |
|
|
|
|
params |
|
|
|
|
|> Map.merge(%{ |
|
|
|
|
minimum_gas_price: Map.get(elixir, "minimumGasPrice"), |
|
|
|
|
bitcoin_merged_mining_header: Map.get(elixir, "bitcoinMergedMiningHeader"), |
|
|
|
|
bitcoin_merged_mining_coinbase_transaction: Map.get(elixir, "bitcoinMergedMiningCoinbaseTransaction"), |
|
|
|
|
bitcoin_merged_mining_merkle_proof: Map.get(elixir, "bitcoinMergedMiningMerkleProof"), |
|
|
|
|
hash_for_merged_mining: Map.get(elixir, "hashForMergedMining") |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
_ -> |
|
|
|
|
params |
|
|
|
|
end |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
@doc """ |
|
|
|
|
Get `t:EthereumJSONRPC.Transactions.elixir/0` from `t:elixir/0` |
|
|
|
|
|
|
|
|
@ -685,7 +761,7 @@ defmodule EthereumJSONRPC.Block do |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
defp entry_to_elixir({key, quantity}, _block) |
|
|
|
|
when key in ~w(difficulty gasLimit gasUsed minimumGasPrice baseFeePerGas number size cumulativeDifficulty totalDifficulty paidFees) and |
|
|
|
|
when key in ~w(difficulty gasLimit gasUsed minimumGasPrice baseFeePerGas number size cumulativeDifficulty totalDifficulty paidFees minimumGasPrice) and |
|
|
|
|
not is_nil(quantity) do |
|
|
|
|
{key, quantity_to_integer(quantity)} |
|
|
|
|
end |
|
|
|
@ -700,7 +776,7 @@ defmodule EthereumJSONRPC.Block do |
|
|
|
|
# hash format |
|
|
|
|
defp entry_to_elixir({key, _} = entry, _block) |
|
|
|
|
when key in ~w(author extraData hash logsBloom miner mixHash nonce parentHash receiptsRoot sealFields sha3Uncles |
|
|
|
|
signature stateRoot step transactionsRoot uncles withdrawalsRoot), |
|
|
|
|
signature stateRoot step transactionsRoot uncles withdrawalsRoot bitcoinMergedMiningHeader bitcoinMergedMiningCoinbaseTransaction bitcoinMergedMiningMerkleProof hashForMergedMining), |
|
|
|
|
do: entry |
|
|
|
|
|
|
|
|
|
defp entry_to_elixir({"timestamp" = key, timestamp}, _block) do |
|
|
|
|