git.delta.rocks / unique-network / refs/commits / cf53619f112d

difftreelog

Use default runtime in the local testnet

Daniel Shiposha2022-03-30parent: #6d40a57.patch.diff
in: master

4 files changed

modifiednode/cli/src/chain_spec.rsdiffbeforeafterboth
--- a/node/cli/src/chain_spec.rs
+++ b/node/cli/src/chain_spec.rs
@@ -14,7 +14,6 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
-use cumulus_primitives_core::ParaId;
 use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
 use sc_service::ChainType;
 use sp_core::{sr25519, Pair, Public};
@@ -26,6 +25,15 @@
 
 use unique_runtime_common::types::*;
 
+#[cfg(feature = "unique-runtime")]
+use unique_runtime as default_runtime;
+
+#[cfg(all(not(feature = "unique-runtime"), feature = "quartz-runtime"))]
+use quartz_runtime as default_runtime;
+
+#[cfg(all(not(feature = "unique-runtime"), not(feature = "quartz-runtime")))]
+use opal_runtime as default_runtime;
+
 /// The `ChainSpec` parameterized for the unique runtime.
 #[cfg(feature = "unique-runtime")]
 pub type UniqueChainSpec = sc_service::GenericChainSpec<unique_runtime::GenesisConfig, Extensions>;
@@ -37,6 +45,15 @@
 /// The `ChainSpec` parameterized for the opal runtime.
 pub type OpalChainSpec = sc_service::GenericChainSpec<opal_runtime::GenesisConfig, Extensions>;
 
+#[cfg(feature = "unique-runtime")]
+pub type DefaultChainSpec = UniqueChainSpec;
+
+#[cfg(all(not(feature = "unique-runtime"), feature = "quartz-runtime"))]
+pub type DefaultChainSpec = QuartzChainSpec;
+
+#[cfg(all(not(feature = "unique-runtime"), not(feature = "quartz-runtime")))]
+pub type DefaultChainSpec = OpalChainSpec;
+
 pub enum RuntimeId {
 	#[cfg(feature = "unique-runtime")]
 	Unique,
@@ -125,11 +142,54 @@
 	AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
 }
 
