diff --git a/Cargo.lock b/Cargo.lock index 53d67848ea..f73dd94394 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4610,6 +4610,7 @@ dependencies = [ "frame-benchmarking", "frame-benchmarking-cli", "frame-system", + "hex-literal", "jsonrpsee", "mashnet-node-runtime", "pallet-transaction-payment", diff --git a/nodes/standalone/Cargo.toml b/nodes/standalone/Cargo.toml index b0dafb4ce8..5328bd1891 100644 --- a/nodes/standalone/Cargo.toml +++ b/nodes/standalone/Cargo.toml @@ -24,6 +24,7 @@ substrate-build-script-utils.workspace = true # External dependencies clap = {workspace = true, features = ["derive"]} jsonrpsee = {workspace = true, features = ["server"]} +hex-literal.workspace = true # Internal dependencies mashnet-node-runtime = {workspace = true, features = ["std"]} diff --git a/nodes/standalone/src/chain_spec.rs b/nodes/standalone/src/chain_spec.rs index 6e2f6b3b97..defe96c9ea 100644 --- a/nodes/standalone/src/chain_spec.rs +++ b/nodes/standalone/src/chain_spec.rs @@ -23,9 +23,10 @@ use mashnet_node_runtime::{ }; use runtime_common::{AccountId, AccountPublic}; +use hex_literal::hex; use sc_service::{self, ChainType, Properties}; use sp_consensus_aura::ed25519::AuthorityId as AuraId; -use sp_core::{ed25519, sr25519, Pair, Public}; +use sp_core::{crypto::UncheckedInto, ed25519, sr25519, Pair, Public}; use sp_finality_grandpa::AuthorityId as GrandpaId; use sp_runtime::traits::IdentifyAccount; @@ -36,17 +37,6 @@ use sp_runtime::traits::IdentifyAccount; /// ChainSpec type. pub type ChainSpec = sc_service::GenericChainSpec; -/// The chain specification option. This is expected to come in from the CLI and -/// is little more than one of a number of alternatives which can easily be -/// converted from a string (`--chain=...`) into a `ChainSpec`. -#[derive(Clone, Debug)] -pub enum Alternative { - /// Whatever the current runtime is, with just Alice as an auth. - Development, - /// Whatever the current runtime is, with simple Alice/Bob auths. - KiltTestnet, -} - /// Helper function to generate a crypto pair from seed fn get_from_secret(seed: &str) -> ::Public { TPublic::Pair::from_string(seed, None) @@ -71,55 +61,92 @@ fn get_authority_keys_from_secret(seed: &str) -> (AccountId, AuraId, GrandpaId) ) } -impl Alternative { - /// Get an actual chain config from one of the alternatives. - pub(crate) fn load(self) -> Result { - let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm binary not available".to_string())?; - - let mut properties = Properties::new(); - properties.insert("tokenDecimals".into(), 15_i16.into()); - - Ok(match self { - Alternative::Development => { - properties.insert("tokenSymbol".into(), "KILT".into()); - ChainSpec::from_genesis( - "Development", - "development", - ChainType::Development, - move || { - devnet_genesis( - wasm_binary, - vec![get_authority_keys_from_secret("//Alice")], - get_account_id_from_secret::("//Alice"), - vec![ - // Dev Faucet account - get_account_id_from_secret::("receive clutch item involve chaos clutch furnace arrest claw isolate okay together"), - get_account_id_from_secret::("//Alice"), - get_account_id_from_secret::("//Bob"), - get_account_id_from_secret::("//Alice"), - get_account_id_from_secret::("//Bob"), - ], - ) - }, - vec![], - None, - None, - None, - Some(properties), - None, - ) - } - Alternative::KiltTestnet => ChainSpec::from_json_bytes(&include_bytes!("../res/testnet.json")[..])?, - }) - } +fn devnet_chain_spec() -> Result { + let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm binary not available".to_string())?; + + let mut properties = Properties::new(); + properties.insert("tokenDecimals".into(), 15_i16.into()); + + properties.insert("tokenSymbol".into(), "DILT".into()); + Ok(ChainSpec::from_genesis( + "Development", + "development", + ChainType::Development, + move || { + devnet_genesis( + wasm_binary, + vec![get_authority_keys_from_secret("//Alice")], + get_account_id_from_secret::("//Alice"), + vec![ + // Dev Faucet account + get_account_id_from_secret::( + "receive clutch item involve chaos clutch furnace arrest claw isolate okay together", + ), + get_account_id_from_secret::("//Alice"), + get_account_id_from_secret::("//Bob"), + get_account_id_from_secret::("//Alice"), + get_account_id_from_secret::("//Bob"), + ], + ) + }, + vec![], + None, + None, + None, + Some(properties), + None, + )) +} - pub(crate) fn from(s: &str) -> Option { - match s { - "dev" => Some(Alternative::Development), - "kilt-testnet" => Some(Alternative::KiltTestnet), - _ => None, - } - } +const YORLIN_ALICE_ACC: [u8; 32] = hex!["e82655d021c27086c4c8a47c29a9094c50c3d09d5ddbb71c01781b4cf6c2dc3f"]; +const YORLIN_ALICE_SESSION_SR: [u8; 32] = hex!["ecb26520504cecf51936e8d9df07d1355726bf186f9cd38d35277f918fe3230c"]; +const YORLIN_ALICE_SESSION_ED: [u8; 32] = hex!["d600f710ab168414cb29faef92bd570f01c375cb359ec27485b176246ac597a5"]; +const YORLIN_BOB_ACC: [u8; 32] = hex!["38621f2de0250bd855fef9ab09fd8b06e6ed67c574ea4ae2b46557a809fab56d"]; +const YORLIN_BOB_SESSION_SR: [u8; 32] = hex!["1284c324ac272432b83779886ad66ff74dc6147f4a4a67124218e0b88c27ea7d"]; +const YORLIN_BOB_SESSION_ED: [u8; 32] = hex!["5d1040178af44ca8bc598d48c6b0c49e8b5b916315d3d91f953df7623c9c78ae"]; +const YORLIN_FAUCET_ACC: [u8; 32] = hex!["a874b37f88e76eefbeb62d4424876004c81f7ae30e2d7c2bb380001a1961fc38"]; + +fn yorlin_chain_spec() -> Result { + let wasm_binary = WASM_BINARY.ok_or_else(|| "Yorlin wasm binary not available".to_string())?; + + let mut properties = Properties::new(); + properties.insert("tokenDecimals".into(), 15_i16.into()); + + properties.insert("tokenSymbol".into(), "YILT".into()); + Ok(ChainSpec::from_genesis( + "Yorlin", + "Yorlin", + ChainType::Development, + move || { + devnet_genesis( + wasm_binary, + vec![ + ( + YORLIN_ALICE_ACC.into(), + YORLIN_ALICE_SESSION_SR.unchecked_into(), + YORLIN_ALICE_SESSION_ED.unchecked_into(), + ), + ( + YORLIN_BOB_ACC.into(), + YORLIN_BOB_SESSION_SR.unchecked_into(), + YORLIN_BOB_SESSION_ED.unchecked_into(), + ), + ], + YORLIN_ALICE_ACC.into(), + vec![YORLIN_ALICE_ACC.into(), YORLIN_BOB_ACC.into(), YORLIN_FAUCET_ACC.into()], + ) + }, + vec![], + None, + Some("yOrLiN"), + None, + Some(properties), + None, + )) +} + +fn testnet_chain_spec() -> Result { + ChainSpec::from_json_bytes(&include_bytes!("../res/testnet.json")[..]) } fn devnet_genesis( @@ -159,8 +186,10 @@ fn devnet_genesis( } pub fn load_spec(id: &str) -> Result, String> { - Ok(match Alternative::from(id) { - Some(spec) => Box::new(spec.load()?), - None => Box::new(ChainSpec::from_json_file(std::path::PathBuf::from(id))?), - }) + Ok(Box::new(match id { + "kilt-testnet" => testnet_chain_spec()?, + "dev" => devnet_chain_spec()?, + "yorlin" => yorlin_chain_spec()?, + _ => return Err(format!("Unknown spec: {}", id)), + })) }