1
// Copyright (C) Moondance Labs Ltd.
2
// This file is part of Tanssi.
3

            
4
// Tanssi is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Tanssi is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
// You should have received a copy of the GNU General Public License
15
// along with Tanssi.  If not, see <http://www.gnu.org/licenses/>.
16

            
17
use {
18
    container_chain_template_simple_runtime::genesis_config_presets::{development, local},
19
    cumulus_primitives_core::ParaId,
20
    node_common::chain_spec::Extensions,
21
    sc_network::config::MultiaddrWithPeerId,
22
    sc_service::ChainType,
23
    sp_keyring::Sr25519Keyring,
24
};
25

            
26
/// Specialized `ChainSpec` for the normal parachain runtime.
27
pub type ChainSpec = sc_service::GenericChainSpec<Extensions>;
28

            
29
2
pub fn development_config(para_id: ParaId, boot_nodes: Vec<String>) -> ChainSpec {
30
    // Give your base currency a unit name and decimal places
31
2
    let mut properties = sc_chain_spec::Properties::new();
32
2
    properties.insert("tokenSymbol".into(), "UNIT".into());
33
2
    properties.insert("tokenDecimals".into(), 12.into());
34
2
    properties.insert("ss58Format".into(), 42.into());
35
2
    properties.insert("isEthereum".into(), false.into());
36

            
37
2
    let mut default_funded_accounts =
38
2
        container_chain_template_simple_runtime::genesis_config_presets::pre_funded_accounts();
39
2
    default_funded_accounts.sort();
40
2
    default_funded_accounts.dedup();
41
2
    let boot_nodes: Vec<MultiaddrWithPeerId> = boot_nodes
42
2
        .into_iter()
43
2
        .map(|x| {
44
            x.parse::<MultiaddrWithPeerId>()
45
                .unwrap_or_else(|e| panic!("invalid bootnode address format {:?}: {:?}", x, e))
46
        })
47
2
        .collect();
48

            
49
2
    ChainSpec::builder(
50
2
        container_chain_template_simple_runtime::WASM_BINARY
51
2
            .expect("WASM binary was not built, please build it!"),
52
2
        Extensions {
53
2
            relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
54
2
            para_id: para_id.into(),
55
2
        },
56
    )
57
2
    .with_name("Development")
58
2
    .with_id("dev")
59
2
    .with_chain_type(ChainType::Development)
60
2
    .with_genesis_config(development(
61
2
        default_funded_accounts.clone(),
62
2
        para_id,
63
2
        Sr25519Keyring::Alice.to_account_id(),
64
    ))
65
2
    .with_properties(properties)
66
2
    .with_boot_nodes(boot_nodes)
67
2
    .build()
68
2
}
69

            
70
pub fn local_testnet_config(para_id: ParaId, boot_nodes: Vec<String>) -> ChainSpec {
71
    // Give your base currency a unit name and decimal places
72
    let mut properties = sc_chain_spec::Properties::new();
73
    properties.insert("tokenSymbol".into(), "UNIT".into());
74
    properties.insert("tokenDecimals".into(), 12.into());
75
    properties.insert("ss58Format".into(), 42.into());
76
    properties.insert("isEthereum".into(), false.into());
77
    let protocol_id = format!("container-chain-{}", para_id);
78

            
79
    let mut default_funded_accounts =
80
        container_chain_template_simple_runtime::genesis_config_presets::pre_funded_accounts();
81
    default_funded_accounts.sort();
82
    default_funded_accounts.dedup();
83
    let boot_nodes: Vec<MultiaddrWithPeerId> = boot_nodes
84
        .into_iter()
85
        .map(|x| {
86
            x.parse::<MultiaddrWithPeerId>()
87
                .unwrap_or_else(|e| panic!("invalid bootnode address format {:?}: {:?}", x, e))
88
        })
89
        .collect();
90

            
91
    ChainSpec::builder(
92
        container_chain_template_simple_runtime::WASM_BINARY
93
            .expect("WASM binary was not built, please build it!"),
94
        Extensions {
95
            relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
96
            para_id: para_id.into(),
97
        },
98
    )
99
    .with_name(&format!("Simple Container {}", para_id))
100
    .with_id(&format!("simple_container_{}", para_id))
101
    .with_chain_type(ChainType::Local)
102
    .with_genesis_config(local(
103
        default_funded_accounts.clone(),
104
        para_id,
105
        Sr25519Keyring::Alice.to_account_id(),
106
    ))
107
    .with_properties(properties)
108
    .with_protocol_id(&protocol_id)
109
    .with_boot_nodes(boot_nodes)
110
    .build()
111
}