-
Notifications
You must be signed in to change notification settings - Fork 40
/
cli_parachain.rs
259 lines (206 loc) · 7.25 KB
/
cli_parachain.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
use sc_cli::{
self, ChainSpec, ImportParams, KeystoreParams, NetworkParams, RuntimeVersion, SharedParams,
SubstrateCli,
};
use sc_service::config::{BasePath, PrometheusConfig};
use std::{net::SocketAddr, path::PathBuf};
use structopt::StructOpt;
const BATTERY_STATION_RELAY_ID: &str = "battery_station_relay_v3";
#[derive(Debug)]
pub struct RelayChainCli {
/// The actual relay chain cli object.
pub base: polkadot_cli::RunCmd,
/// The base path that should be used by the relay chain.
pub base_path: Option<PathBuf>,
/// Optional chain id that should be passed to the relay chain.
pub chain_id: Option<String>,
}
impl RelayChainCli {
/// Parse the relay chain CLI parameters using the parachain `Configuration`.
pub fn new<'a>(
para_config: &sc_service::Configuration,
relay_chain_args: impl Iterator<Item = &'a String>,
) -> Self {
let extension = crate::chain_spec::Extensions::try_get(&*para_config.chain_spec);
let chain_id = extension.map(|e| e.relay_chain.clone());
let base_path = para_config
.base_path
.as_ref()
.map(|x| x.path().join(chain_id.clone().unwrap_or_else(|| "polkadot".into())));
Self { base_path, chain_id, base: polkadot_cli::RunCmd::from_iter(relay_chain_args) }
}
}
impl sc_cli::CliConfiguration<Self> for RelayChainCli {
fn announce_block(&self) -> sc_cli::Result<bool> {
self.base.base.announce_block()
}
fn base_path(&self) -> sc_cli::Result<Option<BasePath>> {
Ok(self.shared_params().base_path().or_else(|| self.base_path.clone().map(Into::into)))
}
fn chain_id(&self, is_dev: bool) -> sc_cli::Result<String> {
let chain_id = self.base.base.chain_id(is_dev)?;
Ok(if chain_id.is_empty() { self.chain_id.clone().unwrap_or_default() } else { chain_id })
}
fn default_heap_pages(&self) -> sc_cli::Result<Option<u64>> {
self.base.base.default_heap_pages()
}
fn disable_grandpa(&self) -> sc_cli::Result<bool> {
self.base.base.disable_grandpa()
}
fn force_authoring(&self) -> sc_cli::Result<bool> {
self.base.base.force_authoring()
}
fn import_params(&self) -> Option<&ImportParams> {
self.base.base.import_params()
}
fn init<C>(&self) -> sc_cli::Result<()>
where
C: SubstrateCli,
{
unreachable!("PolkadotCli is never initialized; qed");
}
fn keystore_params(&self) -> Option<&KeystoreParams> {
self.base.base.keystore_params()
}
fn max_runtime_instances(&self) -> sc_cli::Result<Option<usize>> {
self.base.base.max_runtime_instances()
}
fn network_params(&self) -> Option<&NetworkParams> {
self.base.base.network_params()
}
fn prometheus_config(
&self,
default_listen_port: u16,
) -> sc_cli::Result<Option<PrometheusConfig>> {
self.base.base.prometheus_config(default_listen_port)
}
fn role(&self, is_dev: bool) -> sc_cli::Result<sc_service::Role> {
self.base.base.role(is_dev)
}
fn rpc_cors(&self, is_dev: bool) -> sc_cli::Result<Option<Vec<String>>> {
self.base.base.rpc_cors(is_dev)
}
fn rpc_http(&self, default_listen_port: u16) -> sc_cli::Result<Option<SocketAddr>> {
self.base.base.rpc_http(default_listen_port)
}
fn rpc_ipc(&self) -> sc_cli::Result<Option<String>> {
self.base.base.rpc_ipc()
}
fn rpc_methods(&self) -> sc_cli::Result<sc_service::config::RpcMethods> {
self.base.base.rpc_methods()
}
fn rpc_ws(&self, default_listen_port: u16) -> sc_cli::Result<Option<SocketAddr>> {
self.base.base.rpc_ws(default_listen_port)
}
fn rpc_ws_max_connections(&self) -> sc_cli::Result<Option<usize>> {
self.base.base.rpc_ws_max_connections()
}
fn shared_params(&self) -> &SharedParams {
self.base.base.shared_params()
}
fn state_cache_child_ratio(&self) -> sc_cli::Result<Option<usize>> {
self.base.base.state_cache_child_ratio()
}
fn telemetry_external_transport(
&self,
) -> sc_cli::Result<Option<sc_service::config::ExtTransport>> {
self.base.base.telemetry_external_transport()
}
fn transaction_pool(&self) -> sc_cli::Result<sc_service::config::TransactionPoolOptions> {
self.base.base.transaction_pool()
}
}
impl sc_cli::DefaultConfigurationValues for RelayChainCli {
fn p2p_listen_port() -> u16 {
30334
}
fn prometheus_listen_port() -> u16 {
9616
}
fn rpc_http_listen_port() -> u16 {
9934
}
fn rpc_ws_listen_port() -> u16 {
9945
}
}
impl sc_cli::SubstrateCli for RelayChainCli {
fn author() -> String {
env!("CARGO_PKG_AUTHORS").into()
}
fn copyright_start_year() -> i32 {
crate::cli::COPYRIGHT_START_YEAR
}
fn description() -> String {
env!("CARGO_PKG_DESCRIPTION").into()
}
fn impl_name() -> String {
crate::cli::IMPL_NAME.into()
}
fn impl_version() -> String {
env!("SUBSTRATE_CLI_IMPL_VERSION").into()
}
fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
if id == BATTERY_STATION_RELAY_ID {
Ok(Box::new(polkadot_service::RococoChainSpec::from_json_bytes(
&include_bytes!("../../res/battery_station_relay.json")[..],
)?))
} else {
<polkadot_cli::Cli as SubstrateCli>::from_iter(
[RelayChainCli::executable_name()].iter(),
)
.load_spec(id)
}
}
fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
polkadot_cli::Cli::native_runtime_version(chain_spec)
}
fn support_url() -> String {
crate::cli::SUPPORT_URL.into()
}
}
/// Command for exporting the genesis state of the parachain
#[derive(Debug, StructOpt)]
pub struct ExportGenesisStateCommand {
/// Output file name or stdout if unspecified.
#[structopt(parse(from_os_str))]
pub output: Option<PathBuf>,
/// Id of the parachain this state is for.
// Sync with crate::DEFAULT_PARACHAIN_ID
#[structopt(long)]
pub parachain_id: u32,
/// Write output in binary. Default is to write in hex.
#[structopt(short, long)]
pub raw: bool,
/// The name of the chain for that the genesis state should be exported.
#[structopt(long)]
pub chain: Option<String>,
}
/// Command for exporting the genesis wasm file.
#[derive(Debug, structopt::StructOpt)]
pub struct ExportGenesisWasmCommand {
/// Output file name or stdout if unspecified.
#[structopt(parse(from_os_str))]
pub output: Option<PathBuf>,
/// Write output in binary. Default is to write in hex.
#[structopt(short, long)]
pub raw: bool,
/// The name of the chain for that the genesis wasm file should be exported.
#[structopt(long)]
pub chain: Option<String>,
}
#[derive(Debug, structopt::StructOpt)]
pub struct RunCmd {
#[structopt(flatten)]
pub base: sc_cli::RunCmd,
/// Id of the parachain this collator collates for.
#[structopt(long)]
pub parachain_id: u32,
}
impl core::ops::Deref for RunCmd {
type Target = sc_cli::RunCmd;
#[inline]
fn deref(&self) -> &Self::Target {
&self.base
}
}