utility_cli_rs/js_command_match/
generate_key.rs1#[derive(Debug, Clone, clap::Parser)]
2pub struct GenerateKeyArgs {
4 account_id: Option<String>,
5 #[clap(long, aliases = ["seed_phrase", "seedPhrase"], default_value = None, conflicts_with = "use_ledger_key")]
6 seed_phrase: Option<String>,
7 #[clap(long, aliases = ["use_ledger_key", "useLedgerKey"], default_missing_value = Some("44'/397'/0'/0'/1'"), num_args=0..=1)]
8 use_ledger_key: Option<String>,
9 #[clap(allow_hyphen_values = true, num_args = 0..)]
10 _unknown_args: Vec<String>,
11}
12
13impl GenerateKeyArgs {
14 pub fn to_cli_args(&self, network_config: String) -> color_eyre::eyre::Result<Vec<String>> {
15 let config = crate::common::get_config_toml()?;
16 let mut generation_method = "use-auto-generation".to_string();
17 if self.use_ledger_key.is_some() {
18 generation_method = "use-ledger".to_string();
19 }
20 if let Some(account_id) = self.account_id.as_deref() {
21 let folder_path = shellexpand::tilde(
22 format!(
23 "{}/{}/{}",
24 config.credentials_home_dir.to_string_lossy(),
25 network_config,
26 account_id
27 )
28 .as_str(),
29 )
30 .as_ref()
31 .parse()?;
32 if let Some(seed_phrase) = self.seed_phrase.as_deref() {
33 return Ok(vec![
34 "account".to_owned(),
35 "create-account".to_owned(),
36 "fund-later".to_owned(),
37 "use-seed-phrase".to_owned(),
38 seed_phrase.to_owned(),
39 "--seed-phrase-hd-path".to_owned(),
40 "m/44'/397'/0'".to_owned(),
41 "save-to-folder".to_owned(),
42 folder_path,
43 ]);
44 }
45 return Ok(vec![
46 "account".to_owned(),
47 "create-account".to_owned(),
48 "fund-later".to_owned(),
49 generation_method,
50 "save-to-folder".to_owned(),
51 folder_path,
52 ]);
53 }
54 let folder_path = shellexpand::tilde(
55 format!("{}/implicit", config.credentials_home_dir.to_string_lossy()).as_str(),
56 )
57 .as_ref()
58 .parse()?;
59 if let Some(seed_phrase) = self.seed_phrase.as_deref() {
60 return Ok(vec![
61 "account".to_owned(),
62 "create-account".to_owned(),
63 "fund-later".to_owned(),
64 "use-seed-phrase".to_owned(),
65 seed_phrase.to_owned(),
66 "--seed-phrase-hd-path".to_owned(),
67 "m/44'/397'/0'".to_owned(),
68 "save-to-folder".to_owned(),
69 folder_path,
70 ]);
71 }
72 Ok(vec![
73 "account".to_owned(),
74 "create-account".to_owned(),
75 "fund-later".to_owned(),
76 generation_method,
77 "save-to-folder".to_owned(),
78 folder_path,
79 ])
80 }
81}