|
1 | 1 | use sc_service::ChainType; |
2 | | -use solochain_template_runtime::{AccountId, Signature, WASM_BINARY}; |
3 | | -use sp_consensus_aura::sr25519::AuthorityId as AuraId; |
4 | | -use sp_consensus_grandpa::AuthorityId as GrandpaId; |
5 | | -use sp_core::{sr25519, Pair, Public}; |
6 | | -use sp_runtime::traits::{IdentifyAccount, Verify}; |
7 | | - |
8 | | -// The URL for the telemetry server. |
9 | | -// const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; |
| 2 | +use solochain_template_runtime::WASM_BINARY; |
10 | 3 |
|
11 | 4 | /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. |
12 | 5 | pub type ChainSpec = sc_service::GenericChainSpec; |
13 | 6 |
|
14 | | -/// Generate a crypto pair from seed. |
15 | | -pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public { |
16 | | - TPublic::Pair::from_string(&format!("//{}", seed), None) |
17 | | - .expect("static values are valid; qed") |
18 | | - .public() |
19 | | -} |
20 | | - |
21 | | -type AccountPublic = <Signature as Verify>::Signer; |
22 | | - |
23 | | -/// Generate an account ID from seed. |
24 | | -pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId |
25 | | -where |
26 | | - AccountPublic: From<<TPublic::Pair as Pair>::Public>, |
27 | | -{ |
28 | | - AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account() |
29 | | -} |
30 | | - |
31 | | -/// Generate an Aura authority key. |
32 | | -pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) { |
33 | | - (get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s)) |
34 | | -} |
35 | | - |
36 | | -pub fn development_config() -> Result<ChainSpec, String> { |
| 7 | +pub fn development_chain_spec() -> Result<ChainSpec, String> { |
37 | 8 | Ok(ChainSpec::builder( |
38 | 9 | WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?, |
39 | 10 | None, |
40 | 11 | ) |
41 | 12 | .with_name("Development") |
42 | 13 | .with_id("dev") |
43 | 14 | .with_chain_type(ChainType::Development) |
44 | | - .with_genesis_config_patch(testnet_genesis( |
45 | | - // Initial PoA authorities |
46 | | - vec![authority_keys_from_seed("Alice")], |
47 | | - // Sudo account |
48 | | - get_account_id_from_seed::<sr25519::Public>("Alice"), |
49 | | - // Pre-funded accounts |
50 | | - vec![ |
51 | | - get_account_id_from_seed::<sr25519::Public>("Alice"), |
52 | | - get_account_id_from_seed::<sr25519::Public>("Bob"), |
53 | | - get_account_id_from_seed::<sr25519::Public>("Alice//stash"), |
54 | | - get_account_id_from_seed::<sr25519::Public>("Bob//stash"), |
55 | | - ], |
56 | | - true, |
57 | | - )) |
| 15 | + .with_genesis_config_preset_name(sp_genesis_builder::DEV_RUNTIME_PRESET) |
58 | 16 | .build()) |
59 | 17 | } |
60 | 18 |
|
61 | | -pub fn local_testnet_config() -> Result<ChainSpec, String> { |
| 19 | +pub fn local_chain_spec() -> Result<ChainSpec, String> { |
62 | 20 | Ok(ChainSpec::builder( |
63 | 21 | WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?, |
64 | 22 | None, |
65 | 23 | ) |
66 | 24 | .with_name("Local Testnet") |
67 | 25 | .with_id("local_testnet") |
68 | 26 | .with_chain_type(ChainType::Local) |
69 | | - .with_genesis_config_patch(testnet_genesis( |
70 | | - // Initial PoA authorities |
71 | | - vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")], |
72 | | - // Sudo account |
73 | | - get_account_id_from_seed::<sr25519::Public>("Alice"), |
74 | | - // Pre-funded accounts |
75 | | - vec![ |
76 | | - get_account_id_from_seed::<sr25519::Public>("Alice"), |
77 | | - get_account_id_from_seed::<sr25519::Public>("Bob"), |
78 | | - get_account_id_from_seed::<sr25519::Public>("Charlie"), |
79 | | - get_account_id_from_seed::<sr25519::Public>("Dave"), |
80 | | - get_account_id_from_seed::<sr25519::Public>("Eve"), |
81 | | - get_account_id_from_seed::<sr25519::Public>("Ferdie"), |
82 | | - get_account_id_from_seed::<sr25519::Public>("Alice//stash"), |
83 | | - get_account_id_from_seed::<sr25519::Public>("Bob//stash"), |
84 | | - get_account_id_from_seed::<sr25519::Public>("Charlie//stash"), |
85 | | - get_account_id_from_seed::<sr25519::Public>("Dave//stash"), |
86 | | - get_account_id_from_seed::<sr25519::Public>("Eve//stash"), |
87 | | - get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"), |
88 | | - ], |
89 | | - true, |
90 | | - )) |
| 27 | + .with_genesis_config_preset_name(sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET) |
91 | 28 | .build()) |
92 | 29 | } |
93 | | - |
94 | | -/// Configure initial storage state for FRAME modules. |
95 | | -fn testnet_genesis( |
96 | | - initial_authorities: Vec<(AuraId, GrandpaId)>, |
97 | | - root_key: AccountId, |
98 | | - endowed_accounts: Vec<AccountId>, |
99 | | - _enable_println: bool, |
100 | | -) -> serde_json::Value { |
101 | | - serde_json::json!({ |
102 | | - "balances": { |
103 | | - // Configure endowed accounts with initial balance of 1 << 60. |
104 | | - "balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::<Vec<_>>(), |
105 | | - }, |
106 | | - "aura": { |
107 | | - "authorities": initial_authorities.iter().map(|x| (x.0.clone())).collect::<Vec<_>>(), |
108 | | - }, |
109 | | - "grandpa": { |
110 | | - "authorities": initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect::<Vec<_>>(), |
111 | | - }, |
112 | | - "sudo": { |
113 | | - // Assign network admin rights. |
114 | | - "key": Some(root_key), |
115 | | - }, |
116 | | - }) |
117 | | -} |
0 commit comments