11use std:: collections:: BTreeMap ;
22
33use cumulus_primitives_core:: ParaId ;
4- use evm_runtime_template:: {
5- AccountId , AuraId , OpenZeppelinPrecompiles as Precompiles , Runtime , Signature ,
6- } ;
4+ use evm_runtime_template:: { AccountId , OpenZeppelinPrecompiles as Precompiles , Runtime } ;
5+ # [ cfg ( not ( feature = "tanssi" ) ) ]
6+ use evm_runtime_template :: { AuraId , Signature } ;
77use fp_evm:: GenesisAccount ;
88use hex_literal:: hex;
99use log:: error;
1010use sc_chain_spec:: { ChainSpecExtension , ChainSpecGroup } ;
1111use sc_service:: ChainType ;
1212use serde:: { Deserialize , Serialize } ;
13- use sp_core:: { ecdsa, Pair , Public , H160 } ;
13+ use sp_core:: H160 ;
14+ #[ cfg( not( feature = "tanssi" ) ) ]
15+ use sp_core:: { ecdsa, Pair , Public } ;
16+ #[ cfg( not( feature = "tanssi" ) ) ]
1417use sp_runtime:: traits:: { IdentifyAccount , Verify } ;
1518
1619use crate :: contracts:: { parse_contracts, ContractsPath } ;
@@ -22,6 +25,7 @@ pub type ChainSpec = sc_service::GenericChainSpec<Extensions>;
2225const SAFE_XCM_VERSION : u32 = xcm:: prelude:: XCM_VERSION ;
2326
2427/// Helper function to generate a crypto pair from seed
28+ #[ cfg( not( feature = "tanssi" ) ) ]
2529pub fn get_from_seed < TPublic : Public > ( seed : & str ) -> <TPublic :: Pair as Pair >:: Public {
2630 TPublic :: Pair :: from_string ( & format ! ( "//{}" , seed) , None )
2731 . expect ( "static values are valid; qed" )
@@ -45,17 +49,20 @@ impl Extensions {
4549 }
4650}
4751
52+ #[ cfg( not( feature = "tanssi" ) ) ]
4853type AccountPublic = <Signature as Verify >:: Signer ;
4954
5055/// Generate collator keys from seed.
5156///
5257/// This function's return type must always match the session keys of the chain
5358/// in tuple format.
59+ #[ cfg( not( feature = "tanssi" ) ) ]
5460pub fn get_collator_keys_from_seed ( seed : & str ) -> AuraId {
5561 get_from_seed :: < AuraId > ( seed)
5662}
5763
5864/// Helper function to generate an account ID from seed
65+ #[ cfg( not( feature = "tanssi" ) ) ]
5966pub fn get_account_id_from_seed < TPublic : Public > ( seed : & str ) -> AccountId
6067where
6168 AccountPublic : From < <TPublic :: Pair as Pair >:: Public > ,
6774///
6875/// The input must be a tuple of individual keys (a single arg for now since we
6976/// have just one key).
77+ #[ cfg( not( feature = "tanssi" ) ) ]
7078pub fn template_session_keys ( keys : AuraId ) -> evm_runtime_template:: SessionKeys {
7179 evm_runtime_template:: SessionKeys { aura : keys }
7280}
@@ -94,6 +102,7 @@ pub fn development_config(contracts_path: ContractsPath) -> ChainSpec {
94102 . with_chain_type ( ChainType :: Development )
95103 . with_genesis_config_patch ( testnet_genesis (
96104 // initial collators.
105+ #[ cfg( not( feature = "tanssi" ) ) ]
97106 vec ! [
98107 (
99108 get_account_id_from_seed:: <ecdsa:: Public >( "Alice" ) ,
@@ -140,6 +149,7 @@ pub fn local_testnet_config(contracts_path: ContractsPath) -> ChainSpec {
140149 . with_chain_type ( ChainType :: Local )
141150 . with_genesis_config_patch ( testnet_genesis (
142151 // initial collators.
152+ #[ cfg( not( feature = "tanssi" ) ) ]
143153 vec ! [
144154 (
145155 get_account_id_from_seed:: <ecdsa:: Public >( "Alice" ) ,
@@ -165,6 +175,7 @@ pub fn local_testnet_config(contracts_path: ContractsPath) -> ChainSpec {
165175 . build ( )
166176}
167177
178+ #[ cfg( not( feature = "tanssi" ) ) ]
168179fn testnet_genesis (
169180 invulnerables : Vec < ( AccountId , AuraId ) > ,
170181 #[ cfg( not( feature = "runtime-benchmarks" ) ) ] endowed_accounts : Vec < AccountId > ,
@@ -245,3 +256,67 @@ fn testnet_genesis(
245256 "sudo" : { "key" : Some ( root) }
246257 } )
247258}
259+
260+ #[ cfg( feature = "tanssi" ) ]
261+ fn testnet_genesis (
262+ #[ cfg( not( feature = "runtime-benchmarks" ) ) ] endowed_accounts : Vec < AccountId > ,
263+ #[ cfg( feature = "runtime-benchmarks" ) ] mut endowed_accounts : Vec < AccountId > ,
264+ root : AccountId ,
265+ id : ParaId ,
266+ contracts_path : ContractsPath ,
267+ ) -> serde_json:: Value {
268+ let contracts = parse_contracts ( contracts_path)
269+ . map_err ( |e| error ! ( "Error while parsing contracts: {e:?}" ) )
270+ . unwrap_or_default ( ) ;
271+ let precompiles = Precompiles :: < Runtime > :: used_addresses ( )
272+ . map ( |addr| {
273+ (
274+ addr,
275+ GenesisAccount {
276+ nonce : Default :: default ( ) ,
277+ balance : Default :: default ( ) ,
278+ storage : Default :: default ( ) ,
279+ // bytecode to revert without returning data
280+ // (PUSH1 0x00 PUSH1 0x00 REVERT)
281+ code : vec ! [ 0x60 , 0x00 , 0x60 , 0x00 , 0xFD ] ,
282+ } ,
283+ )
284+ } )
285+ . into_iter ( ) ;
286+ let accounts: BTreeMap < H160 , GenesisAccount > = contracts
287+ . into_iter ( )
288+ . map ( |( address, contract) | {
289+ (
290+ address,
291+ GenesisAccount {
292+ code : contract. bytecode ( ) ,
293+ nonce : Default :: default ( ) ,
294+ balance : Default :: default ( ) ,
295+ storage : Default :: default ( ) ,
296+ } ,
297+ )
298+ } )
299+ . chain ( precompiles)
300+ . collect ( ) ;
301+ #[ cfg( feature = "runtime-benchmarks" ) ]
302+ endowed_accounts. push ( AccountId :: from ( hex ! ( "1000000000000000000000000000000000000001" ) ) ) ;
303+ serde_json:: json!( {
304+ "balances" : {
305+ "balances" : endowed_accounts. iter( ) . cloned( ) . map( |k| ( k, 1u64 << 60 ) ) . collect:: <Vec <_>>( ) ,
306+ } ,
307+ "parachainInfo" : {
308+ "parachainId" : id,
309+ } ,
310+ "treasury" : { } ,
311+ "evmChainId" : {
312+ "chainId" : 9999
313+ } ,
314+ "evm" : {
315+ "accounts" : accounts
316+ } ,
317+ "polkadotXcm" : {
318+ "safeXcmVersion" : Some ( SAFE_XCM_VERSION ) ,
319+ } ,
320+ "sudo" : { "key" : Some ( root) }
321+ } )
322+ }
0 commit comments