Skip to content

Commit

Permalink
feat: add epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
DenSmolonski committed Sep 12, 2024
1 parent f1db75c commit 0df605e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ defmodule BlockScoutWeb.API.V2.BlockView do
"miner" => Helper.address_with_info(nil, block.miner, block.miner_hash, false),
"size" => block.size,
"hash" => block.hash,
"epoch" => block.epoch,
"parent_hash" => block.parent_hash,
"difficulty" => block.difficulty,
"total_difficulty" => block.total_difficulty,
Expand Down
14 changes: 13 additions & 1 deletion apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ defmodule EthereumJSONRPC.Block do
extra_data: EthereumJSONRPC.hash(),
gas_limit: non_neg_integer(),
gas_used: non_neg_integer(),
epoch: non_neg_integer(),
hash: EthereumJSONRPC.hash(),
logs_bloom: EthereumJSONRPC.hash(),
miner_hash: EthereumJSONRPC.hash(),
Expand All @@ -53,6 +54,7 @@ defmodule EthereumJSONRPC.Block do
* `"difficulty"` - `t:EthereumJSONRPC.quantity/0` of the difficulty for this block.
* `"extraData"` - the extra `t:EthereumJSONRPC.data/0` field of this block.
* `"gasLimit" - maximum gas `t:EthereumJSONRPC.quantity/0` in this block.
* `"epoch"` - `t:EthereumJSONRPC.quantity/0` of the epoch for this block.
* `"gasUsed" - the total `t:EthereumJSONRPC.quantity/0` of gas used by all transactions in this block.
* `"hash"` - the `t:EthereumJSONRPC.hash/0` of the block.
* `"logsBloom"` - `t:EthereumJSONRPC.data/0` for the [Bloom filter](https://en.wikipedia.org/wiki/Bloom_filter)
Expand Down Expand Up @@ -262,6 +264,7 @@ defmodule EthereumJSONRPC.Block do
"extraData" => extra_data,
"gasLimit" => gas_limit,
"gasUsed" => gas_used,
"epoch" => epoch,
"hash" => hash,
"logsBloom" => logs_bloom,
"miner" => miner_hash,
Expand All @@ -283,6 +286,7 @@ defmodule EthereumJSONRPC.Block do
extra_data: extra_data,
gas_limit: gas_limit,
gas_used: gas_used,
epoch: epoch,
hash: hash,
logs_bloom: logs_bloom,
miner_hash: miner_hash,
Expand Down Expand Up @@ -311,6 +315,7 @@ defmodule EthereumJSONRPC.Block do
"gasLimit" => gas_limit,
"gasUsed" => gas_used,
"hash" => hash,
"epoch" => epoch,
"logsBloom" => logs_bloom,
"miner" => miner_hash,
"number" => number,
Expand All @@ -332,6 +337,7 @@ defmodule EthereumJSONRPC.Block do
gas_used: gas_used,
hash: hash,
logs_bloom: logs_bloom,
epoch: epoch,
miner_hash: miner_hash,
mix_hash: Map.get(elixir, "mixHash", "0x0"),
nonce: Map.get(elixir, "nonce", 0),
Expand All @@ -358,6 +364,7 @@ defmodule EthereumJSONRPC.Block do
"gasUsed" => gas_used,
"hash" => hash,
"logsBloom" => logs_bloom,
"epoch" => epoch,
"miner" => miner_hash,
"number" => number,
"parentHash" => parent_hash,
Expand All @@ -379,6 +386,7 @@ defmodule EthereumJSONRPC.Block do
hash: hash,
logs_bloom: logs_bloom,
miner_hash: miner_hash,
epoch: epoch,
mix_hash: Map.get(elixir, "mixHash", "0x0"),
nonce: Map.get(elixir, "nonce", 0),
number: number,
Expand Down Expand Up @@ -406,6 +414,7 @@ defmodule EthereumJSONRPC.Block do
"hash" => hash,
"logsBloom" => logs_bloom,
"miner" => miner_hash,
"epoch" => epoch,
"number" => number,
"parentHash" => parent_hash,
"receiptsRoot" => receipts_root,
Expand All @@ -425,6 +434,7 @@ defmodule EthereumJSONRPC.Block do
hash: hash,
logs_bloom: logs_bloom,
miner_hash: miner_hash,
epoch: epoch,
mix_hash: Map.get(elixir, "mixHash", "0x0"),
nonce: Map.get(elixir, "nonce", 0),
number: number,
Expand All @@ -448,6 +458,7 @@ defmodule EthereumJSONRPC.Block do
"gasLimit" => gas_limit,
"gasUsed" => gas_used,
"hash" => hash,
"epoch" => epoch,
"logsBloom" => logs_bloom,
"miner" => miner_hash,
"number" => number,
Expand All @@ -471,6 +482,7 @@ defmodule EthereumJSONRPC.Block do
mix_hash: Map.get(elixir, "mixHash", "0x0"),
nonce: Map.get(elixir, "nonce", 0),
number: number,
epoch: epoch,
parent_hash: parent_hash,
receipts_root: receipts_root,
size: size,
Expand Down Expand Up @@ -806,7 +818,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 minimumGasPrice) and
when key in ~w(difficulty gasLimit gasUsed minimumGasPrice baseFeePerGas number size cumulativeDifficulty totalDifficulty paidFees minimumGasPrice epoch) and
not is_nil(quantity) do
{key, quantity_to_integer(quantity)}
end
Expand Down
2 changes: 1 addition & 1 deletion apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/block/by_tag.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule EthereumJSONRPC.Block.ByTag do
alias EthereumJSONRPC.Blocks

