fc_rpc_v2_types/
block.rs

1// This file is part of Frontier.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19use ethereum_types::{Address, Bloom, H256, U256, U64};
20use serde::{Deserialize, Serialize};
21
22use crate::{bytes::Bytes, transaction::Transaction};
23
24/// Block information.
25#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
26#[serde(rename_all = "camelCase")]
27pub struct Block {
28	/// Block header.
29	#[serde(flatten)]
30	pub header: Header,
31
32	/// Block transactions.
33	pub transactions: BlockTransactions,
34
35	/// Uncles' hashes.
36	#[serde(default)]
37	pub uncles: Vec<H256>,
38
39	/// Block size in bytes.
40	#[serde(default, skip_serializing_if = "Option::is_none")]
41	pub size: Option<U256>,
42
43	/// Withdrawals, see [EIP-4895](https://eips.ethereum.org/EIPS/eip-4895).
44	#[serde(skip_serializing_if = "Option::is_none")]
45	pub withdrawals: Option<Vec<Withdrawal>>,
46}
47
48/// Block header representation.
49#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
50#[serde(rename_all = "camelCase")]
51pub struct Header {
52	/// Block number.
53	pub number: U256,
54	/// Block hash.
55	pub hash: Option<H256>,
56	/// Hash of the parent block.
57	pub parent_hash: H256,
58	/// Hash of the uncles.
59	#[serde(rename = "sha3Uncles")]
60	pub uncles_hash: H256,
61	/// Nonce.
62	pub nonce: Option<U64>,
63	/// Authors address.
64	#[serde(rename = "miner")]
65	pub author: Address,
66	/// State root hash.
67	pub state_root: H256,
68	/// Transactions root hash.
69	pub transactions_root: H256,
70	/// Transactions receipts root hash.
71	pub receipts_root: H256,
72	/// Logs bloom.
73	pub logs_bloom: Bloom,
74	/// Gas limit.
75	pub gas_limit: U256,
76	/// Gas used
77	pub gas_used: U256,
78	/// Timestamp.
79	pub timestamp: U64,
80	/// Extra data.
81	pub extra_data: Bytes,
82	/// Difficulty.
83	pub difficulty: U256,
84	/// Total difficulty.
85	#[serde(skip_serializing_if = "Option::is_none")]
86	pub total_difficulty: Option<U256>,
87	/// Mix hash.
88	#[serde(default, skip_serializing_if = "Option::is_none")]
89	pub mix_hash: Option<H256>,
90
91	/// Base fee per unit of gas, which is added by [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559).
92	#[serde(default, skip_serializing_if = "Option::is_none")]
93	pub base_fee_per_gas: Option<U256>,
94	/// Withdrawals root hash, which is added by [EIP-4895](https://eips.ethereum.org/EIPS/eip-4895).
95	#[serde(skip_serializing_if = "Option::is_none")]
96	pub withdrawals_root: Option<H256>,
97	/// Parent beacon block root, which is added by [EIP-4788](https://eips.ethereum.org/EIPS/eip-4788).
98	#[serde(skip_serializing_if = "Option::is_none")]
99	pub parent_beacon_block_root: Option<H256>,
100}
101
102/// Block Transactions
103#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
104#[serde(untagged)]
105pub enum BlockTransactions {
106	/// Only hashes.
107	Hashes(Vec<H256>),
108	/// Full transactions.
109	Full(Vec<Transaction>),
110}
111
112// Withdrawal represents a validator withdrawal from the consensus layer.
113#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
114#[serde(rename_all = "camelCase")]
115pub struct Withdrawal {
116	/// Monotonically increasing identifier issued by consensus layer.
117	pub index: U64,
118	/// Index of validator associated with withdrawal.
119	pub validator_index: U64,
120	/// Target address for withdrawn ether.
121	pub address: Address,
122	/// Value of withdrawal in Gwei.
123	pub amount: U64,
124}
125
126/// [`BlockOverrides`] is a set of header fields to override.
127#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
128#[serde(default, rename_all = "camelCase")]
129pub struct BlockOverrides {
130	/// Fake block number.
131	// Note: geth uses `number`, erigon uses `blockNumber`
132	#[serde(
133		default,
134		skip_serializing_if = "Option::is_none",
135		alias = "blockNumber"
136	)]
137	pub number: Option<U256>,
138	/// Fake difficulty.
139	// Note post-merge difficulty should be 0.
140	#[serde(default, skip_serializing_if = "Option::is_none")]
141	pub difficulty: Option<U256>,
142	/// Fake block timestamp.
143	// Note: geth uses `time`, erigon uses `timestamp`
144	#[serde(default, skip_serializing_if = "Option::is_none", alias = "timestamp")]
145	pub time: Option<U64>,
146	/// Block gas capacity.
147	#[serde(default, skip_serializing_if = "Option::is_none")]
148	pub gas_limit: Option<U64>,
149	/// Block fee recipient.
150	#[serde(default, skip_serializing_if = "Option::is_none")]
151	pub coinbase: Option<Address>,
152	/// Fake PrevRandao value.
153	#[serde(default, skip_serializing_if = "Option::is_none")]
154	pub random: Option<H256>,
155	/// Block base fee.
156	#[serde(default, skip_serializing_if = "Option::is_none")]
157	pub base_fee: Option<U256>,
158}