referrerpolicy=no-referrer-when-downgrade

polkadot_parachain/chain_spec/
glutton.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Cumulus.
3// SPDX-License-Identifier: Apache-2.0
4
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// 	http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17use cumulus_primitives_core::ParaId;
18use polkadot_omni_node_lib::chain_spec::{Extensions, GenericChainSpec};
19use sc_service::ChainType;
20
21/// Generic Glutton Westend Config for all currently used setups.
22pub fn glutton_westend_config(
23	para_id: ParaId,
24	chain_type: ChainType,
25	relay_chain: &str,
26) -> GenericChainSpec {
27	let mut properties = sc_chain_spec::Properties::new();
28	properties.insert("ss58Format".into(), 42.into());
29
30	GenericChainSpec::builder(
31		glutton_westend_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
32		Extensions::new(relay_chain.into(), para_id.into()),
33	)
34	.with_name(&chain_type_name(para_id, &chain_type))
35	.with_id(&chain_id(para_id, &chain_type))
36	.with_chain_type(chain_type.clone())
37	.with_genesis_config_preset_name(match chain_type {
38		ChainType::Development => sp_genesis_builder::DEV_RUNTIME_PRESET,
39		ChainType::Local => sp_genesis_builder::LOCAL_TESTNET_RUNTIME_PRESET,
40		_ => panic!("chain_type: {chain_type:?} not supported here!"),
41	})
42	// The presets bake in a fixed (fallback) para-id, so patch the requested one on top.
43	.with_genesis_config_patch(serde_json::json!({
44		"parachainInfo": { "parachainId": u32::from(para_id) },
45	}))
46	.build()
47}
48
49/// Generate the name directly from the ChainType
50fn chain_type_name(para_id: ParaId, chain_type: &ChainType) -> String {
51	match chain_type {
52		ChainType::Development => format!("Glutton Development {}", para_id),
53		ChainType::Local => format!("Glutton Local {}", para_id),
54		ChainType::Live => format!("Glutton {}", para_id),
55		ChainType::Custom(name) => name.clone(),
56	}
57}
58
59/// Generate the name directly from the ChainType
60pub fn chain_id(para_id: ParaId, chain_type: &ChainType) -> String {
61	match chain_type {
62		ChainType::Development => format!("glutton-westend-dev-{}", para_id),
63		ChainType::Local => format!("glutton-westend-local-{}", para_id),
64		ChainType::Live => format!("glutton-westend-{}", para_id),
65		ChainType::Custom(_) => format!("glutton-westend-custom-{}", para_id),
66	}
67}