-
Notifications
You must be signed in to change notification settings - Fork 3
/
chain_spec.rs
180 lines (170 loc) · 6.66 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
use sc_service::ChainType;
use sp_consensus_babe::AuthorityId as BabeId;
use sp_consensus_grandpa::AuthorityId as GrandpaId;
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
use sqnc_runtime::WASM_BINARY;
use sqnc_runtime_types::{AccountId, RuntimeExpressionSymbol, RuntimeRestriction, Signature};
const DEFAULT_PROTOCOL_ID: &str = "sqnc";
/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::GenericChainSpec;
/// Generate a crypto pair from seed.
pub 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()
}
type AccountPublic = <Signature as Verify>::Signer;
/// Generate an account ID from 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()
}
/// Generate an authority key.
pub fn authority_keys_from_seed(s: &str) -> (BabeId, GrandpaId) {
(get_from_seed::<BabeId>(s), get_from_seed::<GrandpaId>(s))
}
pub fn development_config() -> Result<ChainSpec, String> {
Ok(ChainSpec::builder(
WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?,
None,
)
.with_name("Development")
.with_id("dev")
.with_protocol_id(DEFAULT_PROTOCOL_ID)
.with_chain_type(ChainType::Development)
.with_genesis_config_patch(testnet_genesis(
// Initial PoA authorities
vec![authority_keys_from_seed("Alice")],
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
// Pre-funded accounts
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
],
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
],
vec![(
//0000000000000000000000000000000000000000000000000000000000000001
bs58::decode("12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp")
.into_vec()
.unwrap(),
get_account_id_from_seed::<sr25519::Public>("Alice"),
)],
))
.build())
}
pub fn l3_sqnc_config() -> Result<ChainSpec, String> {
ChainSpec::from_json_bytes(&include_bytes!("../res/l3-sqnc.json")[..])
}
pub fn local_testnet_config() -> Result<ChainSpec, String> {
Ok(ChainSpec::builder(
WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?,
None,
)
.with_name("Local Testnet")
.with_id("local_testnet")
.with_protocol_id(DEFAULT_PROTOCOL_ID)
.with_chain_type(ChainType::Local)
.with_genesis_config_patch(testnet_genesis(
// Initial PoA authorities
vec![
authority_keys_from_seed("Alice"),
authority_keys_from_seed("Bob"),
authority_keys_from_seed("Charlie"),
],
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
// Pre-funded accounts
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
],
vec![
get_account_id_from_seed::<sr25519::Public>("Alice"),
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
],
vec![
(
// 0000000000000000000000000000000000000000000000000000000000000001
bs58::decode("12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp")
.into_vec()
.unwrap(),
get_account_id_from_seed::<sr25519::Public>("Alice"),
),
(
// 0000000000000000000000000000000000000000000000000000000000000002
bs58::decode("12D3KooWHdiAxVd8uMQR1hGWXccidmfCwLqcMpGwR6QcTP6QRMuD")
.into_vec()
.unwrap(),
get_account_id_from_seed::<sr25519::Public>("Bob"),
),
(
// 0000000000000000000000000000000000000000000000000000000000000003
bs58::decode("12D3KooWSCufgHzV4fCwRijfH2k3abrpAJxTKxEvN1FDuRXA2U9x")
.into_vec()
.unwrap(),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
),
(
// 0000000000000000000000000000000000000000000000000000000000000004
bs58::decode("12D3KooWSsChzF81YDUKpe9Uk5AHV5oqAaXAcWNSPYgoLauUk4st")
.into_vec()
.unwrap(),
get_account_id_from_seed::<sr25519::Public>("Eve"),
),
],
))
.build())
}
/// Configure initial storage state for FRAME modules.
fn testnet_genesis(
initial_authorities: Vec<(BabeId, GrandpaId)>,
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
technical_committee_accounts: Vec<AccountId>,
authorized_nodes: Vec<(Vec<u8>, AccountId)>,
) -> serde_json::Value {
serde_json::json!({
"balances": {
"balances": endowed_accounts.iter().cloned().map(|k| (k, 1i64 << 60)).collect::<Vec<_>>(),
},
"babe": {
"authorities": initial_authorities.iter().map(|x| (x.0.clone(), 1)).collect::<Vec<_>>(),
"epochConfig": Some(sqnc_runtime::BABE_GENESIS_EPOCH_CONFIG),
},
"grandpa": {
"authorities": initial_authorities.iter().map(|x| (x.1.clone(), 1)).collect::<Vec<_>>(),
},
"sudo": {
"key": Some(root_key),
},
"nodeAuthorization": {
"nodes": authorized_nodes,
},
"membership": {
"members": technical_committee_accounts,
},
"technicalCommittee": {
"members": Vec::<AccountId>::new()
},
"processValidation": {
"processes": vec![(
"default".as_bytes().to_vec(),
vec![RuntimeExpressionSymbol::Restriction(RuntimeRestriction::None)],
)],
},
})
}