+macro_rules! testnet_genesis {
+	(
+		$runtime:path,
+		$root_key:expr,
+		$initial_authorities:expr,
+		$endowed_accounts:expr,
+		$id:expr
+	) => {{
+		use $runtime::*;
+
+		GenesisConfig {
+			system: SystemConfig {
+				code: WASM_BINARY
+					.expect("WASM binary was not build, please build it!")
+					.to_vec(),
+			},
+			balances: BalancesConfig {
+				balances: $endowed_accounts
+					.iter()
+					.cloned()
+					// 1e13 UNQ
+					.map(|k| (k, 1 << 100))
+					.collect(),
+			},
+			treasury: Default::default(),
+			sudo: SudoConfig {
+				key: Some($root_key),
+			},
+			vesting: VestingConfig { vesting: vec![] },
+			parachain_info: ParachainInfoConfig { parachain_id: $id.into() },
+			parachain_system: Default::default(),
+			aura: AuraConfig {
+				authorities: $initial_authorities,
+			},
+			aura_ext: Default::default(),
+			evm: EVMConfig {
+				accounts: BTreeMap::new(),
+			},
+			ethereum: EthereumConfig {},
+		}
+	}};
+}
+
 pub fn development_config() -> OpalChainSpec {
 	let mut properties = Map::new();
-	properties.insert("tokenSymbol".into(), "OPL".into());
+	properties.insert("tokenSymbol".into(), opal_runtime::TOKEN_SYMBOL.into());
 	properties.insert("tokenDecimals".into(), 18.into());
-	properties.insert("ss58Format".into(), 42.into());
+	properties.insert("ss58Format".into(), opal_runtime::SS58Prefix::get().into());
 
 	OpalChainSpec::from_genesis(
 		// Name
@@ -138,7 +198,9 @@
 		"opal_dev",
 		ChainType::Local,
 		move || {
-			testnet_genesis(
+			testnet_genesis!(
+				opal_runtime,
+
 				// Sudo account
 				get_account_id_from_seed::<sr25519::Public>("Alice"),
 				vec![
@@ -150,7 +212,7 @@
 					get_account_id_from_seed::<sr25519::Public>("Alice"),
 					get_account_id_from_seed::<sr25519::Public>("Bob"),
 				],
-				1000.into(),
+				1000
 			)
 		},
 		// Bootnodes
@@ -170,20 +232,26 @@
 	)
 }
 
-pub fn local_testnet_rococo_config() -> OpalChainSpec {
+pub fn local_testnet_rococo_config() -> DefaultChainSpec {
 	let mut properties = Map::new();
-	properties.insert("tokenSymbol".into(), "OPL".into());
+	properties.insert("tokenSymbol".into(), default_runtime::TOKEN_SYMBOL.into());
 	properties.insert("tokenDecimals".into(), 18.into());
-	properties.insert("ss58Format".into(), 42.into());
+	properties.insert("ss58Format".into(), default_runtime::SS58Prefix::get().into());
 
-	OpalChainSpec::from_genesis(
+	DefaultChainSpec::from_genesis(
 		// Name
-		"OPAL by UNIQUE",
+		format!(
+			"{}{}",
+			default_runtime::RUNTIME_NAME.to_uppercase(),
+			if cfg!(feature = "unique-runtime") { "" } else { " by UNIQUE" }
+		).as_str(),
 		// ID
-		"opal_local",
+		format!("{}_local", default_runtime::RUNTIME_NAME).as_str(),
 		ChainType::Local,
 		move || {
-			testnet_genesis(
+			testnet_genesis!(
+				default_runtime,
+
 				// Sudo account
 				get_account_id_from_seed::<sr25519::Public>("Alice"),
 				vec![
@@ -205,7 +273,7 @@
 					get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
 					get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
 				],
-				1000.into(),
+				1000
 			)
 		},
 		// Bootnodes
@@ -223,44 +291,4 @@
 			para_id: 1000,
 		},
 	)
-}
-
-fn testnet_genesis(
-	root_key: AccountId,
-	initial_authorities: Vec<AuraId>,
-	endowed_accounts: Vec<AccountId>,
-	id: ParaId,
-) -> opal_runtime::GenesisConfig {
-	use opal_runtime::*;
-
-	GenesisConfig {
-		system: SystemConfig {
-			code: WASM_BINARY
-				.expect("WASM binary was not build, please build it!")
-				.to_vec(),
-		},
-		balances: BalancesConfig {
-			balances: endowed_accounts
-				.iter()
-				.cloned()
-				// 1e13 UNQ
-				.map(|k| (k, 1 << 100))
-				.collect(),
-		},
-		treasury: Default::default(),
-		sudo: SudoConfig {
-			key: Some(root_key),
-		},
-		vesting: VestingConfig { vesting: vec![] },
-		parachain_info: ParachainInfoConfig { parachain_id: id },
-		parachain_system: Default::default(),
-		aura: AuraConfig {
-			authorities: initial_authorities,
-		},
-		aura_ext: Default::default(),
-		evm: EVMConfig {
-			accounts: BTreeMap::new(),
-		},
-		ethereum: EthereumConfig {},
-	}
 }
modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
115use unique_runtime_common::{impl_common_runtime_apis, types::*, constants::*};115use unique_runtime_common::{impl_common_runtime_apis, types::*, constants::*};
116116
117pub const RUNTIME_NAME: &str = "opal";117pub const RUNTIME_NAME: &str = "opal";
118pub const TOKEN_SYMBOL: &str = "OPL";
118119
119type CrossAccountId = pallet_common::account::BasicCrossAccountId<Runtime>;120type CrossAccountId = pallet_common::account::BasicCrossAccountId<Runtime>;
120121
modifiedruntime/quartz/src/lib.rsdiffbeforeafterboth
--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -115,6 +115,7 @@
 use unique_runtime_common::{impl_common_runtime_apis, types::*, constants::*};
 
 pub const RUNTIME_NAME: &str = "quartz";
+pub const TOKEN_SYMBOL: &str = "QTZ";
 
 type CrossAccountId = pallet_common::account::BasicCrossAccountId<Runtime>;
 
modifiedruntime/unique/src/lib.rsdiffbeforeafterboth
--- a/runtime/unique/src/lib.rs
+++ b/runtime/unique/src/lib.rs
@@ -114,6 +114,7 @@
 use unique_runtime_common::{impl_common_runtime_apis, types::*, constants::*};
 
 pub const RUNTIME_NAME: &str = "unique";
+pub const TOKEN_SYMBOL: &str = "UNQ";
 
 type CrossAccountId = pallet_common::account::BasicCrossAccountId<Runtime>;