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)]
23
use crate::chain_spec::{derive_bip44_pairs_from_mnemonic, get_account_id_from_pair};
24
use crate::chain_spec::{generate_accounts, get_from_seed, Extensions};
25
use cumulus_primitives_core::ParaId;
26
use hex_literal::hex;
27
use moonriver_runtime::{
28
	currency::MOVR, genesis_config_preset::testnet_genesis, AccountId, WASM_BINARY,
29
};
30
use nimbus_primitives::NimbusId;
31
use sc_service::ChainType;
32
#[cfg(test)]
33
use sp_core::ecdsa;
34

            
35
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
36
pub type ChainSpec = sc_service::GenericChainSpec<Extensions>;
37

            
38
/// Generate a chain spec for use with the development service.
39
pub fn development_chain_spec(mnemonic: Option<String>, num_accounts: Option<u32>) -> ChainSpec {
40
	// Default mnemonic if none was provided
41
	let parent_mnemonic = mnemonic.unwrap_or_else(|| {
42
		"bottom drive obey lake curtain smoke basket hold race lonely fit walk".to_string()
43
	});
44
	let mut accounts = generate_accounts(parent_mnemonic, num_accounts.unwrap_or(10));
45
	// We add Gerald here
46
	accounts.push(AccountId::from(hex!(
47
		"6Be02d1d3665660d22FF9624b7BE0551ee1Ac91b"
48
	)));
49

            
50
	ChainSpec::builder(
51
		WASM_BINARY.expect("WASM binary was not build, please build it!"),
52
		Extensions {
53
			relay_chain: "dev-service".into(),
54
			para_id: Default::default(),
55
		},
56
	)
57
	.with_name("Moonriver Development Testnet")
58
	.with_id("moonriver_dev")
59
	.with_chain_type(ChainType::Development)
60
	.with_properties(
61
		serde_json::from_str(
62
			"{\"tokenDecimals\": 18, \"tokenSymbol\": \"MOVR\", \"SS58Prefix\": 1285}",
63
		)
64
		.expect("Provided valid json map"),
65
	)
66
	.with_genesis_config(testnet_genesis(
67
		// Treasury Council members: Baltathar, Charleth and Dorothy
68
		vec![accounts[1], accounts[2], accounts[3]],
69
		// Open Tech committee members: Alith and Baltathar
70
		vec![accounts[0], accounts[1]],
71
		// Collator Candidate: Alice -> Alith
72
		vec![(
73
			AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
74
			get_from_seed::<NimbusId>("Alice"),
75
			100_000 * MOVR,
76
		)],
77
		// Delegations
78
		vec![],
79
		accounts.clone(),
80
		3_000_000 * MOVR,
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.
89
pub 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
		3_000_000 * MOVR,
146
		para_id,
147
		1280, //ChainId
148
	))
149
	.build()
150
}
151

            
152
#[cfg(test)]
153
mod tests {
154
	use super::*;
155
	#[test]
156
	fn test_derived_pairs_1() {
157
		let mnemonic =
158
			"bottom drive obey lake curtain smoke basket hold race lonely fit walk".to_string();
159
		let accounts = 10;
160
		let pairs = derive_bip44_pairs_from_mnemonic::<ecdsa::Public>(&mnemonic, accounts);
161
		let first_account = get_account_id_from_pair(pairs.first().unwrap().clone()).unwrap();
162
		let last_account = get_account_id_from_pair(pairs.last().unwrap().clone()).unwrap();
163

            
164
		let expected_first_account =
165
			AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"));
166
		let expected_last_account =
167
			AccountId::from(hex!("2898FE7a42Be376C8BC7AF536A940F7Fd5aDd423"));
168
		assert_eq!(first_account, expected_first_account);
169
		assert_eq!(last_account, expected_last_account);
170
		assert_eq!(pairs.len(), 10);
171
	}
172
	#[test]
173
	fn test_derived_pairs_2() {
174
		let mnemonic =
175
			"slab nerve salon plastic filter inherit valve ozone crash thumb quality whale"
176
				.to_string();
177
		let accounts = 20;
178
		let pairs = derive_bip44_pairs_from_mnemonic::<ecdsa::Public>(&mnemonic, accounts);
179
		let first_account = get_account_id_from_pair(pairs.first().unwrap().clone()).unwrap();
180
		let last_account = get_account_id_from_pair(pairs.last().unwrap().clone()).unwrap();
181

            
182
		let expected_first_account =
183
			AccountId::from(hex!("1e56ca71b596f2b784a27a2fdffef053dbdeff83"));
184
		let expected_last_account =
185
			AccountId::from(hex!("4148202BF0c0Ad7697Cff87EbB83340C80c947f8"));
186
		assert_eq!(first_account, expected_first_account);
187
		assert_eq!(last_account, expected_last_account);
188
		assert_eq!(pairs.len(), 20);
189
	}
190
}