moonbeam_service/chain_spec/
moonriver.rs

1// Copyright 2019-2025 PureStake Inc.
2// This file is part of Moonbeam.
3
4// Moonbeam is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Moonbeam is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Moonbeam.  If not, see <http://www.gnu.org/licenses/>.
16
17//! Moonriver Chain Specifications and utilities for building them.
18//!
19//! Learn more about Substrate chain specifications at
20//! https://substrate.dev/docs/en/knowledgebase/integrate/chain-spec
21
22#[cfg(test)]
23use crate::chain_spec::{derive_bip44_pairs_from_mnemonic, get_account_id_from_pair};
24use crate::chain_spec::{generate_accounts, get_from_seed, Extensions};
25use crate::HostFunctions;
26use cumulus_primitives_core::ParaId;
27use hex_literal::hex;
28use moonriver_runtime::{
29	currency::MOVR, genesis_config_preset::testnet_genesis, AccountId, WASM_BINARY,
30};
31use nimbus_primitives::NimbusId;
32use sc_service::ChainType;
33#[cfg(test)]
34use sp_core::ecdsa;
35
36/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
37pub type ChainSpec = sc_service::GenericChainSpec<Extensions, HostFunctions>;
38
39/// Generate a chain spec for use with the development service.
40pub fn development_chain_spec(mnemonic: Option<String>, num_accounts: Option<u32>) -> ChainSpec {
41	// Default mnemonic if none was provided
42	let parent_mnemonic = mnemonic.unwrap_or_else(|| {
43		"bottom drive obey lake curtain smoke basket hold race lonely fit walk".to_string()
44	});
45	let mut accounts = generate_accounts(parent_mnemonic, num_accounts.unwrap_or(10));
46	// We add Gerald here
47	accounts.push(AccountId::from(hex!(
48		"6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b"
49	)));
50
51	ChainSpec::builder(
52		WASM_BINARY.expect("WASM binary was not build, please build it!"),
53		Extensions {
54			relay_chain: "dev-service".into(),
55			para_id: Default::default(),
56		},
57	)
58	.with_name("Moonriver Development Testnet")
59	.with_id("moonriver_dev")
60	.with_chain_type(ChainType::Development)
61	.with_properties(
62		serde_json::from_str(
63			"{\"tokenDecimals\": 18, \"tokenSymbol\": \"MOVR\", \"SS58Prefix\": 1285}",
64		)
65		.expect("Provided valid json map"),
66	)
67	.with_genesis_config(testnet_genesis(
68		// Treasury Council members: Baltathar, Charleth and Dorothy
69		vec![accounts[1], accounts[2], accounts[3]],
70		// Open Tech committee members: Alith and Baltathar
71		vec![accounts[0], accounts[1]],
72		// Collator Candidate: Alice -> Alith
73		vec![(
74			AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
75			get_from_seed::<NimbusId>("Alice"),
76			100_000 * MOVR,
77		)],
78		// Delegations
79		vec![],
80		accounts.clone(),
81		Default::default(), // para_id
82		1281,               //ChainId
83	))
84	.build()
85}
86
87/// Generate a default spec for the parachain service. Use this as a starting point when launching
88/// a custom chain.
89pub fn get_chain_spec(para_id: ParaId) -> ChainSpec {
90	ChainSpec::builder(
91		WASM_BINARY.expect("WASM binary was not build, please build it!"),
92		Extensions {
93			relay_chain: "kusama-local".into(),
94			para_id: para_id.into(),
95		},
96	)
97	// TODO Apps depends on this string to determine whether the chain is an ethereum compat
98	// or not. We should decide the proper strings, and update Apps accordingly.
99	// Or maybe Apps can be smart enough to say if the string contains "moonbeam" at all...
100	.with_name("Moonriver Local Testnet")
101	.with_id("moonriver_local")
102	.with_chain_type(ChainType::Local)
103	.with_properties(
104		serde_json::from_str(
105			"{\"tokenDecimals\": 18, \"tokenSymbol\": \"MOVR\", \"SS58Prefix\": 1285}",
106		)
107		.expect("Provided valid json map"),
108	)
109	.with_genesis_config(testnet_genesis(
110		// Treasury Council members: Baltathar, Charleth and Dorothy
111		vec![
112			AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")),
113			AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")),
114			AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")),
115		],
116		// Open Tech committee members: Alith and Baltathar
117		vec![
118			AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
119			AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")),
120		],
121		// Collator Candidates
122		vec![
123			// Alice -> Alith
124			(
125				AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
126				get_from_seed::<NimbusId>("Alice"),
127				100_000 * MOVR,
128			),
129			// Bob -> Baltathar
130			(
131				AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")),
132				get_from_seed::<NimbusId>("Bob"),
133				100_000 * MOVR,
134			),
135		],
136		// Delegations
137		vec![],
138		// Endowed: Alith, Baltathar, Charleth and Dorothy
139		vec![
140			AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
141			AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")),
142			AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")),
143			AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")),
144		],
145		para_id,
146		1280, //ChainId
147	))
148	.build()
149}
150
151#[cfg(test)]
152mod tests {
153	use super::*;
154	#[test]
155	fn test_derived_pairs_1() {
156		let mnemonic =
157			"bottom drive obey lake curtain smoke basket hold race lonely fit walk".to_string();
158		let accounts = 10;
159		let pairs = derive_bip44_pairs_from_mnemonic::<ecdsa::Public>(&mnemonic, accounts);
160		let first_account = get_account_id_from_pair(pairs.first().unwrap().clone()).unwrap();
161		let last_account = get_account_id_from_pair(pairs.last().unwrap().clone()).unwrap();
162
163		let expected_first_account =
164			AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"));
165		let expected_last_account =
166			AccountId::from(hex!("2898FE7a42Be376C8BC7AF536A940F7Fd5aDd423"));
167		assert_eq!(first_account, expected_first_account);
168		assert_eq!(last_account, expected_last_account);
169		assert_eq!(pairs.len(), 10);
170	}
171	#[test]
172	fn test_derived_pairs_2() {
173		let mnemonic =
174			"slab nerve salon plastic filter inherit valve ozone crash thumb quality whale"
175				.to_string();
176		let accounts = 20;
177		let pairs = derive_bip44_pairs_from_mnemonic::<ecdsa::Public>(&mnemonic, accounts);
178		let first_account = get_account_id_from_pair(pairs.first().unwrap().clone()).unwrap();
179		let last_account = get_account_id_from_pair(pairs.last().unwrap().clone()).unwrap();
180
181		let expected_first_account =
182			AccountId::from(hex!("1e56ca71b596f2b784a27a2fdffef053dbdeff83"));
183		let expected_last_account =
184			AccountId::from(hex!("4148202BF0c0Ad7697Cff87EbB83340C80c947f8"));
185		assert_eq!(first_account, expected_first_account);
186		assert_eq!(last_account, expected_last_account);
187		assert_eq!(pairs.len(), 20);
188	}
189}