-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathchain_spec.rs
142 lines (124 loc) · 4.61 KB
/
chain_spec.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// KILT Blockchain – <https://kilt.io>
// Copyright (C) 2025, KILT Foundation
// The KILT Blockchain is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// The KILT Blockchain is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// If you feel like getting in touch with us, you can do so at <hello@kilt.io>
// Triggered by the `ChainSpecGroup` derive macro used for the custom chainspec
// extension.
#![allow(clippy::derive_partial_eq_without_eq)]
use cumulus_primitives_core::ParaId;
use dip_provider_runtime_template::{
AccountId, AuraId, BalancesConfig, CollatorSelectionConfig, ParachainInfoConfig, RuntimeGenesisConfig,
SessionConfig, SessionKeys, Signature, SudoConfig, EXISTENTIAL_DEPOSIT, SS58_PREFIX, WASM_BINARY,
};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup, Properties};
use sc_service::{ChainType, GenericChainSpec};
use serde::{Deserialize, Serialize};
use serde_json::to_value;
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
const PARA_ID: u32 = 2_000;
pub type ChainSpec = GenericChainSpec<RuntimeGenesisConfig, Extensions>;
type AccountPublic = <Signature as Verify>::Signer;
pub(crate) fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
.expect("static values are valid; qed")
.public()
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
#[serde(deny_unknown_fields)]
pub struct Extensions {
pub relay_chain: String,
pub para_id: u32,
}
impl Extensions {
pub fn try_get(chain_spec: &dyn sc_service::ChainSpec) -> Option<&Self> {
sc_chain_spec::get_extension(chain_spec.extensions())
}
}
pub fn get_collator_keys_from_seed(seed: &str) -> AuraId {
get_from_seed::<AuraId>(seed)
}
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
}
pub fn template_session_keys(keys: AuraId) -> SessionKeys {
SessionKeys { aura: keys }
}
fn testnet_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> RuntimeGenesisConfig {
RuntimeGenesisConfig {
parachain_info: ParachainInfoConfig {
parachain_id: id,
..Default::default()
},
sudo: SudoConfig {
key: Some(endowed_accounts.first().unwrap().clone()),
},
balances: BalancesConfig {
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
},
collator_selection: CollatorSelectionConfig {
invulnerables: invulnerables.iter().cloned().map(|(acc, _)| acc).collect(),
candidacy_bond: EXISTENTIAL_DEPOSIT * 16,
..Default::default()
},
session: SessionConfig {
keys: invulnerables
.into_iter()
.map(|(acc, aura)| (acc.clone(), acc, template_session_keys(aura)))
.collect(),
},
..Default::default()
}
}
pub fn development_config() -> ChainSpec {
let wasm_binary = WASM_BINARY.expect("WASM binary was not build, please build it!");
let mut properties = Properties::new();
properties.insert("tokenSymbol".into(), "SEILT".into());
properties.insert("tokenDecimals".into(), 12.into());
properties.insert("ss58Format".into(), SS58_PREFIX.into());
let genesis_state = testnet_genesis(
vec![(
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_collator_keys_from_seed("Alice"),
)],
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
],
PARA_ID.into(),
);
ChainSpec::builder(
wasm_binary,
Extensions {
relay_chain: "rococo-local".into(),
para_id: PARA_ID,
},
)
.with_name("DIP provider dev")
.with_id("dip-provider-dev")
.with_chain_type(ChainType::Development)
.with_protocol_id("dip-consumer-dev")
.with_properties(properties)
.with_genesis_config(to_value(genesis_state).unwrap())
.build()
}