1- use sp_core:: { Pair , Public , sr25519, U256 , H160 } ;
1+ use sp_core:: { Pair , Public , sr25519, U256 , H160 , crypto :: UncheckedInto , } ;
22use mathchain_runtime:: {
33 AccountId , AuraConfig , BalancesConfig , EVMConfig , EthereumConfig , GenesisConfig , GrandpaConfig ,
4- SudoConfig , SystemConfig , WASM_BINARY , Signature
4+ SudoConfig , SystemConfig , WASM_BINARY , Signature , ValidatorSetConfig , opaque :: SessionKeys , SessionConfig
55} ;
66use mathchain_runtime:: constants:: currency:: MATHS as MATH ;
77
@@ -11,6 +11,7 @@ use sp_runtime::traits::{Verify, IdentifyAccount};
1111use sc_service:: { ChainType , Properties } ;
1212use std:: collections:: BTreeMap ;
1313use std:: str:: FromStr ;
14+ use sc_telemetry:: TelemetryEndpoints ;
1415
1516const DEFAULT_PROTOCOL_ID : & str = "math" ;
1617
@@ -79,6 +80,145 @@ pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
7980 )
8081}
8182
83+ fn session_keys (
84+ aura : AuraId ,
85+ grandpa : GrandpaId ,
86+ ) -> SessionKeys {
87+ SessionKeys { aura, grandpa }
88+ }
89+
90+ pub fn get_authority_keys_from_seed ( seed : & str ) -> (
91+ AccountId ,
92+ AuraId ,
93+ GrandpaId
94+ ) {
95+ (
96+ get_account_id_from_seed :: < sr25519:: Public > ( seed) ,
97+ get_from_seed :: < AuraId > ( seed) ,
98+ get_from_seed :: < GrandpaId > ( seed)
99+ )
100+ }
101+
102+ pub fn galois_for_genesis ( ) -> Result < ChainSpec , String > {
103+ let wasm_binary = WASM_BINARY . ok_or_else ( || "Galois wasm not available" . to_string ( ) ) ?;
104+
105+ const ROOT : & ' static str = "0x24a80b84d2d5130beafcb2b1a3b1a0e0e1cee122ef0e508d6b1eb862b802fe1d" ;
106+ let root: AccountId = array_bytes:: hex_str_array_unchecked!( ROOT , 32 ) . into ( ) ;
107+
108+ const GENESIS_VALIDATOR_SR1 : & ' static str =
109+ "0xf88768150c3a86509384e744132b5323390c6c24ddccbe39468865db7c07d842" ;
110+ const GENESIS_VALIDATOR_ED1 : & ' static str =
111+ "0x490c6732f48ae1ce0e0208d53776e7b0153713fce99e5a0c36731fd4da761450" ;
112+
113+ const GENESIS_VALIDATOR_SR2 : & ' static str =
114+ "0xa2e1437ba4d59fc44ee774fab33a06d952527e909e35ef64dc91859bbb60fe65" ;
115+ const GENESIS_VALIDATOR_ED2 : & ' static str =
116+ "0xa2e1437ba4d59fc44ee774fab33a06d952527e909e35ef64dc91859bbb60fe65" ;
117+
118+ const GENESIS_VALIDATOR_SR3 : & ' static str =
119+ "0xbca164498a1bc44c91e20a64c83431592a9caa7aa509e0ba5d1fc5710b524557" ;
120+ const GENESIS_VALIDATOR_ED3 : & ' static str =
121+ "0xf350c893e43dafe5d0e1c572673666b3d414057c0d117b476fcac5f777e627f2" ;
122+
123+ let genesis_validator1: (
124+ AccountId ,
125+ AuraId ,
126+ GrandpaId ,
127+ ) = {
128+ let stash = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_SR1 , 32 ) ;
129+ let session = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_SR1 , 32 ) ;
130+ let grandpa = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_ED1 , 32 ) ;
131+
132+ (
133+ stash. into ( ) ,
134+ session. unchecked_into ( ) ,
135+ grandpa. unchecked_into ( ) ,
136+ )
137+ } ;
138+
139+ let genesis_validator2: (
140+ AccountId ,
141+ AuraId ,
142+ GrandpaId ,
143+ ) = {
144+ let stash = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_SR2 , 32 ) ;
145+ let session = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_SR2 , 32 ) ;
146+ let grandpa = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_ED2 , 32 ) ;
147+
148+ (
149+ stash. into ( ) ,
150+ session. unchecked_into ( ) ,
151+ grandpa. unchecked_into ( ) ,
152+ )
153+ } ;
154+
155+ let genesis_validator3: (
156+ AccountId ,
157+ AuraId ,
158+ GrandpaId ,
159+ ) = {
160+ let stash = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_SR3 , 32 ) ;
161+ let session = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_SR3 , 32 ) ;
162+ let grandpa = array_bytes:: hex_str_array_unchecked!( GENESIS_VALIDATOR_ED3 , 32 ) ;
163+
164+ (
165+ stash. into ( ) ,
166+ session. unchecked_into ( ) ,
167+ grandpa. unchecked_into ( ) ,
168+ )
169+ } ;
170+
171+ let endowed_accounts = [
172+ // Sudo
173+ "0x24a80b84d2d5130beafcb2b1a3b1a0e0e1cee122ef0e508d6b1eb862b802fe1d" ,
174+ // node1
175+ "0xf88768150c3a86509384e744132b5323390c6c24ddccbe39468865db7c07d842" ,
176+ // node2
177+ "0xa2e1437ba4d59fc44ee774fab33a06d952527e909e35ef64dc91859bbb60fe65" ,
178+ // node3
179+ "0xbca164498a1bc44c91e20a64c83431592a9caa7aa509e0ba5d1fc5710b524557"
180+ ]
181+ . iter ( )
182+ . map ( |s| array_bytes:: hex_str_array_unchecked!( s, 32 ) . into ( ) )
183+ . collect :: < Vec < _ > > ( ) ;
184+
185+ Ok ( ChainSpec :: from_genesis (
186+ // Name
187+ "Galois" ,
188+ "galois" ,
189+ ChainType :: Live ,
190+ move || testnet_genesis (
191+ wasm_binary,
192+ // Initial Poa authorities
193+ vec ! [
194+ genesis_validator1. clone( ) ,
195+ genesis_validator2. clone( ) ,
196+ genesis_validator3. clone( ) ,
197+ ] ,
198+ root. clone ( ) ,
199+ endowed_accounts. clone ( ) ,
200+ true
201+ ) ,
202+ vec ! [
203+ "/ip4/47.111.168.132/tcp/3031/p2p/12D3KooWNMtGp5TQGApApAoPj37QHXSCv1Yi4mkZvVnse2A5wQZK" . parse( ) . unwrap( ) ,
204+ "/ip4/8.209.214.249/tcp/3033/p2p/12D3KooWG2QSh8hKp1Bm4XuidjFijKZcHY9Q7my4fBJfJTqWj4Xd" . parse( ) . unwrap( )
205+ ] ,
206+ Some (
207+ TelemetryEndpoints :: new ( vec ! [
208+ ( "/dns4/telemetry.polkadot.io/tcp/443/x-parity-wss/%2Fsubmit%2F" . parse( ) . unwrap( ) , 0 ) ,
209+ ( "/dns4/telemetry.maiziqianbao.net/tcp/443/x-parity-wss/%2Fsubmit%2F" . parse( ) . unwrap( ) , 0 ) ,
210+ ( "/dns4/telemetry.maiziqianbao.vip/tcp/443/x-parity-wss/%2Fsubmit%2F" . parse( ) . unwrap( ) , 0 ) ,
211+ ] ) . expect ( "Galois telemetry url is valid; qed" )
212+ ) ,
213+ // Protocol ID
214+ Some ( DEFAULT_PROTOCOL_ID ) ,
215+ // Properties
216+ Some ( math_testnet_properties ( ) ) ,
217+ // Extensions
218+ None
219+ ) )
220+ }
221+
82222pub fn development_config ( ) -> Result < ChainSpec , String > {
83223 let wasm_binary = WASM_BINARY . ok_or_else ( || "Development wasm not available" . to_string ( ) ) ?;
84224
@@ -92,7 +232,7 @@ pub fn development_config() -> Result<ChainSpec, String> {
92232 wasm_binary,
93233 // Initial PoA authorities
94234 vec ! [
95- authority_keys_from_seed ( "Alice" ) ,
235+ get_authority_keys_from_seed ( "Alice" ) ,
96236 ] ,
97237 // Sudo account
98238 get_account_id_from_seed :: < sr25519:: Public > ( "Alice" ) ,
@@ -131,8 +271,8 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
131271 wasm_binary,
132272 // Initial PoA authorities
133273 vec ! [
134- authority_keys_from_seed ( "Alice" ) ,
135- authority_keys_from_seed ( "Bob" ) ,
274+ get_authority_keys_from_seed ( "Alice" ) ,
275+ get_authority_keys_from_seed ( "Bob" ) ,
136276 ] ,
137277 // Sudo account
138278 get_account_id_from_seed :: < sr25519:: Public > ( "Alice" ) ,
@@ -169,7 +309,7 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
169309/// Configure initial storage state for FRAME modules.
170310fn testnet_genesis (
171311 wasm_binary : & [ u8 ] ,
172- initial_authorities : Vec < ( AuraId , GrandpaId ) > ,
312+ initial_authorities : Vec < ( AccountId , AuraId , GrandpaId ) > ,
173313 root_key : AccountId ,
174314 endowed_accounts : Vec < AccountId > ,
175315 _enable_println : bool ,
@@ -197,10 +337,10 @@ fn testnet_genesis(
197337 balances : endowed_accounts. iter ( ) . cloned ( ) . map ( |k|( k, 10000 * MATH ) ) . collect ( ) ,
198338 } ,
199339 pallet_aura : AuraConfig {
200- authorities : initial_authorities . iter ( ) . map ( |x| ( x . 0 . clone ( ) ) ) . collect ( ) ,
340+ authorities : vec ! [ ] ,
201341 } ,
202342 pallet_grandpa : GrandpaConfig {
203- authorities : initial_authorities . iter ( ) . map ( |x| ( x . 1 . clone ( ) , 1 ) ) . collect ( ) ,
343+ authorities : vec ! [ ] ,
204344 } ,
205345 pallet_sudo : SudoConfig {
206346 // Assign network admin rights.
@@ -210,5 +350,13 @@ fn testnet_genesis(
210350 accounts : evm_accounts,
211351 } ,
212352 pallet_ethereum : EthereumConfig { } ,
353+ pallet_validator_set : ValidatorSetConfig {
354+ validators : initial_authorities. iter ( ) . map ( |x| x. 0 . clone ( ) ) . collect :: < Vec < _ > > ( ) ,
355+ } ,
356+ pallet_session : SessionConfig {
357+ keys : initial_authorities. iter ( ) . map ( |x| {
358+ ( x. 0 . clone ( ) , x. 0 . clone ( ) , session_keys ( x. 1 . clone ( ) , x. 2 . clone ( ) ) )
359+ } ) . collect :: < Vec < _ > > ( ) ,
360+ } ,
213361 }
214362}
0 commit comments