/home/runner/work/creditcoin/creditcoin/node/src/cli.rs
Line | Count | Source (jump to first uncovered line) |
1 | | use creditcoin_node_runtime::AccountId; |
2 | | use sc_cli::RunCmd; |
3 | | use sp_core::crypto::{PublicError, Ss58Codec}; |
4 | | use structopt::StructOpt; |
5 | | |
6 | 4 | fn parse_rpc_pair(input: &str) -> Result<(String, String), String> { |
7 | 4 | let (name, uri) = input |
8 | 4 | .split_once('=') |
9 | 4 | .ok_or_else(|| String::from("expected a key-value pair separated by '='")0 )?0 ; |
10 | 8 | let unquote4 = |s: &str| { |
11 | 8 | if s.starts_with('\'') && s.ends_with('\'')4 { |
12 | 4 | Ok(s.trim_matches('\'').into()) |
13 | 4 | } else if s.starts_with('\"') && s.ends_with('\"') { |
14 | 4 | Ok(s.trim_matches('\"').into()) |
15 | 0 | } else if !s.starts_with(&['\'', '\"']) { |
16 | 0 | Ok(s.into()) |
17 | | } else { |
18 | 0 | Err(String::from("invalid quotes in rpc mapping")) |
19 | | } |
20 | | }; |
21 | | |
22 | 4 | let name = unquote(name.trim())?0 ; |
23 | 4 | let uri = unquote(uri.trim())?0 ; |
24 | 4 | Ok((name, uri)) |
25 | 4 | } |
26 | | |
27 | | mod parse_tests { |
28 | 2 | #[test] |
29 | 2 | fn parse_rpc_pair_quoted() { |
30 | 2 | assert_eq!( |
31 | 2 | super::parse_rpc_pair(r#""ethereum"="https://mainnet.infura.io/thingwith=foo""#), |
32 | 2 | Ok(("ethereum".into(), "https://mainnet.infura.io/thingwith=foo".into())) |
33 | 2 | ); |
34 | 2 | assert_eq!( |
35 | 2 | super::parse_rpc_pair(r#"'ethereum'='https://mainnet.infura.io/thingwith=foo'"#), |
36 | 2 | Ok(("ethereum".into(), "https://mainnet.infura.io/thingwith=foo".into())) |
37 | 2 | ) |
38 | 2 | } |
39 | | } |
40 | | |
41 | 0 | #[derive(Debug, StructOpt)] |
42 | | pub struct Cli { |
43 | | #[structopt(subcommand)] |
44 | | pub subcommand: Option<Subcommand>, |
45 | | |
46 | | #[structopt(flatten)] |
47 | | pub run: RunCmd, |
48 | | |
49 | 0 | #[structopt(long)] |
50 | 0 | /// The public key or SS58 Address of the account to receive mining rewards in. |
51 | 0 | pub mining_key: Option<String>, |
52 | | |
53 | 0 | #[structopt(long)] |
54 | 0 | /// The number of mining worker threads to spawn. Defaults to the number of cores if omitted. |
55 | 0 | pub mining_threads: Option<usize>, |
56 | | |
57 | 0 | #[structopt(long, parse(try_from_str = parse_rpc_pair))] |
58 | | /// If the node is an oracle authority, the RPC URL to use for a given external chain. |
59 | 0 | pub rpc_mapping: Option<Vec<(String, String)>>, |
60 | | |
61 | 0 | #[structopt(long)] |
62 | 0 | /// An authority account ID to monitor the nonce of (must be an account actively running as an authority on this node), or |
63 | 0 | /// `auto` to find the authority account automatically. |
64 | 0 | pub monitor_nonce: Option<NonceMonitorTarget>, |
65 | | } |
66 | | |
67 | 0 | #[derive(Debug, Clone)] |
68 | | pub enum NonceMonitorTarget { |
69 | | Auto, |
70 | | Account(AccountId), |
71 | | } |
72 | | |
73 | | impl std::str::FromStr for NonceMonitorTarget { |
74 | | type Err = PublicError; |
75 | | |
76 | 0 | fn from_str(s: &str) -> Result<Self, Self::Err> { |
77 | 0 | Ok(match s { |
78 | 0 | "auto" | "AUTO" | "Auto" => Self::Auto, |
79 | 0 | acct => Self::Account(AccountId::from_string(acct)?), |
80 | | }) |
81 | 0 | } |
82 | | } |
83 | | |
84 | 0 | #[derive(Debug, StructOpt)] |
85 | | pub enum Subcommand { |
86 | | /// Key management cli utilities |
87 | | Key(sc_cli::KeySubcommand), |
88 | | |
89 | | /// Build a chain specification. |
90 | | BuildSpec(sc_cli::BuildSpecCmd), |
91 | | |
92 | | /// Validate blocks. |
93 | | CheckBlock(sc_cli::CheckBlockCmd), |
94 | | |
95 | | /// Export blocks. |
96 | | ExportBlocks(sc_cli::ExportBlocksCmd), |
97 | | |
98 | | /// Export the state of a given block into a chain spec. |
99 | | ExportState(sc_cli::ExportStateCmd), |
100 | | |
101 | | /// Import blocks. |
102 | | ImportBlocks(sc_cli::ImportBlocksCmd), |
103 | | |
104 | | /// Remove the whole chain. |
105 | | PurgeChain(sc_cli::PurgeChainCmd), |
106 | | |
107 | | /// Revert the chain to a previous state. |
108 | | Revert(sc_cli::RevertCmd), |
109 | | |
110 | | /// The custom benchmark subcommand benchmarking runtime pallets. |
111 | | #[structopt(name = "benchmark", about = "Benchmark runtime pallets.")] |
112 | | Benchmark(frame_benchmarking_cli::BenchmarkCmd), |
113 | | } |