Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 57cc25b

Browse files
committed
Introduce PoC-1 spec
1 parent a13b429 commit 57cc25b

File tree

3 files changed

+82
-8
lines changed

3 files changed

+82
-8
lines changed

polkadot/cli/poc-1.json

Lines changed: 38 additions & 0 deletions
Large diffs are not rendered by default.

polkadot/cli/src/chain_spec.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ pub enum ChainSpec {
2424
Development,
2525
/// Whatever the current runtime is, with simple Alice/Bob auths.
2626
LocalTestnet,
27+
/// The PoC-1 testnet.
28+
PoC1Testnet,
2729
/// The PoC-2 testnet.
2830
PoC2Testnet,
2931
/// Custom Genesis file.
@@ -35,6 +37,7 @@ impl<'a> From<&'a str> for ChainSpec {
3537
match s {
3638
"dev" => ChainSpec::Development,
3739
"local" => ChainSpec::LocalTestnet,
40+
"poc-1" => ChainSpec::PoC1Testnet,
3841
"poc-2" => ChainSpec::PoC2Testnet,
3942
s => ChainSpec::Custom(s.into()),
4043
}
@@ -46,6 +49,7 @@ impl From<ChainSpec> for String {
4649
match s {
4750
ChainSpec::Development => "dev".into(),
4851
ChainSpec::LocalTestnet => "local".into(),
52+
ChainSpec::PoC1Testnet => "poc-1".into(),
4953
ChainSpec::PoC2Testnet => "poc-2".into(),
5054
ChainSpec::Custom(f) => format!("custom ({})", f),
5155
}
@@ -60,6 +64,7 @@ impl ::std::fmt::Display for ChainSpec {
6064
write!(f, "{}", match *self {
6165
ChainSpec::Development => "Development",
6266
ChainSpec::LocalTestnet => "Local Testnet",
67+
ChainSpec::PoC1Testnet => "PoC-1 Testnet",
6368
ChainSpec::PoC2Testnet => "PoC-2 Testnet",
6469
_ => unreachable!(),
6570
})

polkadot/cli/src/preset_config.rs

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,43 @@
1616

1717
//! Polkadot chain configurations.
1818
19+
use std::collections::HashMap;
1920
use ed25519;
20-
use substrate_primitives::AuthorityId;
21-
use chain_spec::ChainSpec;
22-
use runtime_primitives::{MakeStorage, BuildStorage};
21+
use serde_json;
22+
use substrate_primitives::{AuthorityId, storage::{StorageKey, StorageData}};
23+
use runtime_primitives::{MakeStorage, BuildStorage, StorageMap};
2324
use polkadot_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
2425
SessionConfig, StakingConfig};
26+
use chain_spec::ChainSpec;
27+
28+
enum Config {
29+
Local(GenesisConfig),
30+
Raw(&'static [u8]),
31+
}
2532

2633
/// A configuration of a chain. Can be used to build a genesis block.
2734
pub struct PresetConfig {
28-
pub(crate) genesis_config: GenesisConfig,
35+
genesis_config: Config,
2936
pub(crate) boot_nodes: Vec<String>,
3037
}
3138

39+
impl BuildStorage for Config {
40+
fn build_storage(self) -> StorageMap {
41+
match self {
42+
Config::Local(gc) => gc.build_storage(),
43+
Config::Raw(json) => {
44+
let h: HashMap<StorageKey, StorageData> = serde_json::from_slice(json).expect("Data is from an internal source and is guaranteed to be of the correct format");
45+
h.into_iter().map(|(k, v)| (k.0, v.0)).collect()
46+
}
47+
}
48+
}
49+
}
50+
3251
impl PresetConfig {
3352
/// Get a chain config from a spec, if it's predefined.
3453
pub fn from_spec(chain_spec: ChainSpec) -> Result<Self, String> {
3554
Ok(match chain_spec {
55+
ChainSpec::PoC1Testnet => Self::poc_1_testnet_config(),
3656
ChainSpec::Development => Self::development_config(),
3757
ChainSpec::LocalTestnet => Self::local_testnet_config(),
3858
ChainSpec::PoC2Testnet => Self::poc_2_testnet_config(),
@@ -48,6 +68,17 @@ impl PresetConfig {
4868
(Box::new(f), self.boot_nodes)
4969
}
5070

71+
/// PoC-1 testnet config.
72+
fn poc_1_testnet_config() -> Self {
73+
let genesis_config = Config::Raw(include_bytes!("../poc-1.json"));
74+
let boot_nodes = vec![
75+
"enode://a93a29fa68d965452bf0ff8c1910f5992fe2273a72a1ee8d3a3482f68512a61974211ba32bb33f051ceb1530b8ba3527fc36224ba6b9910329025e6d9153cf50@104.211.54.233:30333".into(),
76+
"enode://051b18f63a316c4c5fef4631f8c550ae0adba179153588406fac3e5bbbbf534ebeda1bf475dceda27a531f6cdef3846ab6a010a269aa643a1fec7bff51af66bd@104.211.48.51:30333".into(),
77+
"enode://c831ec9011d2c02d2c4620fc88db6d897a40d2f88fd75f47b9e4cf3b243999acb6f01b7b7343474650b34eeb1363041a422a91f1fc3850e43482983ee15aa582@104.211.48.247:30333".into(),
78+
];
79+
PresetConfig { genesis_config, boot_nodes }
80+
}
81+
5182
/// PoC-2 testnet config.
5283
fn poc_2_testnet_config() -> Self {
5384
let initial_authorities = vec![
@@ -59,7 +90,7 @@ impl PresetConfig {
5990
let endowed_accounts = vec![
6091
hex!["f295940fa750df68a686fcf4abd4111c8a9c5a5a5a83c4c8639c451a94a7adfd"].into(),
6192
];
62-
let genesis_config = GenesisConfig {
93+
let genesis_config = Config::Local(GenesisConfig {
6394
consensus: Some(ConsensusConfig {
6495
code: include_bytes!("../../runtime/wasm/genesis.wasm").to_vec(), // TODO change
6596
authorities: initial_authorities.clone(),
@@ -105,7 +136,7 @@ impl PresetConfig {
105136
voting_period: 7 * 120 * 24, // 7 day voting period for council members.
106137
}),
107138
parachains: Some(Default::default()),
108-
};
139+
});
109140
let boot_nodes = vec![
110141
"enode://a93a29fa68d965452bf0ff8c1910f5992fe2273a72a1ee8d3a3482f68512a61974211ba32bb33f051ceb1530b8ba3527fc36224ba6b9910329025e6d9153cf50@104.211.54.233:30333".into(),
111142
"enode://051b18f63a316c4c5fef4631f8c550ae0adba179153588406fac3e5bbbbf534ebeda1bf475dceda27a531f6cdef3846ab6a010a269aa643a1fec7bff51af66bd@104.211.48.51:30333".into(),
@@ -123,7 +154,7 @@ impl PresetConfig {
123154
ed25519::Pair::from_seed(b"Eve ").public().0.into(),
124155
ed25519::Pair::from_seed(b"Ferdie ").public().0.into(),
125156
];
126-
let genesis_config = GenesisConfig {
157+
let genesis_config = Config::Local(GenesisConfig {
127158
consensus: Some(ConsensusConfig {
128159
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm").to_vec(),
129160
authorities: initial_authorities.clone(),
@@ -169,7 +200,7 @@ impl PresetConfig {
169200
voting_period: 20,
170201
}),
171202
parachains: Some(Default::default()),
172-
};
203+
});
173204
let boot_nodes = Vec::new();
174205
PresetConfig { genesis_config, boot_nodes }
175206
}

0 commit comments

Comments
 (0)