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 node_common::chain_spec::Extensions;
18
use sc_cli::ChainSpec;
19

            
20
/// Specialized `ChainSpec` for the normal parachain runtime.
21
pub type OrchestratorChainSpec = sc_service::GenericChainSpec<Extensions>;
22

            
23
pub struct EmbededParachainOrchestratorCli(pub cumulus_client_cli::RunCmd);
24

            
25
fn load_spec(path: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
26
    Ok(Box::new(OrchestratorChainSpec::from_json_file(
27
        std::path::PathBuf::from(path),
28
    )?))
29
}
30

            
31
impl sc_cli::SubstrateCli for EmbededParachainOrchestratorCli {
32
    fn impl_name() -> String {
33
        "Parachain orchestrator embeded node".into()
34
    }
35

            
36
    fn impl_version() -> String {
37
        env!("SUBSTRATE_CLI_IMPL_VERSION").into()
38
    }
39

            
40
    fn description() -> String {
41
        "Parachain orchestrator embeded node".into()
42
    }
43

            
44
    fn author() -> String {
45
        env!("CARGO_PKG_AUTHORS").into()
46
    }
47

            
48
    fn support_url() -> String {
49
        "https://github.com/moondance-labs/tanssi/issues/new".into()
50
    }
51

            
52
    fn copyright_start_year() -> i32 {
53
        2020
54
    }
55

            
56
    fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
57
        load_spec(id)
58
    }
59
}
60

            
61
impl sc_cli::DefaultConfigurationValues for EmbededParachainOrchestratorCli {
62
    fn p2p_listen_port() -> u16 {
63
        30334
64
    }
65

            
66
    fn rpc_listen_port() -> u16 {
67
        9945
68
    }
69

            
70
    fn prometheus_listen_port() -> u16 {
71
        9616
72
    }
73
}
74

            
75
impl sc_cli::CliConfiguration<Self> for EmbededParachainOrchestratorCli {
76
    fn shared_params(&self) -> &sc_cli::SharedParams {
77
        self.0.base.shared_params()
78
    }
79

            
80
    fn import_params(&self) -> Option<&sc_cli::ImportParams> {
81
        self.0.base.import_params()
82
    }
83

            
84
    fn network_params(&self) -> Option<&sc_cli::NetworkParams> {
85
        self.0.base.network_params()
86
    }
87

            
88
    fn keystore_params(&self) -> Option<&sc_cli::KeystoreParams> {
89
        self.0.base.keystore_params()
90
    }
91

            
92
    fn base_path(&self) -> sc_cli::Result<Option<sc_service::BasePath>> {
93
        self.shared_params().base_path()
94
    }
95

            
96
    fn rpc_addr(
97
        &self,
98
        default_listen_port: u16,
99
    ) -> sc_cli::Result<Option<Vec<sc_cli::RpcEndpoint>>> {
100
        self.0.base.rpc_addr(default_listen_port)
101
    }
102

            
103
    fn prometheus_config(
104
        &self,
105
        default_listen_port: u16,
106
        chain_spec: &Box<dyn ChainSpec>,
107
    ) -> sc_cli::Result<Option<sc_service::config::PrometheusConfig>> {
108
        self.0
109
            .base
110
            .prometheus_config(default_listen_port, chain_spec)
111
    }
112

            
113
    fn init<F>(
114
        &self,
115
        support_url: &String,
116
        impl_version: &String,
117
        logger_hook: F,
118
    ) -> sc_cli::Result<()>
119
    where
120
        F: FnOnce(&mut sc_cli::LoggerBuilder),
121
    {
122
        self.0.base.init(support_url, impl_version, logger_hook)
123
    }
124

            
125
    fn chain_id(&self, is_dev: bool) -> sc_cli::Result<String> {
126
        self.0.base.chain_id(is_dev)
127
    }
128

            
129
    fn role(&self, is_dev: bool) -> sc_cli::Result<sc_service::Role> {
130
        self.0.base.role(is_dev)
131
    }
132

            
133
    fn transaction_pool(
134
        &self,
135
        is_dev: bool,
136
    ) -> sc_cli::Result<sc_service::config::TransactionPoolOptions> {
137
        self.0.base.transaction_pool(is_dev)
138
    }
139

            
140
    fn trie_cache_maximum_size(&self) -> sc_cli::Result<Option<usize>> {
141
        self.0.base.trie_cache_maximum_size()
142
    }
143

            
144
    fn rpc_methods(&self) -> sc_cli::Result<sc_service::config::RpcMethods> {
145
        self.0.base.rpc_methods()
146
    }
147

            
148
    fn rpc_max_connections(&self) -> sc_cli::Result<u32> {
149
        self.0.base.rpc_max_connections()
150
    }
151

            
152
    fn rpc_cors(&self, is_dev: bool) -> sc_cli::Result<Option<Vec<String>>> {
153
        self.0.base.rpc_cors(is_dev)
154
    }
155

            
156
    fn default_heap_pages(&self) -> sc_cli::Result<Option<u64>> {
157
        self.0.base.default_heap_pages()
158
    }
159

            
160
    fn force_authoring(&self) -> sc_cli::Result<bool> {
161
        self.0.base.force_authoring()
162
    }
163

            
164
    fn disable_grandpa(&self) -> sc_cli::Result<bool> {
165
        self.0.base.disable_grandpa()
166
    }
167

            
168
    fn max_runtime_instances(&self) -> sc_cli::Result<Option<usize>> {
169
        self.0.base.max_runtime_instances()
170
    }
171

            
172
    fn announce_block(&self) -> sc_cli::Result<bool> {
173
        self.0.base.announce_block()
174
    }
175

            
176
    fn telemetry_endpoints(
177
        &self,
178
        chain_spec: &Box<dyn ChainSpec>,
179
    ) -> sc_cli::Result<Option<sc_telemetry::TelemetryEndpoints>> {
180
        self.0.base.telemetry_endpoints(chain_spec)
181
    }
182

            
183
    fn node_name(&self) -> sc_cli::Result<String> {
184
        self.0.base.node_name()
185
    }
186
}