chain_spec.rs 2.33 KB
Newer Older
Shawn Tabrizi's avatar
Shawn Tabrizi committed
1
// Copyright 2017-2020 Parity Technologies (UK) Ltd.
Gav Wood's avatar
Gav Wood committed
2
3
4
5
6
7
8
9
10
11
12
13
14
// This file is part of Polkadot.

// Polkadot 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.

// Polkadot 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
15
// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
Gav Wood's avatar
Gav Wood committed
16
17
18

//! Predefined chains.

19
20
use service;

Gav Wood's avatar
Gav Wood committed
21
22
23
24
25
26
27
28
/// The chain specification (this should eventually be replaced by a more general JSON-based chain
/// specification).
#[derive(Clone, Debug)]
pub enum ChainSpec {
	/// Whatever the current runtime is, with just Alice as an auth.
	Development,
	/// Whatever the current runtime is, with simple Alice/Bob auths.
	LocalTestnet,
29
30
	/// The Kusama network.
	Kusama,
ddorgan's avatar
ddorgan committed
31
32
	/// The Westend network,
	Westend,
Gav Wood's avatar
Gav Wood committed
33
34
	/// Whatever the current runtime is with the "global testnet" defaults.
	StagingTestnet,
Gav Wood's avatar
Gav Wood committed
35
36
}

37
38
impl Default for ChainSpec {
	fn default() -> Self {
39
		ChainSpec::Kusama
40
41
42
	}
}

43
44
45
/// Get a chain config from a spec setting.
impl ChainSpec {
	pub(crate) fn load(self) -> Result<service::ChainSpec, String> {
46
47
48
49
		match self {
			ChainSpec::Development => Ok(service::chain_spec::development_config()),
			ChainSpec::LocalTestnet => Ok(service::chain_spec::local_testnet_config()),
			ChainSpec::StagingTestnet => Ok(service::chain_spec::staging_testnet_config()),
ddorgan's avatar
ddorgan committed
50
			ChainSpec::Westend => service::chain_spec::westend_config(),
51
52
53
54
			ChainSpec::Kusama => service::chain_spec::kusama_config(),
		}
	}

Arkadiy Paronyan's avatar
Arkadiy Paronyan committed
55
	pub(crate) fn from(s: &str) -> Option<Self> {
Gav Wood's avatar
Gav Wood committed
56
		match s {
Arkadiy Paronyan's avatar
Arkadiy Paronyan committed
57
58
			"dev" => Some(ChainSpec::Development),
			"local" => Some(ChainSpec::LocalTestnet),
59
			"kusama" => Some(ChainSpec::Kusama),
ddorgan's avatar
ddorgan committed
60
			"westend" => Some(ChainSpec::Westend),
Arkadiy Paronyan's avatar
Arkadiy Paronyan committed
61
			"staging" => Some(ChainSpec::StagingTestnet),
62
			"" => Some(ChainSpec::default()),
Arkadiy Paronyan's avatar
Arkadiy Paronyan committed
63
			_ => None,
Gav Wood's avatar
Gav Wood committed
64
65
66
67
		}
	}
}

Gavin Wood's avatar
Gavin Wood committed
68
69
70
71
72
73
74
/// Load the `ChainSpec` for the given `id`.
pub fn load_spec(id: &str) -> Result<Option<service::ChainSpec>, String> {
	Ok(match ChainSpec::from(id) {
		Some(spec) => Some(spec.load()?),
		None => None,
	})
}