11use serde:: { Deserialize , Serialize } ;
2+ use std:: collections:: BTreeMap ;
3+
4+ use crate :: fork_id:: ForkId ;
5+
6+ /// Hex-encoded quantity helper.
7+ #[ derive( Debug , Clone , Copy , PartialEq , Eq , Default ) ]
8+ pub struct HexU64 ( pub u64 ) ;
9+
10+ impl Serialize for HexU64 {
11+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
12+ where
13+ S : serde:: Serializer ,
14+ {
15+ serializer. serialize_str ( & format ! ( "0x{:x}" , self . 0 ) )
16+ }
17+ }
18+
19+ impl < ' de > Deserialize < ' de > for HexU64 {
20+ fn deserialize < D > ( deserializer : D ) -> Result < Self , D :: Error >
21+ where
22+ D : serde:: Deserializer < ' de > ,
23+ {
24+ let s = String :: deserialize ( deserializer) ?;
25+ let s = s. strip_prefix ( "0x" ) . unwrap_or ( & s) ;
26+ u64:: from_str_radix ( s, 16 )
27+ . map ( HexU64 )
28+ . map_err ( |e| serde:: de:: Error :: custom ( format ! ( "invalid hex quantity: {e}" ) ) )
29+ }
30+ }
231
332/// Blob gas scheduling parameters (EIP-4844 style).
433#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , Default ) ]
534#[ serde( rename_all = "camelCase" ) ]
635pub struct BlobSchedule {
7- pub max_blob_gas_per_block : u64 ,
8- pub target_blob_gas_per_block : u64 ,
9- pub blob_gasprice_update_fraction : u64 ,
36+ pub max_blob_gas_per_block : HexU64 ,
37+ pub target_blob_gas_per_block : HexU64 ,
38+ pub blob_gasprice_update_fraction : HexU64 ,
1039}
1140
1241/// Fork-level configuration object as returned by eth_config.
@@ -15,17 +44,18 @@ pub struct BlobSchedule {
1544pub struct ForkConfig {
1645 /// Human-readable fork name (e.g. "cancun").
1746 pub name : String ,
18- /// Block number at which the fork activates; null in EIP becomes None here .
47+ /// Block number at which the fork activates.
1948 #[ serde( skip_serializing_if = "Option::is_none" ) ]
20- pub block : Option < u64 > ,
49+ pub block : Option < HexU64 > ,
2150 /// Optional blob gas schedule parameters for blob-enabled forks.
2251 #[ serde( skip_serializing_if = "Option::is_none" ) ]
2352 pub blob_schedule : Option < BlobSchedule > ,
2453 /// List of enabled precompiles at this fork (hex addresses as strings).
25- pub precompiles : Vec < String > ,
54+ #[ serde( default ) ]
55+ pub precompiles : BTreeMap < String , String > ,
2656 /// List of system contracts active at this fork.
2757 #[ serde( default ) ]
28- pub system_contracts : Vec < SystemContract > ,
58+ pub system_contracts : BTreeMap < String , SystemContract > ,
2959}
3060
3161/// System contract entry in eth_config response.
@@ -50,10 +80,10 @@ pub struct ForkEntry {
5080#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , Eq , Default ) ]
5181#[ serde( rename_all = "camelCase" ) ]
5282pub struct EthConfigResponse {
53- pub current : ForkEntry ,
83+ pub current : ForkConfig ,
5484 #[ serde( skip_serializing_if = "Option::is_none" ) ]
55- pub next : Option < ForkEntry > ,
85+ pub next : Option < ForkConfig > ,
5686 #[ serde( skip_serializing_if = "Option::is_none" ) ]
57- pub last : Option < ForkEntry > ,
58- pub fork_id : crate :: fork_id :: ForkId ,
87+ pub last : Option < ForkConfig > ,
88+ pub fork_id : ForkId ,
5989}
0 commit comments