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_frontier_runtime::{
19
        genesis_config_presets::{development, local},
20
        AccountId,
21
    },
22
    cumulus_primitives_core::ParaId,
23
    hex_literal::hex,
24
    node_common::chain_spec::Extensions,
25
    sc_network::config::MultiaddrWithPeerId,
26
    sc_service::ChainType,
27
};
28

            
29
/// Specialized `ChainSpec` for the normal parachain runtime.
30
pub type ChainSpec = sc_service::GenericChainSpec<Extensions>;
31

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

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

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

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

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

            
94
    ChainSpec::builder(
95
        container_chain_template_frontier_runtime::WASM_BINARY
96
            .expect("WASM binary was not built, please build it!"),
97
        Extensions {
98
            relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
99
            para_id: para_id.into(),
100
        },
101
    )
102
    .with_name(&format!("Frontier Container {}", para_id))
103
    .with_id(&format!("frontier_container_{}", para_id))
104
    .with_chain_type(ChainType::Local)
105
    .with_genesis_config(local(
106
        default_funded_accounts.clone(),
107
        para_id,
108
        AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")), // Alith
109
    ))
110
    .with_properties(properties)
111
    .with_protocol_id(&protocol_id)
112
    .with_boot_nodes(boot_nodes)
113
    .build()
114
}