@@ -3,17 +3,13 @@ use crate::{
3
3
forkid:: ForkFilterKey ,
4
4
header:: Head ,
5
5
proofs:: genesis_state_root,
6
- BlockNumber , Chain , ForkFilter , ForkHash , ForkId , Genesis , GenesisAccount , Hardfork , Header ,
7
- SealedHeader , H160 , H256 , U256 ,
6
+ BlockNumber , Chain , ForkFilter , ForkHash , ForkId , Genesis , Hardfork , Header , SealedHeader ,
7
+ H256 , U256 ,
8
8
} ;
9
- use ethers_core:: utils:: Genesis as EthersGenesis ;
10
9
use hex_literal:: hex;
11
10
use once_cell:: sync:: Lazy ;
12
11
use serde:: { Deserialize , Serialize } ;
13
- use std:: {
14
- collections:: { BTreeMap , HashMap } ,
15
- sync:: Arc ,
16
- } ;
12
+ use std:: { collections:: BTreeMap , sync:: Arc } ;
17
13
18
14
/// The Ethereum mainnet spec
19
15
pub static MAINNET : Lazy < Arc < ChainSpec > > = Lazy :: new ( || {
@@ -316,25 +312,8 @@ impl ChainSpec {
316
312
}
317
313
}
318
314
319
- impl From < EthersGenesis > for ChainSpec {
320
- fn from ( genesis : EthersGenesis ) -> Self {
321
- let alloc = genesis
322
- . alloc
323
- . iter ( )
324
- . map ( |( addr, account) | ( addr. 0 . into ( ) , account. clone ( ) . into ( ) ) )
325
- . collect :: < HashMap < H160 , GenesisAccount > > ( ) ;
326
-
327
- let genesis_block = Genesis {
328
- nonce : genesis. nonce . as_u64 ( ) ,
329
- timestamp : genesis. timestamp . as_u64 ( ) ,
330
- gas_limit : genesis. gas_limit . as_u64 ( ) ,
331
- difficulty : genesis. difficulty . into ( ) ,
332
- mix_hash : genesis. mix_hash . 0 . into ( ) ,
333
- coinbase : genesis. coinbase . 0 . into ( ) ,
334
- extra_data : genesis. extra_data . 0 . into ( ) ,
335
- alloc,
336
- } ;
337
-
315
+ impl From < Genesis > for ChainSpec {
316
+ fn from ( genesis : Genesis ) -> Self {
338
317
// Block-based hardforks
339
318
let hardfork_opts = vec ! [
340
319
( Hardfork :: Homestead , genesis. config. homestead_block) ,
@@ -361,7 +340,7 @@ impl From<EthersGenesis> for ChainSpec {
361
340
hardforks. insert (
362
341
Hardfork :: Paris ,
363
342
ForkCondition :: TTD {
364
- total_difficulty : ttd. into ( ) ,
343
+ total_difficulty : ttd,
365
344
fork_block : genesis. config . merge_netsplit_block ,
366
345
} ,
367
346
) ;
@@ -379,7 +358,7 @@ impl From<EthersGenesis> for ChainSpec {
379
358
380
359
Self {
381
360
chain : genesis. config . chain_id . into ( ) ,
382
- genesis : genesis_block ,
361
+ genesis,
383
362
genesis_hash : None ,
384
363
fork_timestamps : ForkTimestamps :: from_hardforks ( & hardforks) ,
385
364
hardforks,
@@ -417,21 +396,26 @@ impl ForkTimestamps {
417
396
#[ serde( untagged) ]
418
397
pub enum AllGenesisFormats {
419
398
/// The geth genesis format
420
- Geth ( EthersGenesis ) ,
399
+ Geth ( Genesis ) ,
421
400
/// The reth genesis format
422
401
Reth ( ChainSpec ) ,
423
402
}
424
403
425
- impl From < EthersGenesis > for AllGenesisFormats {
426
- fn from ( genesis : EthersGenesis ) -> Self {
404
+ impl From < Genesis > for AllGenesisFormats {
405
+ fn from ( genesis : Genesis ) -> Self {
427
406
Self :: Geth ( genesis)
428
407
}
429
408
}
430
409
410
+ impl From < ChainSpec > for AllGenesisFormats {
411
+ fn from ( genesis : ChainSpec ) -> Self {
412
+ Self :: Reth ( genesis)
413
+ }
414
+ }
415
+
431
416
impl From < Arc < ChainSpec > > for AllGenesisFormats {
432
- fn from ( mut genesis : Arc < ChainSpec > ) -> Self {
433
- let cloned_genesis = Arc :: make_mut ( & mut genesis) . clone ( ) ;
434
- Self :: Reth ( cloned_genesis)
417
+ fn from ( genesis : Arc < ChainSpec > ) -> Self {
418
+ Arc :: try_unwrap ( genesis) . unwrap_or_else ( |arc| ( * arc) . clone ( ) ) . into ( )
435
419
}
436
420
}
437
421
@@ -1195,7 +1179,7 @@ mod tests {
1195
1179
}
1196
1180
"# ;
1197
1181
1198
- let genesis: ethers_core :: utils :: Genesis = serde_json:: from_str ( geth_genesis) . unwrap ( ) ;
1182
+ let genesis: Genesis = serde_json:: from_str ( geth_genesis) . unwrap ( ) ;
1199
1183
let chainspec = ChainSpec :: from ( genesis) ;
1200
1184
1201
1185
// assert a bunch of hardforks that should be set
@@ -1334,6 +1318,8 @@ mod tests {
1334
1318
}
1335
1319
}
1336
1320
"# ;
1321
+
1322
+ let _genesis = serde_json:: from_str :: < Genesis > ( hive_json) . unwrap ( ) ;
1337
1323
let genesis = serde_json:: from_str :: < AllGenesisFormats > ( hive_json) . unwrap ( ) ;
1338
1324
let chainspec: ChainSpec = genesis. into ( ) ;
1339
1325
assert_eq ! ( chainspec. genesis_hash, None ) ;
0 commit comments