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
    crate::chain_spec::Extensions,
19
    cumulus_primitives_core::ParaId,
20
    flashbox_runtime::genesis_config_presets::{development, local},
21
    sc_service::ChainType,
22
};
23

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

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

            
40
    // we do conversion from chain_spec file to the string content here because
41
    // local accepts contents vector
42
    let container_chains_spec_contents: Vec<_> = container_chains
43
        .iter()
44
        .map(|path| {
45
            std::fs::read_to_string(path)
46
                .map_err(|_e| format!("ChainSpec for container chain not found at {:?}", path))
47
                .unwrap()
48
        })
49
        .collect();
50

            
51
    ChainSpec::builder(
52
        flashbox_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
53
        Extensions {
54
            relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
55
            para_id: para_id.into(),
56
        },
57
    )
58
    .with_name("Flashbox Development Testnet")
59
    .with_id("flashbox_dev")
60
    .with_chain_type(ChainType::Development)
61
    .with_genesis_config(development(
62
        para_id,
63
        container_chains_spec_contents,
64
        mock_container_chains,
65
        invulnerables,
66
    ))
67
    .with_properties(properties)
68
    .build()
69
}
70

            
71
10
pub fn local_flashbox_config(
72
10
    para_id: ParaId,
73
10
    container_chains: Vec<String>,
74
10
    mock_container_chains: Vec<ParaId>,
75
10
    invulnerables: Vec<String>,
76
10
) -> ChainSpec {
77
    // Give your base currency a unit name and decimal places
78
10
    let mut properties = sc_chain_spec::Properties::new();
79
10
    properties.insert("tokenSymbol".into(), "FLASH".into());
80
10
    properties.insert("tokenDecimals".into(), 12.into());
81
10
    properties.insert("ss58Format".into(), 42.into());
82
10
    properties.insert("isEthereum".into(), false.into());
83

            
84
    // we do conversion from chain_spec file to the string content here because
85
    // local accepts contents vector
86
10
    let container_chains_spec_contents: Vec<_> = container_chains
87
10
        .iter()
88
10
        .map(|path| {
89
            std::fs::read_to_string(path)
90
                .map_err(|_e| format!("ChainSpec for container chain not found at {:?}", path))
91
                .unwrap()
92
        })
93
10
        .collect();
94

            
95
10
    ChainSpec::builder(
96
10
        flashbox_runtime::WASM_BINARY.expect("WASM binary was not built, please build it!"),
97
10
        Extensions {
98
10
            relay_chain: "rococo-local".into(), // You MUST set this to the correct network!
99
10
            para_id: para_id.into(),
100
10
        },
101
    )
102
10
    .with_name("Flashbox Local Testnet")
103
10
    .with_id("flashbox_local")
104
10
    .with_chain_type(ChainType::Local)
105
10
    .with_genesis_config(local(
106
10
        para_id,
107
10
        container_chains_spec_contents,
108
10
        mock_container_chains,
109
10
        invulnerables,
110
    ))
111
10
    .with_properties(properties)
112
10
    .with_protocol_id("orchestrator")
113
10
    .build()
114
10
}