diff --git a/src/commands/vault.rs b/src/commands/vault.rs index dca49498943e522f867ada4459bef3f384b0bfa0..c9682d7a69a93258f03e9d0c663c52726370dca5 100644 --- a/src/commands/vault.rs +++ b/src/commands/vault.rs @@ -13,10 +13,10 @@ use std::path::PathBuf; /// define universal dividends subcommands #[derive(Clone, Debug, clap::Parser)] pub enum Subcommand { - /// List available derivations + /// List available SS58 Addresses in the vault #[clap(subcommand)] List(ListChoice), - /// Use specific derivation (changes the config Address) + /// Use specific SS58 Address (changes the config Address) Use { #[clap(flatten)] address_or_vault_name: AddressOrVaultNameGroup, @@ -27,32 +27,35 @@ pub enum Subcommand { #[clap( long_about = "Import key from (substrate)mnemonic or other format with interactive prompt\n\ \n\ - If a (substrate)mnemonic is provided with a derivation path, it will ensure the <Root> derivation\n\ - and associated key exists before creating the new derivation; but please use command \n\ - `vault derivation|derive|deriv` to add a derivation to an existing <Root> derivation instead." + If a (substrate)mnemonic is provided with a derivation path, it will ensure the base <Account>\n\ + and associated SS58 Address exists before creating the derivation; but please use command \n\ + `vault derivation|derive|deriv` to add a derivation to an existing <Account> instead." )] Import { /// Secret key format (substrate, seed, cesium) #[clap(short = 'S', long, required = false, default_value = SecretFormat::Substrate)] secret_format: SecretFormat, }, - /// Add a derivation to an existing <Root> derivation - #[clap(long_about = "Add a derivation to an existing <Root> derivation\n\ + /// Add a derivation to an existing <Account> + #[clap(long_about = "Add a derivation to an existing <Account>\n\ \n\ Only \"substrate\" and \"seed\" format are supported for derivations\n\ - Use command `vault list root` to see available <Root> derivations and their format")] + Use command `vault list account` to see available <Account> and their format")] #[clap(alias = "deriv")] #[clap(alias = "derive")] Derivation { #[clap(flatten)] address_or_vault_name: AddressOrVaultNameGroup, }, - /// Give a meaningful derivation name to a key derivation (can be for a <Root> derivation) + /// Give a meaningful name to an SS58 Address in the vault Rename { /// SS58 Address address: AccountId, }, - /// Remove a derivation (and all linked derivations along with the key if a <Root> derivation is given) + /// Remove an SS58 Address from the vault + #[clap(long_about = "Remove an SS58 Address from the vault\n\ + \n\ + If an <Account> Address is given it will also remove all linked derivations")] Remove { #[clap(flatten)] address_or_vault_name: AddressOrVaultNameGroup, @@ -67,16 +70,16 @@ pub enum Subcommand { #[derive(Clone, Default, Debug, clap::Parser)] pub enum ListChoice { - /// List all <Root> derivations and their linked derivations in the vault + /// List all <Account> and their linked derivations SS58 Addresses in the vault #[default] All, - /// List all derivations linked to the one selected + /// List <Account> and derivations SS58 Addresses linked to the selected one For { #[clap(flatten)] address_or_vault_name: AddressOrVaultNameGroup, }, - /// List only <Root> derivations in the vault - Root, + /// List all <Account> SS58 Addresses in the vault + Account, } pub struct VaultDataToImport { @@ -129,10 +132,10 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE ) .await?; - println!("available derivations:"); + println!("available SS58 Addresses:"); println!("{table}"); } - ListChoice::Root => { + ListChoice::Account => { let derivations = vault_derivation::list_all_root_derivations_in_order( data.connection.as_ref().unwrap(), ) @@ -144,18 +147,18 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE ) .await?; - println!("available <Root> derivations:"); + println!("available <Account> SS58 Addresses:"); println!("{table}"); } ListChoice::For { address_or_vault_name, } => { - let root_derivation = + let selected_derivation = retrieve_vault_derivation(&data, address_or_vault_name).await?; let linked_derivations = vault_derivation::fetch_all_linked_derivations_in_order( data.connection.as_ref().unwrap(), - &root_derivation.root_address, + &selected_derivation.root_address, ) .await?; @@ -165,7 +168,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE ) .await?; - println!("available derivations linked to {root_derivation}:"); + println!("available SS58 Addresses linked to {selected_derivation}:"); println!("{table}"); } }, @@ -280,7 +283,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE Into::<&str>::into(SecretFormat::Substrate), Into::<&str>::into(SecretFormat::Seed) ); - println!("Use command `vault list root` to see available <Root> derivations and their format"); + println!("Use command `vault list root` to see available <Account> and their format"); return Ok(()); } @@ -537,9 +540,9 @@ where { let mut table = Table::new(); table.load_preset(comfy_table::presets::UTF8_BORDERS_ONLY); - table.set_header(vec!["SS58 Address", "Format", "Path", "Derivation Name"]); + table.set_header(vec!["SS58 Address", "Format", "Account/Path", "Name"]); let empty_string = "".to_string(); - let root_path = "<Root>".to_string(); + let root_path = "<Account>".to_string(); let mut current_root_address = "".to_string(); let mut current_root_name: Option<String> = None; @@ -560,7 +563,7 @@ where .one(db) .await? .ok_or(GcliError::Input(format!( - "No vault account found with address:'{current_root_address}'" + "No vault <Account> found with address:'{current_root_address}'" )))?; current_vault_format = match vault_account.crypto_type { @@ -643,7 +646,7 @@ pub async fn retrieve_vault_derivation<T: AddressOrVaultName>( .await?; let derivation = derivation.ok_or(GcliError::Input(format!( - "No vault derivation found with name:'{name}'" + "No vault SS58 Address found with name:'{name}'" )))?; match derivation_path_opt { @@ -658,7 +661,7 @@ pub async fn retrieve_vault_derivation<T: AddressOrVaultName>( .await?; sub_derivation.ok_or(GcliError::Input(format!( - "No vault derivation found with root name:'{name}' and path:'{path}'" + "No vault derivation found with <Account> name:'{name}' and path:'{path}'" )))? } } @@ -668,7 +671,7 @@ pub async fn retrieve_vault_derivation<T: AddressOrVaultName>( .await?; derivation.ok_or(GcliError::Input(format!( - "No vault derivation found with Address:'{address}'" + "No vault entry found with Address:'{address}'" )))? } else { //Should never happen since clap enforces exactly one of the 2 options diff --git a/src/conf.rs b/src/conf.rs index 2310958e1a121fc6cee68b62de76332b99036212..389dbd579367fc99e7f04af3e5b10a6ebfc16aea 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -91,7 +91,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE ) .await? { - println!("(Vault derivation: {})", derivation); + println!("(Vault: {})", derivation); } } } diff --git a/src/entities/vault_derivation.rs b/src/entities/vault_derivation.rs index 16beab68e490be8f6b8697274ff5b32a8a37801d..5e40fc337085ae53177cb6978d5535d7d51dff23 100644 --- a/src/entities/vault_derivation.rs +++ b/src/entities/vault_derivation.rs @@ -28,11 +28,19 @@ pub struct Model { impl Display for Model { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "[address:\"{}\", name:{:?}, path:{:?}, root_address:\"{}\"]", - self.address, self.name, self.path, self.root_address - ) + if self.path.is_none() { + write!( + f, + "Account[address:\"{}\", name:{:?}]", + self.address, self.name + ) + } else { + write!( + f, + "Derivation[address:\"{}\", name:{:?}, path:{:?}, account_address:\"{}\"]", + self.address, self.name, self.path, self.root_address + ) + } } } diff --git a/src/main.rs b/src/main.rs index 75ee885631daa149b0c1848a7e203f1447b840fa..2e40ad54e238a0f58de57a10ffd766dda5dabdae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,8 +81,8 @@ pub struct AddressOrVaultNameGroupOptional { /// SS58 Address #[clap(short)] address: Option<AccountId>, - /// Derivation name for a SS58 Address (can be a <Root> derivation name) - #[clap(short = 'd')] + /// Name of an SS58 Address in the vault + #[clap(short = 'v')] name: Option<String>, } @@ -101,8 +101,8 @@ pub struct AddressOrVaultNameGroup { /// SS58 Address #[clap(short)] address: Option<AccountId>, - /// Derivation name for a SS58 Address (can be a <Root> derivation name) - #[clap(short = 'd')] + /// Name of an SS58 Address in the vault + #[clap(short = 'v')] name: Option<String>, }