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

Commit

Permalink
Introduce PoC-1 spec
Browse files Browse the repository at this point in the history
  • Loading branch information
gavofyork authored and arkpar committed Jun 18, 2018
1 parent 8068165 commit 7c45f35
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 8 deletions.
38 changes: 38 additions & 0 deletions polkadot/cli/poc-1.json

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions polkadot/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub enum ChainSpec {
Development,
/// Whatever the current runtime is, with simple Alice/Bob auths.
LocalTestnet,
/// The PoC-1 testnet.
PoC1Testnet,
/// The PoC-2 testnet.
PoC2Testnet,
/// Custom Genesis file.
Expand All @@ -35,6 +37,7 @@ impl<'a> From<&'a str> for ChainSpec {
match s {
"dev" => ChainSpec::Development,
"local" => ChainSpec::LocalTestnet,
"poc-1" => ChainSpec::PoC1Testnet,
"poc-2" => ChainSpec::PoC2Testnet,
s => ChainSpec::Custom(s.into()),
}
Expand All @@ -46,6 +49,7 @@ impl From<ChainSpec> for String {
match s {
ChainSpec::Development => "dev".into(),
ChainSpec::LocalTestnet => "local".into(),
ChainSpec::PoC1Testnet => "poc-1".into(),
ChainSpec::PoC2Testnet => "poc-2".into(),
ChainSpec::Custom(f) => format!("custom ({})", f),
}
Expand All @@ -60,6 +64,7 @@ impl ::std::fmt::Display for ChainSpec {
write!(f, "{}", match *self {
ChainSpec::Development => "Development",
ChainSpec::LocalTestnet => "Local Testnet",
ChainSpec::PoC1Testnet => "PoC-1 Testnet",
ChainSpec::PoC2Testnet => "PoC-2 Testnet",
_ => unreachable!(),
})
Expand Down
47 changes: 39 additions & 8 deletions polkadot/cli/src/preset_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,43 @@

//! Polkadot chain configurations.

use std::collections::HashMap;
use ed25519;
use substrate_primitives::AuthorityId;
use chain_spec::ChainSpec;
use runtime_primitives::{MakeStorage, BuildStorage};
use serde_json;
use substrate_primitives::{AuthorityId, storage::{StorageKey, StorageData}};
use runtime_primitives::{MakeStorage, BuildStorage, StorageMap};
use polkadot_runtime::{GenesisConfig, ConsensusConfig, CouncilConfig, DemocracyConfig,
SessionConfig, StakingConfig};
use chain_spec::ChainSpec;

enum Config {
Local(GenesisConfig),
Raw(&'static [u8]),
}

/// A configuration of a chain. Can be used to build a genesis block.
pub struct PresetConfig {
pub(crate) genesis_config: GenesisConfig,
genesis_config: Config,
pub(crate) boot_nodes: Vec<String>,
}

impl BuildStorage for Config {
fn build_storage(self) -> StorageMap {
match self {
Config::Local(gc) => gc.build_storage(),
Config::Raw(json) => {
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");
h.into_iter().map(|(k, v)| (k.0, v.0)).collect()
}
}
}
}

impl PresetConfig {
/// Get a chain config from a spec, if it's predefined.
pub fn from_spec(chain_spec: ChainSpec) -> Result<Self, String> {
Ok(match chain_spec {
ChainSpec::PoC1Testnet => Self::poc_1_testnet_config(),
ChainSpec::Development => Self::development_config(),
ChainSpec::LocalTestnet => Self::local_testnet_config(),
ChainSpec::PoC2Testnet => Self::poc_2_testnet_config(),
Expand All @@ -48,6 +68,17 @@ impl PresetConfig {
(Box::new(f), self.boot_nodes)
}

/// PoC-1 testnet config.
fn poc_1_testnet_config() -> Self {
let genesis_config = Config::Raw(include_bytes!("../poc-1.json"));
let boot_nodes = vec![
"enode://a93a29fa68d965452bf0ff8c1910f5992fe2273a72a1ee8d3a3482f68512a61974211ba32bb33f051ceb1530b8ba3527fc36224ba6b9910329025e6d9153cf50@104.211.54.233:30333".into(),
"enode://051b18f63a316c4c5fef4631f8c550ae0adba179153588406fac3e5bbbbf534ebeda1bf475dceda27a531f6cdef3846ab6a010a269aa643a1fec7bff51af66bd@104.211.48.51:30333".into(),
"enode://c831ec9011d2c02d2c4620fc88db6d897a40d2f88fd75f47b9e4cf3b243999acb6f01b7b7343474650b34eeb1363041a422a91f1fc3850e43482983ee15aa582@104.211.48.247:30333".into(),
];
PresetConfig { genesis_config, boot_nodes }
}

/// PoC-2 testnet config.
fn poc_2_testnet_config() -> Self {
let initial_authorities = vec![
Expand All @@ -59,7 +90,7 @@ impl PresetConfig {
let endowed_accounts = vec![
hex!["f295940fa750df68a686fcf4abd4111c8a9c5a5a5a83c4c8639c451a94a7adfd"].into(),
];
let genesis_config = GenesisConfig {
let genesis_config = Config::Local(GenesisConfig {
consensus: Some(ConsensusConfig {
code: include_bytes!("../../runtime/wasm/genesis.wasm").to_vec(), // TODO change
authorities: initial_authorities.clone(),
Expand Down Expand Up @@ -105,7 +136,7 @@ impl PresetConfig {
voting_period: 7 * 120 * 24, // 7 day voting period for council members.
}),
parachains: Some(Default::default()),
};
});
let boot_nodes = vec![
"enode://a93a29fa68d965452bf0ff8c1910f5992fe2273a72a1ee8d3a3482f68512a61974211ba32bb33f051ceb1530b8ba3527fc36224ba6b9910329025e6d9153cf50@104.211.54.233:30333".into(),
"enode://051b18f63a316c4c5fef4631f8c550ae0adba179153588406fac3e5bbbbf534ebeda1bf475dceda27a531f6cdef3846ab6a010a269aa643a1fec7bff51af66bd@104.211.48.51:30333".into(),
Expand All @@ -123,7 +154,7 @@ impl PresetConfig {
ed25519::Pair::from_seed(b"Eve ").public().0.into(),
ed25519::Pair::from_seed(b"Ferdie ").public().0.into(),
];
let genesis_config = GenesisConfig {
let genesis_config = Config::Local(GenesisConfig {
consensus: Some(ConsensusConfig {
code: include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/polkadot_runtime.compact.wasm").to_vec(),
authorities: initial_authorities.clone(),
Expand Down Expand Up @@ -169,7 +200,7 @@ impl PresetConfig {
voting_period: 20,
}),
parachains: Some(Default::default()),
};
});
let boot_nodes = Vec::new();
PresetConfig { genesis_config, boot_nodes }
}
Expand Down

0 comments on commit 7c45f35

Please sign in to comment.