/home/runner/work/creditcoin/creditcoin/node/src/chain_spec.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use creditcoin_node_runtime::{ |
2 | | AccountId, BalancesConfig, CreditcoinConfig, DifficultyConfig, GenesisConfig, Signature, |
3 | | SudoConfig, SystemConfig, WASM_BINARY, |
4 | | }; |
5 | | use sc_service::ChainType; |
6 | | use sp_core::{sr25519, Pair, Public, U256}; |
7 | | use sp_runtime::traits::{IdentifyAccount, Verify}; |
8 | | |
9 | | // The URL for the telemetry server. |
10 | | // const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; |
11 | | |
12 | | /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. |
13 | | pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>; |
14 | | |
15 | | /// Generate a crypto pair from seed. |
16 | 0 | pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public { |
17 | 0 | TPublic::Pair::from_string(&format!("//{}", seed), None) |
18 | 0 | .expect("static values are valid; qed") |
19 | 0 | .public() |
20 | 0 | } |
21 | | |
22 | | type AccountPublic = <Signature as Verify>::Signer; |
23 | | |
24 | | /// Generate an account ID from seed. |
25 | 0 | pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId |
26 | 0 | where |
27 | 0 | AccountPublic: From<<TPublic::Pair as Pair>::Public>, |
28 | 0 | { |
29 | 0 | AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account() |
30 | 0 | } |
31 | | |
32 | 0 | pub fn development_config() -> Result<ChainSpec, String> { |
33 | 0 | let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; |
34 | | |
35 | 0 | Ok(ChainSpec::from_genesis( |
36 | 0 | // Name |
37 | 0 | "Development", |
38 | 0 | // ID |
39 | 0 | "dev", |
40 | 0 | ChainType::Development, |
41 | 0 | move || { |
42 | 0 | testnet_genesis( |
43 | 0 | wasm_binary, |
44 | 0 | // Sudo account |
45 | 0 | get_account_id_from_seed::<sr25519::Public>("Alice"), |
46 | 0 | // Pre-funded accounts |
47 | 0 | vec![ |
48 | 0 | get_account_id_from_seed::<sr25519::Public>("Alice"), |
49 | 0 | get_account_id_from_seed::<sr25519::Public>("Bob"), |
50 | 0 | get_account_id_from_seed::<sr25519::Public>("Alice//stash"), |
51 | 0 | get_account_id_from_seed::<sr25519::Public>("Bob//stash"), |
52 | 0 | ], |
53 | 0 | Some(6000), |
54 | 0 | Some(128), |
55 | 0 | ) |
56 | 0 | }, |
57 | 0 | // Bootnodes |
58 | 0 | vec![], |
59 | 0 | // Telemetry |
60 | 0 | None, |
61 | 0 | // Protocol ID |
62 | 0 | None, |
63 | 0 | // Fork ID |
64 | 0 | None, |
65 | 0 | // Properties |
66 | 0 | None, |
67 | 0 | // Extensions |
68 | 0 | None, |
69 | 0 | )) |
70 | 0 | } |
71 | | |
72 | 0 | pub fn local_testnet_config() -> Result<ChainSpec, String> { |
73 | 0 | let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?; |
74 | | |
75 | 0 | Ok(ChainSpec::from_genesis( |
76 | 0 | // Name |
77 | 0 | "Local Testnet", |
78 | 0 | // ID |
79 | 0 | "local_testnet", |
80 | 0 | ChainType::Local, |
81 | 0 | move || { |
82 | 0 | testnet_genesis( |
83 | 0 | wasm_binary, |
84 | 0 | // Sudo account |
85 | 0 | get_account_id_from_seed::<sr25519::Public>("Alice"), |
86 | 0 | // Pre-funded accounts |
87 | 0 | vec![ |
88 | 0 | get_account_id_from_seed::<sr25519::Public>("Alice"), |
89 | 0 | get_account_id_from_seed::<sr25519::Public>("Bob"), |
90 | 0 | get_account_id_from_seed::<sr25519::Public>("Charlie"), |
91 | 0 | get_account_id_from_seed::<sr25519::Public>("Dave"), |
92 | 0 | get_account_id_from_seed::<sr25519::Public>("Eve"), |
93 | 0 | get_account_id_from_seed::<sr25519::Public>("Ferdie"), |
94 | 0 | get_account_id_from_seed::<sr25519::Public>("Alice//stash"), |
95 | 0 | get_account_id_from_seed::<sr25519::Public>("Bob//stash"), |
96 | 0 | get_account_id_from_seed::<sr25519::Public>("Charlie//stash"), |
97 | 0 | get_account_id_from_seed::<sr25519::Public>("Dave//stash"), |
98 | 0 | get_account_id_from_seed::<sr25519::Public>("Eve//stash"), |
99 | 0 | get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"), |
100 | 0 | ], |
101 | 0 | None, |
102 | 0 | None, |
103 | 0 | ) |
104 | 0 | }, |
105 | 0 | // Bootnodes |
106 | 0 | vec![], |
107 | 0 | // Telemetry |
108 | 0 | None, |
109 | 0 | // Protocol ID |
110 | 0 | None, |
111 | 0 | // Fork ID |
112 | 0 | None, |
113 | 0 | // Properties |
114 | 0 | None, |
115 | 0 | // Extensions |
116 | 0 | None, |
117 | 0 | )) |
118 | 0 | } |
119 | | |
120 | 0 | pub fn testnet_config() -> Result<ChainSpec, String> { |
121 | 0 | ChainSpec::from_json_bytes(&include_bytes!("../../chainspecs/testnetSpec.json")[..]) |
122 | 0 | } |
123 | | |
124 | 0 | pub fn mainnet_config() -> Result<ChainSpec, String> { |
125 | 0 | ChainSpec::from_json_bytes(&include_bytes!("../../chainspecs/mainnetSpec.json")[..]) |
126 | 0 | } |
127 | | |
128 | | /// Configure initial storage state for FRAME modules. |
129 | 0 | fn testnet_genesis( |
130 | 0 | wasm_binary: &[u8], |
131 | 0 | root_key: AccountId, |
132 | 0 | endowed_accounts: Vec<AccountId>, |
133 | 0 | target_time: Option<u64>, |
134 | 0 | adjustment: Option<i64>, |
135 | 0 | ) -> GenesisConfig { |
136 | 0 | GenesisConfig { |
137 | 0 | system: SystemConfig { |
138 | 0 | // Add Wasm runtime to storage. |
139 | 0 | code: wasm_binary.to_vec(), |
140 | 0 | }, |
141 | 0 | balances: BalancesConfig { |
142 | 0 | // Configure endowed accounts with initial balance of 1 << 60. |
143 | 0 | balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(), |
144 | 0 | }, |
145 | 0 | sudo: SudoConfig { |
146 | 0 | // Assign network admin rights. |
147 | 0 | key: Some(root_key), |
148 | 0 | }, |
149 | 0 | difficulty: DifficultyConfig { |
150 | 0 | initial_difficulty: U256::from(1_000_000u64), |
151 | 0 | target_time: target_time.unwrap_or(60 * 1000), |
152 | 0 | difficulty_adjustment_period: adjustment.unwrap_or(43), |
153 | 0 | }, |
154 | 0 | creditcoin: CreditcoinConfig::default(), |
155 | 0 | } |
156 | 0 | } |