-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathchain_spec.rs
More file actions
96 lines (87 loc) · 3.31 KB
/
chain_spec.rs
File metadata and controls
96 lines (87 loc) · 3.31 KB
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
use partner_chains_cli::CreateChainSpecConfig;
use partner_chains_demo_runtime::{
AccountId, CrossChainPublic, SLOT_DURATION, SessionConfig, Signature, WASM_BINARY,
opaque::SessionKeys,
};
use sc_service::ChainType;
use sidechain_domain::ScEpochDuration;
use sp_core::{Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};
pub type ChainSpec = sc_service::GenericChainSpec;
#[derive(Clone, Debug, PartialEq)]
pub struct AuthorityKeys {
pub session: SessionKeys,
pub cross_chain: CrossChainPublic,
}
/// Generate a crypto pair from seed.
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(seed, None)
.expect("static values are valid; qed")
.public()
}
type AccountPublic = <Signature as Verify>::Signer;
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 runtime_wasm() -> &'static [u8] {
WASM_BINARY.expect("Runtime wasm not available")
}
pub const DEFAULT_SLOTS_PER_EPOCH: u64 = 60;
/// Creates chain-spec according to the config obtained by wizards.
/// [serde_json::Value] is returned instead of [sc_service::GenericChainSpec] in order to avoid
/// GPL code in the toolkit.
pub fn pc_create_chain_spec(config: &CreateChainSpecConfig<SessionKeys>) -> serde_json::Value {
let runtime_genesis_config = partner_chains_demo_runtime::RuntimeGenesisConfig {
system: partner_chains_demo_runtime::SystemConfig::default(),
balances: partner_chains_demo_runtime::BalancesConfig::default(),
aura: partner_chains_demo_runtime::AuraConfig::default(),
grandpa: partner_chains_demo_runtime::GrandpaConfig::default(),
sudo: partner_chains_demo_runtime::SudoConfig::default(),
transaction_payment: Default::default(),
session: SessionConfig {
keys: config
.initial_permissioned_candidates_parsed
.iter()
.map(|authority_keys| {
(
authority_keys.account_id_32().into(),
authority_keys.account_id_32().into(),
authority_keys.keys.clone(),
)
})
.collect(),
non_authority_keys: vec![],
},
sidechain: config.pallet_sidechain_config(ScEpochDuration::from_millis(
SLOT_DURATION * DEFAULT_SLOTS_PER_EPOCH,
)),
session_committee_management: config.pallet_session_validator_management_config(),
governed_map: config.governed_map_config(),
test_helper_pallet: partner_chains_demo_runtime::TestHelperPalletConfig {
participation_data_release_period: 30,
..Default::default()
},
bridge: config.bridge_config(),
};
let genesis_json = serde_json::to_value(runtime_genesis_config)
.expect("Genesis config must be serialized correctly");
let chain_spec = ChainSpec::builder(runtime_wasm(), None)
.with_name("Partner Chains Demo")
.with_id("partner_chains_demo")
.with_chain_type(ChainType::Live)
.with_genesis_config(genesis_json)
.with_boot_nodes(config.bootnodes.iter().map(|bn| bn.parse().unwrap()).collect())
.build();
let raw = false;
let chain_spec_str = chain_spec.as_json(raw).expect("Chain spec serialization can not fail");
serde_json::from_str(&chain_spec_str).unwrap()
}
pub(crate) fn read_slots_per_epoch_from_env() -> u64 {
std::env::var("SLOTS_PER_EPOCH")
.ok()
.and_then(|s| s.parse().ok())
.unwrap_or(DEFAULT_SLOTS_PER_EPOCH)
}