referrerpolicy=no-referrer-when-downgrade

pallet_revive/evm/api/
rpc_types_gen.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17//! Generated JSON-RPC types.
18#![allow(missing_docs)]
19
20use super::{byte::*, TypeEip1559, TypeEip2930, TypeEip4844, TypeEip7702, TypeLegacy};
21use alloc::vec::Vec;
22use codec::{Decode, Encode};
23use derive_more::{From, TryInto};
24pub use ethereum_types::*;
25use scale_info::TypeInfo;
26use serde::{de::Error, Deserialize, Deserializer, Serialize};
27
28/// Input of a `GenericTransaction`
29#[derive(
30	Debug, Default, Clone, Encode, Decode, TypeInfo, Serialize, Deserialize, Eq, PartialEq,
31)]
32pub struct InputOrData {
33	#[serde(skip_serializing_if = "Option::is_none")]
34	input: Option<Bytes>,
35	#[serde(skip_serializing_if = "Option::is_none")]
36	data: Option<Bytes>,
37}
38
39impl From<Bytes> for InputOrData {
40	fn from(value: Bytes) -> Self {
41		InputOrData { input: Some(value), data: None }
42	}
43}
44
45impl From<Vec<u8>> for InputOrData {
46	fn from(value: Vec<u8>) -> Self {
47		InputOrData { input: Some(Bytes(value)), data: None }
48	}
49}
50
51impl InputOrData {
52	/// Get the input as `Bytes`.
53	pub fn to_bytes(self) -> Bytes {
54		match self {
55			InputOrData { input: Some(input), data: _ } => input,
56			InputOrData { input: None, data: Some(data) } => data,
57			_ => Default::default(),
58		}
59	}
60
61	/// Get the input as `Vec<u8>`.
62	pub fn to_vec(self) -> Vec<u8> {
63		self.to_bytes().0
64	}
65}
66
67fn deserialize_input_or_data<'d, D: Deserializer<'d>>(d: D) -> Result<InputOrData, D::Error> {
68	let value = InputOrData::deserialize(d)?;
69	match &value {
70        InputOrData { input: Some(input), data: Some(data) } if input != data =>
71            Err(serde::de::Error::custom("Both \"data\" and \"input\" are set and not equal. Please use \"input\" to pass transaction call data")),
72        _ => Ok(value),
73    }
74}
75
76/// Block object
77#[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
78#[serde(rename_all = "camelCase")]
79pub struct Block {
80	/// Base fee per gas
81	pub base_fee_per_gas: U256,
82	/// Blob gas used
83	pub blob_gas_used: U256,
84	/// Difficulty
85	pub difficulty: U256,
86	/// Excess blob gas
87	pub excess_blob_gas: U256,
88	/// Extra data
89	pub extra_data: Bytes,
90	/// Gas limit
91	pub gas_limit: U256,
92	/// Gas used
93	pub gas_used: U256,
94	/// Hash
95	pub hash: H256,
96	/// Bloom filter
97	pub logs_bloom: Bytes256,
98	/// Coinbase
99	pub miner: Address,
100	/// Mix hash
101	pub mix_hash: H256,
102	/// Nonce
103	pub nonce: Bytes8,
104	/// Number
105	pub number: U256,
106	/// Parent Beacon Block Root
107	#[serde(skip_serializing_if = "Option::is_none")]
108	pub parent_beacon_block_root: Option<H256>,
109	/// Parent block hash
110	pub parent_hash: H256,
111	/// Receipts root
112	pub receipts_root: H256,
113	/// Requests root
114	#[serde(skip_serializing_if = "Option::is_none")]
115	pub requests_hash: Option<H256>,
116	/// Ommers hash
117	pub sha_3_uncles: H256,
118	/// Block size
119	pub size: U256,
120	/// State root
121	pub state_root: H256,
122	/// Timestamp
123	pub timestamp: U256,
124	/// Total difficulty
125	#[serde(skip_serializing_if = "Option::is_none")]
126	pub total_difficulty: Option<U256>,
127	pub transactions: HashesOrTransactionInfos,
128	/// Transactions root
129	pub transactions_root: H256,
130	/// Uncles
131	pub uncles: Vec<H256>,
132	/// Withdrawals
133	pub withdrawals: Vec<Withdrawal>,
134	/// Withdrawals root
135	pub withdrawals_root: H256,
136}
137
138/// Block number or tag
139#[derive(Debug, Clone, Serialize, Deserialize, From, TryInto, Eq, PartialEq)]
140#[serde(untagged)]
141pub enum BlockNumberOrTag {
142	/// Block number
143	U256(U256),
144	/// Block tag
145	BlockTag(BlockTag),
146}
147impl Default for BlockNumberOrTag {
148	fn default() -> Self {
149		BlockNumberOrTag::BlockTag(Default::default())
150	}
151}
152
153/// Block number, tag, or block hash
154#[derive(Debug, Clone, Serialize, From, TryInto, Eq, PartialEq)]
155#[serde(untagged)]
156pub enum BlockNumberOrTagOrHash {
157	/// Block number
158	BlockNumber(U256),
159	/// Block tag
160	BlockTag(BlockTag),
161	/// Block hash
162	BlockHash(H256),
163}
164impl Default for BlockNumberOrTagOrHash {
165	fn default() -> Self {
166		BlockNumberOrTagOrHash::BlockTag(Default::default())
167	}
168}
169
170// Support nested object notation as defined in  https://eips.ethereum.org/EIPS/eip-1898
171impl<'a> serde::Deserialize<'a> for BlockNumberOrTagOrHash {
172	fn deserialize<D>(de: D) -> Result<Self, D::Error>
173	where
174		D: serde::Deserializer<'a>,
175	{
176		#[derive(Deserialize)]
177		#[serde(untagged)]
178		pub enum BlockNumberOrTagOrHashWithAlias {
179			BlockTag(BlockTag),
180			BlockNumber(U64),
181			NestedBlockNumber {
182				#[serde(rename = "blockNumber")]
183				block_number: U256,
184			},
185			BlockHash(H256),
186			NestedBlockHash {
187				#[serde(rename = "blockHash")]
188				block_hash: H256,
189			},
190		}
191
192		let r = BlockNumberOrTagOrHashWithAlias::deserialize(de)?;
193		Ok(match r {
194			BlockNumberOrTagOrHashWithAlias::BlockTag(val) => BlockNumberOrTagOrHash::BlockTag(val),
195			BlockNumberOrTagOrHashWithAlias::BlockNumber(val) => {
196				let val: u64 =
197					val.try_into().map_err(|_| D::Error::custom("u64 conversion failed"))?;
198				BlockNumberOrTagOrHash::BlockNumber(val.into())
199			},
200
201			BlockNumberOrTagOrHashWithAlias::NestedBlockNumber { block_number: val } =>
202				BlockNumberOrTagOrHash::BlockNumber(val),
203			BlockNumberOrTagOrHashWithAlias::BlockHash(val) |
204			BlockNumberOrTagOrHashWithAlias::NestedBlockHash { block_hash: val } =>
205				BlockNumberOrTagOrHash::BlockHash(val),
206		})
207	}
208}
209
210/// filter
211#[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
212#[serde(rename_all = "camelCase")]
213pub struct Filter {
214	/// Address(es)
215	pub address: Option<AddressOrAddresses>,
216	/// from block
217	#[serde(skip_serializing_if = "Option::is_none")]
218	pub from_block: Option<BlockNumberOrTag>,
219	/// to block
220	#[serde(skip_serializing_if = "Option::is_none")]
221	pub to_block: Option<BlockNumberOrTag>,
222	/// Restricts the logs returned to the single block
223	#[serde(skip_serializing_if = "Option::is_none")]
224	pub block_hash: Option<H256>,
225	/// Topics
226	#[serde(skip_serializing_if = "Option::is_none")]
227	pub topics: Option<FilterTopics>,
228}
229
230/// Filter results
231#[derive(Debug, Clone, Serialize, Deserialize, From, TryInto, Eq, PartialEq)]
232#[serde(untagged)]
233pub enum FilterResults {
234	/// new block or transaction hashes
235	Hashes(Vec<H256>),
236	/// new logs
237	Logs(Vec<Log>),
238}
239impl Default for FilterResults {
240	fn default() -> Self {
241		FilterResults::Hashes(Default::default())
242	}
243}
244
245/// Transaction object generic to all types
246#[derive(
247	Debug, Default, Clone, Encode, Decode, TypeInfo, Serialize, Deserialize, Eq, PartialEq,
248)]
249#[serde(rename_all = "camelCase")]
250pub struct GenericTransaction {
251	/// accessList
252	/// EIP-2930 access list
253	#[serde(skip_serializing_if = "Option::is_none")]
254	pub access_list: Option<AccessList>,
255	/// authorizationList
256	/// List of account code authorizations (EIP-7702)
257	#[serde(default, skip_serializing_if = "Vec::is_empty")]
258	pub authorization_list: Vec<AuthorizationListEntry>,
259	/// blobVersionedHashes
260	/// List of versioned blob hashes associated with the transaction's EIP-4844 data blobs.
261	#[serde(default)]
262	pub blob_versioned_hashes: Vec<H256>,
263	/// blobs
264	/// Raw blob data.
265	#[serde(default, skip_serializing_if = "Vec::is_empty")]
266	pub blobs: Vec<Bytes>,
267	/// chainId
268	/// Chain ID that this transaction is valid on.
269	#[serde(skip_serializing_if = "Option::is_none")]
270	pub chain_id: Option<U256>,
271	/// from address
272	#[serde(skip_serializing_if = "Option::is_none")]
273	pub from: Option<Address>,
274	/// gas limit
275	#[serde(skip_serializing_if = "Option::is_none")]
276	pub gas: Option<U256>,
277	/// gas price
278	/// The gas price willing to be paid by the sender in wei
279	#[serde(skip_serializing_if = "Option::is_none")]
280	pub gas_price: Option<U256>,
281	/// input data
282	#[serde(flatten, deserialize_with = "deserialize_input_or_data")]
283	pub input: InputOrData,
284	/// max fee per blob gas
285	/// The maximum total fee per gas the sender is willing to pay for blob gas in wei
286	#[serde(skip_serializing_if = "Option::is_none")]
287	pub max_fee_per_blob_gas: Option<U256>,
288	/// max fee per gas
289	/// The maximum total fee per gas the sender is willing to pay (includes the network / base fee
290	/// and miner / priority fee) in wei
291	#[serde(skip_serializing_if = "Option::is_none")]
292	pub max_fee_per_gas: Option<U256>,
293	/// max priority fee per gas
294	/// Maximum fee per gas the sender is willing to pay to miners in wei
295	#[serde(skip_serializing_if = "Option::is_none")]
296	pub max_priority_fee_per_gas: Option<U256>,
297	/// nonce
298	#[serde(skip_serializing_if = "Option::is_none")]
299	pub nonce: Option<U256>,
300	/// to address
301	pub to: Option<Address>,
302	/// type
303	#[serde(skip_serializing_if = "Option::is_none")]
304	pub r#type: Option<Byte>,
305	/// value
306	#[serde(skip_serializing_if = "Option::is_none")]
307	pub value: Option<U256>,
308}
309
310/// Receipt information
311#[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
312#[serde(rename_all = "camelCase")]
313pub struct ReceiptInfo {
314	/// blob gas price
315	/// The actual value per gas deducted from the sender's account for blob gas. Only specified
316	/// for blob transactions as defined by EIP-4844.
317	#[serde(skip_serializing_if = "Option::is_none")]
318	pub blob_gas_price: Option<U256>,
319	/// blob gas used
320	/// The amount of blob gas used for this specific transaction. Only specified for blob
321	/// transactions as defined by EIP-4844.
322	#[serde(skip_serializing_if = "Option::is_none")]
323	pub blob_gas_used: Option<U256>,
324	/// block hash
325	pub block_hash: H256,
326	/// block number
327	pub block_number: U256,
328	/// contract address
329	/// The contract address created, if the transaction was a contract creation, otherwise null.
330	pub contract_address: Option<Address>,
331	/// cumulative gas used
332	/// The sum of gas used by this transaction and all preceding transactions in the same block.
333	pub cumulative_gas_used: U256,
334	/// effective gas price
335	/// The actual value per gas deducted from the sender's account. Before EIP-1559, this is equal
336	/// to the transaction's gas price. After, it is equal to baseFeePerGas + min(maxFeePerGas -
337	/// baseFeePerGas, maxPriorityFeePerGas).
338	pub effective_gas_price: U256,
339	/// from
340	pub from: Address,
341	/// gas used
342	/// The amount of gas used for this specific transaction alone.
343	pub gas_used: U256,
344	/// logs
345	pub logs: Vec<Log>,
346	/// logs bloom
347	pub logs_bloom: Bytes256,
348	/// state root
349	/// The post-transaction state root. Only specified for transactions included before the
350	/// Byzantium upgrade.
351	#[serde(skip_serializing_if = "Option::is_none")]
352	pub root: Option<H256>,
353	/// status
354	/// Either 1 (success) or 0 (failure). Only specified for transactions included after the
355	/// Byzantium upgrade.
356	#[serde(skip_serializing_if = "Option::is_none")]
357	pub status: Option<U256>,
358	/// to
359	/// Address of the receiver or null in a contract creation transaction.
360	pub to: Option<Address>,
361	/// transaction hash
362	pub transaction_hash: H256,
363	/// transaction index
364	pub transaction_index: U256,
365	/// type
366	#[serde(skip_serializing_if = "Option::is_none")]
367	pub r#type: Option<Byte>,
368}
369
370/// Syncing status
371#[derive(Debug, Clone, Serialize, Deserialize, From, TryInto, Eq, PartialEq)]
372#[serde(untagged)]
373pub enum SyncingStatus {
374	/// Syncing progress
375	SyncingProgress(SyncingProgress),
376	/// Not syncing
377	/// Should always return false if not syncing.
378	Bool(bool),
379}
380impl Default for SyncingStatus {
381	fn default() -> Self {
382		SyncingStatus::SyncingProgress(Default::default())
383	}
384}
385
386/// Transaction information
387#[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
388#[serde(rename_all = "camelCase")]
389pub struct TransactionInfo {
390	/// block hash
391	pub block_hash: H256,
392	/// block number
393	pub block_number: U256,
394	/// from address
395	pub from: Address,
396	/// transaction hash
397	pub hash: H256,
398	/// transaction index
399	pub transaction_index: U256,
400	#[serde(flatten)]
401	pub transaction_signed: TransactionSigned,
402}
403
404#[derive(Debug, Clone, Serialize, Deserialize, From, TryInto, Eq, PartialEq)]
405#[serde(untagged)]
406pub enum TransactionUnsigned {
407	Transaction7702Unsigned(Transaction7702Unsigned),
408	Transaction4844Unsigned(Transaction4844Unsigned),
409	Transaction1559Unsigned(Transaction1559Unsigned),
410	Transaction2930Unsigned(Transaction2930Unsigned),
411	TransactionLegacyUnsigned(TransactionLegacyUnsigned),
412}
413impl Default for TransactionUnsigned {
414	fn default() -> Self {
415		TransactionUnsigned::TransactionLegacyUnsigned(Default::default())
416	}
417}
418
419/// Access list
420pub type AccessList = Vec<AccessListEntry>;
421
422/// Address(es)
423#[derive(Debug, Clone, Serialize, Deserialize, From, TryInto, Eq, PartialEq)]
424#[serde(untagged)]
425pub enum AddressOrAddresses {
426	/// Address
427	Address(Address),
428	/// Addresses
429	Addresses(Addresses),
430}
431impl Default for AddressOrAddresses {
432	fn default() -> Self {
433		AddressOrAddresses::Address(Default::default())
434	}
435}
436
437/// hex encoded address
438pub type Addresses = Vec<Address>;
439
440/// Block tag
441/// `earliest`: The lowest numbered block the client has available; `finalized`: The most recent
442/// crypto-economically secure block, cannot be re-orged outside of manual intervention driven by
443/// community coordination; `safe`: The most recent block that is safe from re-orgs under honest
444/// majority and certain synchronicity assumptions; `latest`: The most recent block in the canonical
445/// chain observed by the client, this block may be re-orged out of the canonical chain even under
446/// healthy/normal conditions; `pending`: A sample next block built by the client on top of `latest`
447/// and containing the set of transactions usually taken from local mempool. Before the merge
448/// transition is finalized, any call querying for `finalized` or `safe` block MUST be responded to
449/// with `-39001: Unknown block` error
450#[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
451#[serde(rename_all = "lowercase")]
452pub enum BlockTag {
453	Earliest,
454	Finalized,
455	Safe,
456	#[default]
457	Latest,
458	Pending,
459}
460
461/// Filter Topics
462pub type FilterTopics = Vec<FilterTopic>;
463
464#[derive(Debug, Clone, Serialize, Deserialize, From, TryInto, Eq, PartialEq)]
465#[serde(untagged)]
466pub enum HashesOrTransactionInfos {
467	/// Transaction hashes
468	Hashes(Vec<H256>),
469	/// Full transactions
470	TransactionInfos(Vec<TransactionInfo>),
471}
472impl Default for HashesOrTransactionInfos {
473	fn default() -> Self {
474		HashesOrTransactionInfos::Hashes(Default::default())
475	}
476}
477
478/// log
479#[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
480#[serde(rename_all = "camelCase")]
481pub struct Log {
482	/// address
483	pub address: Address,
484	/// block hash
485	pub block_hash: H256,
486	/// block number
487	pub block_number: U256,
488	/// data
489	#[serde(skip_serializing_if = "Option::is_none")]
490	pub data: Option<Bytes>,
491	/// log index
492	pub log_index: U256,
493	/// removed
494	#[serde(default)]
495	pub removed: bool,
496	/// topics
497	#[serde(default)]
498	pub topics: Vec<H256>,
499	/// transaction hash
500	pub transaction_hash: H256,
501	/// transaction index
502	pub transaction_index: U256,
503}
504
505/// Syncing progress
506#[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
507#[serde(rename_all = "camelCase")]
508pub struct SyncingProgress {
509	/// Current block
510	#[serde(skip_serializing_if = "Option::is_none")]
511	pub current_block: Option<U256>,
512	/// Highest block
513	#[serde(skip_serializing_if = "Option::is_none")]
514	pub highest_block: Option<U256>,
515	/// Starting block
516	#[serde(skip_serializing_if = "Option::is_none")]
517	pub starting_block: Option<U256>,
518}
519
520/// EIP-1559 transaction.
521#[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
522#[serde(rename_all = "camelCase")]
523pub struct Transaction1559Unsigned {
524	/// accessList
525	/// EIP-2930 access list
526	pub access_list: AccessList,
527	/// chainId
528	/// Chain ID that this transaction is valid on.
529	pub chain_id: U256,
530	/// gas limit
531	pub gas: U256,
532	/// gas price
533	/// The effective gas price paid by the sender in wei. For transactions not yet included in a
534	/// block, this value should be set equal to the max fee per gas. This field is DEPRECATED,
535	/// please transition to using effectiveGasPrice in the receipt object going forward.
536	pub gas_price: U256,
537	/// input data
538	pub input: Bytes,
539	/// max fee per gas
540	/// The maximum total fee per gas the sender is willing to pay (includes the network / base fee
541	/// and miner / priority fee) in wei
542	pub max_fee_per_gas: U256,
543	/// max priority fee per gas
544	/// Maximum fee per gas the sender is willing to pay to miners in wei
545	pub max_priority_fee_per_gas: U256,
546	/// nonce
547	pub nonce: U256,
548	/// to address
549	pub to: Option<Address>,
550	/// type
551	pub r#type: TypeEip1559,
552	/// value
553	pub value: U256,
554}
555
556/// EIP-2930 transaction.
557#[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
558#[serde(rename_all = "camelCase")]
559pub struct Transaction2930Unsigned {
560	/// accessList
561	/// EIP-2930 access list
562	pub access_list: AccessList,
563	/// chainId
564	/// Chain ID that this transaction is valid on.
565	pub chain_id: U256,
566	/// gas limit
567	pub gas: U256,
568	/// gas price
569	/// The gas price willing to be paid by the sender in wei
570	pub gas_price: U256,
571	/// input data
572	pub input: Bytes,
573	/// nonce
574	pub nonce: U256,
575	/// to address
576	pub to: Option<Address>,
577	/// type
578	pub r#type: TypeEip2930,
579	/// value
580	pub value: U256,
581}
582
583/// EIP-4844 transaction.
584#[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
585#[serde(rename_all = "camelCase")]
586pub struct Transaction4844Unsigned {
587	/// accessList
588	/// EIP-2930 access list
589	pub access_list: AccessList,
590	/// blobVersionedHashes
591	/// List of versioned blob hashes associated with the transaction's EIP-4844 data blobs.
592	pub blob_versioned_hashes: Vec<H256>,
593	/// chainId
594	/// Chain ID that this transaction is valid on.
595	pub chain_id: U256,
596	/// gas limit
597	pub gas: U256,
598	/// input data
599	pub input: Bytes,
600	/// max fee per blob gas
601	/// The maximum total fee per gas the sender is willing to pay for blob gas in wei
602	pub max_fee_per_blob_gas: U256,
603	/// max fee per gas
604	/// The maximum total fee per gas the sender is willing to pay (includes the network / base fee
605	/// and miner / priority fee) in wei
606	pub max_fee_per_gas: U256,
607	/// max priority fee per gas
608	/// Maximum fee per gas the sender is willing to pay to miners in wei
609	pub max_priority_fee_per_gas: U256,
610	/// nonce
611	pub nonce: U256,
612	/// to address
613	pub to: Address,
614	/// type
615	pub r#type: TypeEip4844,
616	/// value
617	pub value: U256,
618}
619
620/// Legacy transaction.
621#[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
622#[serde(rename_all = "camelCase")]
623pub struct TransactionLegacyUnsigned {
624	/// chainId
625	/// Chain ID that this transaction is valid on.
626	#[serde(skip_serializing_if = "Option::is_none")]
627	pub chain_id: Option<U256>,
628	/// gas limit
629	pub gas: U256,
630	/// gas price
631	/// The gas price willing to be paid by the sender in wei
632	pub gas_price: U256,
633	/// input data
634	pub input: Bytes,
635	/// nonce
636	pub nonce: U256,
637	/// to address
638	pub to: Option<Address>,
639	/// type
640	pub r#type: TypeLegacy,
641	/// value
642	pub value: U256,
643}
644
645/// EIP-7702 transaction.
646#[derive(
647	Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq, TypeInfo, Encode, Decode,
648)]
649#[serde(rename_all = "camelCase")]
650pub struct Transaction7702Unsigned {
651	/// accessList
652	/// EIP-2930 access list
653	pub access_list: AccessList,
654	/// authorizationList
655	/// List of account code authorizations
656	pub authorization_list: Vec<AuthorizationListEntry>,
657	/// chainId
658	/// Chain ID that this transaction is valid on.
659	pub chain_id: U256,
660	/// gas limit
661	pub gas: U256,
662	/// gas price
663	/// The effective gas price paid by the sender in wei. For transactions not yet included in a
664	/// block, this value should be set equal to the max fee per gas. This field is DEPRECATED,
665	/// please transition to using effectiveGasPrice in the receipt object going forward.
666	pub gas_price: U256,
667	/// input data
668	pub input: Bytes,
669	/// max fee per gas
670	/// The maximum total fee per gas the sender is willing to pay (includes the network / base fee
671	/// and miner / priority fee) in wei
672	pub max_fee_per_gas: U256,
673	/// max priority fee per gas
674	/// Maximum fee per gas the sender is willing to pay to miners in wei
675	pub max_priority_fee_per_gas: U256,
676	/// nonce
677	pub nonce: U256,
678	/// to address
679	pub to: Option<Address>,
680	/// type
681	pub r#type: TypeEip7702,
682	/// value
683	pub value: U256,
684}
685
686/// Authorization list entry for EIP-7702
687#[derive(
688	Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq, TypeInfo, Encode, Decode,
689)]
690#[serde(rename_all = "camelCase")]
691pub struct AuthorizationListEntry {
692	/// Chain ID that this authorization is valid on
693	pub chain_id: U256,
694	/// Address to authorize
695	pub address: Address,
696	/// Nonce of the authorization
697	pub nonce: U256,
698	/// y-parity of the signature
699	pub y_parity: U256,
700	/// r component of signature
701	pub r: U256,
702	/// s component of signature
703	pub s: U256,
704}
705
706#[derive(Debug, Clone, Serialize, Deserialize, From, TryInto, Eq, PartialEq)]
707#[serde(untagged)]
708pub enum TransactionSigned {
709	Transaction7702Signed(Transaction7702Signed),
710	Transaction4844Signed(Transaction4844Signed),
711	Transaction1559Signed(Transaction1559Signed),
712	Transaction2930Signed(Transaction2930Signed),
713	TransactionLegacySigned(TransactionLegacySigned),
714}
715impl Default for TransactionSigned {
716	fn default() -> Self {
717		TransactionSigned::TransactionLegacySigned(Default::default())
718	}
719}
720
721impl TransactionSigned {
722	/// Get the effective gas price.
723	pub fn effective_gas_price(&self, base_gas_price: U256) -> U256 {
724		match &self {
725			TransactionSigned::TransactionLegacySigned(tx) =>
726				tx.transaction_legacy_unsigned.gas_price,
727			TransactionSigned::Transaction7702Signed(tx) => base_gas_price
728				.saturating_add(tx.transaction_7702_unsigned.max_priority_fee_per_gas)
729				.min(tx.transaction_7702_unsigned.max_fee_per_gas),
730			TransactionSigned::Transaction4844Signed(tx) => base_gas_price
731				.saturating_add(tx.transaction_4844_unsigned.max_priority_fee_per_gas)
732				.min(tx.transaction_4844_unsigned.max_fee_per_blob_gas),
733			TransactionSigned::Transaction1559Signed(tx) => base_gas_price
734				.saturating_add(tx.transaction_1559_unsigned.max_priority_fee_per_gas)
735				.min(tx.transaction_1559_unsigned.max_fee_per_gas),
736			TransactionSigned::Transaction2930Signed(tx) => tx.transaction_2930_unsigned.gas_price,
737		}
738	}
739}
740
741/// Validator withdrawal
742#[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
743#[serde(rename_all = "camelCase")]
744pub struct Withdrawal {
745	/// recipient address for withdrawal value
746	pub address: Address,
747	/// value contained in withdrawal
748	pub amount: U256,
749	/// index of withdrawal
750	pub index: U256,
751	/// index of validator that generated withdrawal
752	pub validator_index: U256,
753}
754
755/// Access list entry
756#[derive(
757	Debug, Default, Clone, Encode, Decode, TypeInfo, Serialize, Deserialize, Eq, PartialEq,
758)]
759#[serde(rename_all = "camelCase")]
760pub struct AccessListEntry {
761	pub address: Address,
762	pub storage_keys: Vec<H256>,
763}
764
765/// Filter Topic List Entry
766#[derive(Debug, Clone, Serialize, Deserialize, From, TryInto, Eq, PartialEq)]
767#[serde(untagged)]
768pub enum FilterTopic {
769	/// Single Topic Match
770	Single(H256),
771	/// Multiple Topic Match
772	Multiple(Vec<H256>),
773}
774impl Default for FilterTopic {
775	fn default() -> Self {
776		FilterTopic::Single(Default::default())
777	}
778}
779
780/// Signed 7702 Transaction
781#[derive(
782	Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq, TypeInfo, Encode, Decode,
783)]
784#[serde(rename_all = "camelCase")]
785pub struct Transaction7702Signed {
786	#[serde(flatten)]
787	pub transaction_7702_unsigned: Transaction7702Unsigned,
788	/// r
789	pub r: U256,
790	/// s
791	pub s: U256,
792	/// v
793	/// For backwards compatibility, `v` is optionally provided as an alternative to `yParity`.
794	/// This field is DEPRECATED and all use of it should migrate to `yParity`.
795	#[serde(skip_serializing_if = "Option::is_none")]
796	pub v: Option<U256>,
797	/// yParity
798	/// The parity (0 for even, 1 for odd) of the y-value of the secp256k1 signature.
799	pub y_parity: U256,
800}
801
802/// Signed 1559 Transaction
803#[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
804#[serde(rename_all = "camelCase")]
805pub struct Transaction1559Signed {
806	#[serde(flatten)]
807	pub transaction_1559_unsigned: Transaction1559Unsigned,
808	/// r
809	pub r: U256,
810	/// s
811	pub s: U256,
812	/// v
813	/// For backwards compatibility, `v` is optionally provided as an alternative to `yParity`.
814	/// This field is DEPRECATED and all use of it should migrate to `yParity`.
815	#[serde(skip_serializing_if = "Option::is_none")]
816	pub v: Option<U256>,
817	/// yParity
818	/// The parity (0 for even, 1 for odd) of the y-value of the secp256k1 signature.
819	pub y_parity: U256,
820}
821
822/// Signed 2930 Transaction
823#[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
824#[serde(rename_all = "camelCase")]
825pub struct Transaction2930Signed {
826	#[serde(flatten)]
827	pub transaction_2930_unsigned: Transaction2930Unsigned,
828	/// r
829	pub r: U256,
830	/// s
831	pub s: U256,
832	/// v
833	/// For backwards compatibility, `v` is optionally provided as an alternative to `yParity`.
834	/// This field is DEPRECATED and all use of it should migrate to `yParity`.
835	#[serde(skip_serializing_if = "Option::is_none")]
836	pub v: Option<U256>,
837	/// yParity
838	/// The parity (0 for even, 1 for odd) of the y-value of the secp256k1 signature.
839	pub y_parity: U256,
840}
841
842/// Signed 4844 Transaction
843#[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
844#[serde(rename_all = "camelCase")]
845pub struct Transaction4844Signed {
846	#[serde(flatten)]
847	pub transaction_4844_unsigned: Transaction4844Unsigned,
848	/// r
849	pub r: U256,
850	/// s
851	pub s: U256,
852	/// yParity
853	/// The parity (0 for even, 1 for odd) of the y-value of the secp256k1 signature.
854	pub y_parity: U256,
855}
856
857/// Signed Legacy Transaction
858#[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq)]
859pub struct TransactionLegacySigned {
860	#[serde(flatten)]
861	pub transaction_legacy_unsigned: TransactionLegacyUnsigned,
862	/// r
863	pub r: U256,
864	/// s
865	pub s: U256,
866	/// v
867	pub v: U256,
868}
869
870#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
871#[serde(rename_all = "camelCase")]
872pub struct FeeHistoryResult {
873	/// Lowest number block of the returned range.
874	pub oldest_block: U256,
875
876	/// An array of block base fees per gas.
877	///
878	/// This includes the next block after the newest of the returned range, because this value can
879	/// be derived from the newest block. Zeroes are returned for pre-EIP-1559 blocks.
880	#[serde(default, skip_serializing_if = "Vec::is_empty")]
881	pub base_fee_per_gas: Vec<U256>,
882
883	/// An array of block gas used ratios.
884	/// These are calculated as the ratio of `gasUsed` and `gasLimit`.
885	pub gas_used_ratio: Vec<f64>,
886
887	/// A two-dimensional array of effective priority fees per gas at the requested block
888	/// percentiles.
889	///
890	/// A given percentile sample of effective priority fees per gas from a single block in
891	/// ascending order, weighted by gas used. Zeroes are returned if the block is empty.
892	#[serde(default, skip_serializing_if = "Vec::is_empty")]
893	pub reward: Vec<Vec<U256>>,
894}
895
896#[cfg(test)]
897mod tests {
898	use super::*;
899
900	#[test]
901	fn test_block_serialization_roundtrip() {
902		let json_input = r#"{
903			"baseFeePerGas": "0x126f2347",
904			"blobGasUsed": "0x100000",
905			"difficulty": "0x0",
906			"excessBlobGas": "0x0",
907			"extraData": "0x546974616e2028746974616e6275696c6465722e78797a29",
908			"gasLimit": "0x2aca2c9",
909			"gasUsed": "0x1c06043",
910			"hash": "0xe6064637def8a5a9a90c8a666005975e4a6c46acf8af57e1f2adb20dfced133a",
911			"logsBloom": "0xbf7bf1afcf57ea95fbb5c6fd8db37db9dbffec27cfc6a39b3417e7786defd7e3d6fd577ecddd5676eee8bf79df8faddcefa7e169def77f7e7d6dbbfd1dfef9aebd9e707b4c4ed979fda2cdeeb96b3bfed5d5fabb68ff9e7f2dfb075eff643a93feebbc07877f0dff66fedf4ede0fbcfbf56f98a1626eaed77ed4e6be388f162f9b2deeff1eefa93bdacbf3fbbd7b6757cddb7ae5b3f9b7af9c3bbff7e7f6ddef9f2dff7f17997ea6867675c29fcbe6bf725efbffe1507589bfd47a3bf7b6f5dfde50776fd94fe772d2c7b6b58baf554de55c176f27efa6fdcff7f17689bafa7f7c7bf4fd5fb9b05c2f4ed785f17ac9779feeaf1f5bbdadfc42ebad367fdcf7ad",
912			"miner": "0x4838b106fce9647bdf1e7877bf73ce8b0bad5f97",
913			"mixHash": "0x7e53d2d6772895d024eb00da80213aec81fb4a15bec34a5a39403ad6162274af",
914			"nonce": "0x0000000000000000",
915			"number": "0x1606672",
916			"parentBeaconBlockRoot": "0xd9ef51c8f4155f238ba66df0d35a4d0a6bb043c0dacb5c5dbd5a231bbd4c8a01",
917			"parentHash": "0x37b527c98c86436f292d4e19fac3aba6d8c7768684ea972f50adc305fd9a1475",
918			"receiptsRoot": "0x2abab67c41b350435eb34f9dc0478dd7d262f35544cecf62a85af2da075bd38d",
919			"requestsHash": "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
920			"sha3Uncles": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
921			"size": "0x29e6c",
922			"stateRoot": "0x5159c56472adff9a760275ac63524a71f5645ede822a5547dd9ad333586d5157",
923			"timestamp": "0x6895a93f",
924			"transactions": [],
925			"transactionsRoot": "0xfb0b9f5b28bc927db98d82e18070d2b17434c31bd2773c5dd699e96fa76a34cd",
926			"uncles": [],
927			"withdrawals": [],
928			"withdrawalsRoot": "0x531480435633d56a52433b33f41ac9322f51a2df3364c4c112236fc6ac583118"
929		}"#;
930
931		// Deserialize the JSON into a Block
932		let block: Block = serde_json::from_str(json_input).expect("Failed to deserialize block");
933
934		// Serialize it back to JSON
935		let serialized = serde_json::to_string(&block).expect("Failed to serialize block");
936
937		// Deserialize again to ensure roundtrip consistency
938		let block_roundtrip: Block =
939			serde_json::from_str(&serialized).expect("Failed to deserialize roundtrip block");
940
941		// Verify that deserializing and serializing leads to the same result
942		assert_eq!(block, block_roundtrip);
943	}
944}