@@ -5,48 +5,28 @@ use std::{
5
5
6
6
use ethrex_common:: types:: { Genesis , GenesisError } ;
7
7
use ethrex_p2p:: types:: Node ;
8
- use lazy_static:: lazy_static;
9
8
10
9
pub const HOLESKY_GENESIS_PATH : & str = "cmd/ethrex/networks/holesky/genesis.json" ;
11
10
pub const HOLESKY_GENESIS_CONTENTS : & str = include_str ! ( "networks/holesky/genesis.json" ) ;
12
- const HOLESKY_BOOTNODES_PATH : & str = "cmd/ethrex/ networks/holesky/bootnodes.json";
11
+ const HOLESKY_BOOTNODES : & str = include_str ! ( " networks/holesky/bootnodes.json") ;
13
12
14
13
pub const SEPOLIA_GENESIS_PATH : & str = "cmd/ethrex/networks/sepolia/genesis.json" ;
15
14
pub const SEPOLIA_GENESIS_CONTENTS : & str = include_str ! ( "networks/sepolia/genesis.json" ) ;
16
- const SEPOLIA_BOOTNODES_PATH : & str = "cmd/ethrex/ networks/sepolia/bootnodes.json";
15
+ const SEPOLIA_BOOTNODES : & str = include_str ! ( " networks/sepolia/bootnodes.json") ;
17
16
18
17
pub const HOODI_GENESIS_PATH : & str = "cmd/ethrex/networks/hoodi/genesis.json" ;
19
18
pub const HOODI_GENESIS_CONTENTS : & str = include_str ! ( "networks/hoodi/genesis.json" ) ;
20
- const HOODI_BOOTNODES_PATH : & str = "cmd/ethrex/ networks/hoodi/bootnodes.json";
19
+ const HOODI_BOOTNODES : & str = include_str ! ( " networks/hoodi/bootnodes.json") ;
21
20
22
21
pub const MAINNET_GENESIS_PATH : & str = "cmd/ethrex/networks/mainnet/genesis.json" ;
23
22
pub const MAINNET_GENESIS_CONTENTS : & str = include_str ! ( "networks/mainnet/genesis.json" ) ;
24
- const MAINNET_BOOTNODES_PATH : & str = "cmd/ethrex/ networks/mainnet/bootnodes.json";
23
+ const MAINNET_BOOTNODES : & str = include_str ! ( " networks/mainnet/bootnodes.json") ;
25
24
26
25
pub const LOCAL_DEVNET_GENESIS_PATH : & str = "../../fixtures/genesis/l1-dev.json" ;
27
26
pub const LOCAL_DEVNETL2_GENESIS_PATH : & str = "../../fixtures/genesis/l2.json" ;
28
27
pub const LOCAL_DEVNET_GENESIS_CONTENTS : & str = include_str ! ( "../../fixtures/genesis/l1-dev.json" ) ;
29
28
pub const LOCAL_DEVNETL2_GENESIS_CONTENTS : & str = include_str ! ( "../../fixtures/genesis/l2.json" ) ;
30
29
31
- lazy_static ! {
32
- pub static ref HOLESKY_BOOTNODES : Vec <Node > = serde_json:: from_reader(
33
- std:: fs:: File :: open( HOLESKY_BOOTNODES_PATH ) . expect( "Failed to open holesky bootnodes file" )
34
- )
35
- . expect( "Failed to parse holesky bootnodes file" ) ;
36
- pub static ref SEPOLIA_BOOTNODES : Vec <Node > = serde_json:: from_reader(
37
- std:: fs:: File :: open( SEPOLIA_BOOTNODES_PATH ) . expect( "Failed to open sepolia bootnodes file" )
38
- )
39
- . expect( "Failed to parse sepolia bootnodes file" ) ;
40
- pub static ref HOODI_BOOTNODES : Vec <Node > = serde_json:: from_reader(
41
- std:: fs:: File :: open( HOODI_BOOTNODES_PATH ) . expect( "Failed to open hoodi bootnodes file" )
42
- )
43
- . expect( "Failed to parse hoodi bootnodes file" ) ;
44
- pub static ref MAINNET_BOOTNODES : Vec <Node > = serde_json:: from_reader(
45
- std:: fs:: File :: open( MAINNET_BOOTNODES_PATH ) . expect( "Failed to open mainnet bootnodes file" )
46
- )
47
- . expect( "Failed to parse mainnet bootnodes file" ) ;
48
- }
49
-
50
30
#[ derive( Debug , Clone ) ]
51
31
pub enum Network {
52
32
PublicNetwork ( PublicNetwork ) ,
@@ -129,6 +109,17 @@ impl Network {
129
109
Network :: GenesisPath ( s) => Genesis :: try_from ( s. as_path ( ) ) ,
130
110
}
131
111
}
112
+
113
+ pub fn get_bootnodes ( & self ) -> Vec < Node > {
114
+ let bootnodes = match self {
115
+ Network :: PublicNetwork ( PublicNetwork :: Holesky ) => HOLESKY_BOOTNODES ,
116
+ Network :: PublicNetwork ( PublicNetwork :: Hoodi ) => HOODI_BOOTNODES ,
117
+ Network :: PublicNetwork ( PublicNetwork :: Mainnet ) => MAINNET_BOOTNODES ,
118
+ Network :: PublicNetwork ( PublicNetwork :: Sepolia ) => SEPOLIA_BOOTNODES ,
119
+ _ => return vec ! [ ] ,
120
+ } ;
121
+ serde_json:: from_str ( bootnodes) . expect ( "bootnodes file should be valid JSON" )
122
+ }
132
123
}
133
124
134
125
fn get_genesis_contents ( network : PublicNetwork ) -> & ' static str {
@@ -192,4 +183,12 @@ mod tests {
192
183
"d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3" ,
193
184
) ;
194
185
}
186
+
187
+ #[ test]
188
+ fn test_get_bootnodes_works_for_public_networks ( ) {
189
+ Network :: PublicNetwork ( PublicNetwork :: Holesky ) . get_bootnodes ( ) ;
190
+ Network :: PublicNetwork ( PublicNetwork :: Hoodi ) . get_bootnodes ( ) ;
191
+ Network :: PublicNetwork ( PublicNetwork :: Mainnet ) . get_bootnodes ( ) ;
192
+ Network :: PublicNetwork ( PublicNetwork :: Sepolia ) . get_bootnodes ( ) ;
193
+ }
195
194
}
0 commit comments