referrerpolicy=no-referrer-when-downgrade

polkadot_parachain/chain_spec/
glutton.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
// Copyright (C) Parity Technologies (UK) Ltd.
// This file is part of Cumulus.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// 	http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use cumulus_primitives_core::ParaId;
use polkadot_omni_node_lib::chain_spec::{Extensions, GenericChainSpec};
use sc_service::ChainType;
use sp_keyring::Sr25519Keyring;

/// Generic Glutton Westend Config for all currently used setups.
pub fn glutton_westend_config(
	para_id: ParaId,
	chain_type: ChainType,
	relay_chain: &str,
) -> GenericChainSpec {
	let mut properties = sc_chain_spec::Properties::new();
	properties.insert("ss58Format".into(), 42.into());

	let authorities = match chain_type {
		ChainType::Development => vec![Sr25519Keyring::Alice.public().into()],
		// Even the westend live setup does currently use Alice & Bob.
		_ => vec![Sr25519Keyring::Alice.public().into(), Sr25519Keyring::Bob.public().into()],
	};

	GenericChainSpec::builder(
		glutton_westend_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
		Extensions { relay_chain: relay_chain.into(), para_id: para_id.into() },
	)
	.with_name(&chain_type_name(para_id, &chain_type))
	.with_id(&chain_id(para_id, &chain_type))
	.with_chain_type(chain_type)
	.with_genesis_config_patch(
		glutton_westend_runtime::genesis_config_presets::glutton_westend_genesis(
			authorities,
			Some(Sr25519Keyring::Alice.to_account_id()),
			para_id,
		),
	)
	.build()
}

/// Generate the name directly from the ChainType
fn chain_type_name(para_id: ParaId, chain_type: &ChainType) -> String {
	match chain_type {
		ChainType::Development => format!("Glutton Development {}", para_id),
		ChainType::Local => format!("Glutton Local {}", para_id),
		ChainType::Live => format!("Glutton {}", para_id),
		ChainType::Custom(name) => name.clone(),
	}
}

/// Generate the name directly from the ChainType
pub fn chain_id(para_id: ParaId, chain_type: &ChainType) -> String {
	match chain_type {
		ChainType::Development => format!("glutton-westend-dev-{}", para_id),
		ChainType::Local => format!("glutton-westend-local-{}", para_id),
		ChainType::Live => format!("glutton-westend-{}", para_id),
		ChainType::Custom(_) => format!("glutton-westend-custom-{}", para_id),
	}
}