Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions nodes/standalone/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}
Expand Down
157 changes: 93 additions & 64 deletions nodes/standalone/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -36,17 +37,6 @@ use sp_runtime::traits::IdentifyAccount;
/// ChainSpec type.
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;

/// 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<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(seed, None)
Expand All @@ -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<ChainSpec, String> {
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::<ed25519::Public>("//Alice"),
vec![
// Dev Faucet account
get_account_id_from_secret::<ed25519::Public>("receive clutch item involve chaos clutch furnace arrest claw isolate okay together"),
get_account_id_from_secret::<ed25519::Public>("//Alice"),
get_account_id_from_secret::<ed25519::Public>("//Bob"),
get_account_id_from_secret::<sr25519::Public>("//Alice"),
get_account_id_from_secret::<sr25519::Public>("//Bob"),
],
)
},
vec![],
None,
None,
None,
Some(properties),
None,
)
}
Alternative::KiltTestnet => ChainSpec::from_json_bytes(&include_bytes!("../res/testnet.json")[..])?,
})
}
fn devnet_chain_spec() -> Result<ChainSpec, String> {
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::<ed25519::Public>("//Alice"),
vec![
// Dev Faucet account
get_account_id_from_secret::<ed25519::Public>(
"receive clutch item involve chaos clutch furnace arrest claw isolate okay together",
),
get_account_id_from_secret::<ed25519::Public>("//Alice"),
get_account_id_from_secret::<ed25519::Public>("//Bob"),
get_account_id_from_secret::<sr25519::Public>("//Alice"),
get_account_id_from_secret::<sr25519::Public>("//Bob"),
],
)
},
vec![],
None,
None,
None,
Some(properties),
None,
))
}

pub(crate) fn from(s: &str) -> Option<Self> {
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<ChainSpec, String> {
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, String> {
ChainSpec::from_json_bytes(&include_bytes!("../res/testnet.json")[..])
}

fn devnet_genesis(
Expand Down Expand Up @@ -159,8 +186,10 @@ fn devnet_genesis(
}

pub fn load_spec(id: &str) -> Result<Box<dyn sc_service::ChainSpec>, 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)),
}))
}