def request(%{id: id, tag: tag}) when is_binary(tag) do
EthereumJSONRPC.request(%{id: id, method: "eth_getBlockByNumber", params: [tag, false]})
EthereumJSONRPC.request(%{id: id, method: "hmy_getBlockByNumber", params: [tag, false]})
end

def number_from_result({:ok, %{"number" => nil}}), do: {:error, :not_found}
Expand Down
1 change: 0 additions & 1 deletion apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/blocks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ defmodule EthereumJSONRPC.Blocks do
{:error, error}, %{errors: errors} = acc ->
%{acc | errors: [error | errors]}
end)

elixir_blocks = to_elixir(blocks)

elixir_uncles = elixir_to_uncles(elixir_blocks)
Expand Down
4 changes: 3 additions & 1 deletion apps/explorer/lib/explorer/chain/block.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Explorer.Chain.Block do
alias Explorer.Chain.Block.{EmissionReward, Reward, SecondDegreeRelation}
alias Explorer.Repo

@optional_attrs ~w(size refetch_needed total_difficulty difficulty base_fee_per_gas)a
@optional_attrs ~w(size refetch_needed total_difficulty difficulty base_fee_per_gas epoch)a
|> (&(case Application.compile_env(:explorer, :chain_type) do
"rsk" ->
&1 ++
Expand Down Expand Up @@ -104,6 +104,7 @@ defmodule Explorer.Chain.Block do
number: block_number(),
parent_hash: Hash.t(),
size: non_neg_integer(),
epoch: non_neg_integer(),
timestamp: DateTime.t(),
total_difficulty: difficulty(),
transactions: %Ecto.Association.NotLoaded{} | [Transaction.t()],
Expand All @@ -120,6 +121,7 @@ defmodule Explorer.Chain.Block do
field(:gas_used, :decimal)
field(:nonce, Hash.Nonce)
field(:number, :integer)
field(:epoch, :integer)
field(:size, :integer)
field(:timestamp, :utc_datetime_usec)
field(:total_difficulty, :decimal)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Explorer.Repo.Migrations.AddEpochToBlock do
use Ecto.Migration

def change do
alter table(:blocks) do
add(:epoch, :bigint, null: true)
end
end
end

0 comments on commit 0df605e

Please sign in to comment.