Skip to content
Snippets Groups Projects
Commit 90f5f2aa authored by Nicolas80's avatar Nicolas80
Browse files

* Renaming to refer to "<Account>" instead of "<Root> derivation" to avoid confusion.

* Simply using "name" for the name given to an SS58 Address in the vault
parent b3c0e13c
Branches
Tags
1 merge request!41Adding db persistence for all SecretFormat of vault keys as well as supporting derivations
...@@ -13,10 +13,10 @@ use std::path::PathBuf; ...@@ -13,10 +13,10 @@ use std::path::PathBuf;
/// define universal dividends subcommands /// define universal dividends subcommands
#[derive(Clone, Debug, clap::Parser)] #[derive(Clone, Debug, clap::Parser)]
pub enum Subcommand { pub enum Subcommand {
/// List available derivations /// List available SS58 Addresses in the vault
#[clap(subcommand)] #[clap(subcommand)]
List(ListChoice), List(ListChoice),
/// Use specific derivation (changes the config Address) /// Use specific SS58 Address (changes the config Address)
Use { Use {
#[clap(flatten)] #[clap(flatten)]
address_or_vault_name: AddressOrVaultNameGroup, address_or_vault_name: AddressOrVaultNameGroup,
...@@ -27,32 +27,35 @@ pub enum Subcommand { ...@@ -27,32 +27,35 @@ pub enum Subcommand {
#[clap( #[clap(
long_about = "Import key from (substrate)mnemonic or other format with interactive prompt\n\ long_about = "Import key from (substrate)mnemonic or other format with interactive prompt\n\
\n\ \n\
If a (substrate)mnemonic is provided with a derivation path, it will ensure the <Root> derivation\n\ If a (substrate)mnemonic is provided with a derivation path, it will ensure the base <Account>\n\
and associated key exists before creating the new derivation; but please use command \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 <Root> derivation instead." `vault derivation|derive|deriv` to add a derivation to an existing <Account> instead."
)] )]
Import { Import {
/// Secret key format (substrate, seed, cesium) /// Secret key format (substrate, seed, cesium)
#[clap(short = 'S', long, required = false, default_value = SecretFormat::Substrate)] #[clap(short = 'S', long, required = false, default_value = SecretFormat::Substrate)]
secret_format: SecretFormat, secret_format: SecretFormat,
}, },
/// Add a derivation to an existing <Root> derivation /// Add a derivation to an existing <Account>
#[clap(long_about = "Add a derivation to an existing <Root> derivation\n\ #[clap(long_about = "Add a derivation to an existing <Account>\n\
\n\ \n\
Only \"substrate\" and \"seed\" format are supported for derivations\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 = "deriv")]
#[clap(alias = "derive")] #[clap(alias = "derive")]
Derivation { Derivation {
#[clap(flatten)] #[clap(flatten)]
address_or_vault_name: AddressOrVaultNameGroup, 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 { Rename {
/// SS58 Address /// SS58 Address
address: AccountId, 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 { Remove {
#[clap(flatten)] #[clap(flatten)]
address_or_vault_name: AddressOrVaultNameGroup, address_or_vault_name: AddressOrVaultNameGroup,
...@@ -67,16 +70,16 @@ pub enum Subcommand { ...@@ -67,16 +70,16 @@ pub enum Subcommand {
#[derive(Clone, Default, Debug, clap::Parser)] #[derive(Clone, Default, Debug, clap::Parser)]
pub enum ListChoice { 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] #[default]
All, All,
/// List all derivations linked to the one selected /// List <Account> and derivations SS58 Addresses linked to the selected one
For { For {
#[clap(flatten)] #[clap(flatten)]
address_or_vault_name: AddressOrVaultNameGroup, address_or_vault_name: AddressOrVaultNameGroup,
}, },
/// List only <Root> derivations in the vault /// List all <Account> SS58 Addresses in the vault
Root, Account,
} }
pub struct VaultDataToImport { pub struct VaultDataToImport {
...@@ -129,10 +132,10 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE ...@@ -129,10 +132,10 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
) )
.await?; .await?;
println!("available derivations:"); println!("available SS58 Addresses:");
println!("{table}"); println!("{table}");
} }
ListChoice::Root => { ListChoice::Account => {
let derivations = vault_derivation::list_all_root_derivations_in_order( let derivations = vault_derivation::list_all_root_derivations_in_order(
data.connection.as_ref().unwrap(), data.connection.as_ref().unwrap(),
) )
...@@ -144,18 +147,18 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE ...@@ -144,18 +147,18 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
) )
.await?; .await?;
println!("available <Root> derivations:"); println!("available <Account> SS58 Addresses:");
println!("{table}"); println!("{table}");
} }
ListChoice::For { ListChoice::For {
address_or_vault_name, address_or_vault_name,
} => { } => {
let root_derivation = let selected_derivation =
retrieve_vault_derivation(&data, address_or_vault_name).await?; retrieve_vault_derivation(&data, address_or_vault_name).await?;
let linked_derivations = vault_derivation::fetch_all_linked_derivations_in_order( let linked_derivations = vault_derivation::fetch_all_linked_derivations_in_order(
data.connection.as_ref().unwrap(), data.connection.as_ref().unwrap(),
&root_derivation.root_address, &selected_derivation.root_address,
) )
.await?; .await?;
...@@ -165,7 +168,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE ...@@ -165,7 +168,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
) )
.await?; .await?;
println!("available derivations linked to {root_derivation}:"); println!("available SS58 Addresses linked to {selected_derivation}:");
println!("{table}"); println!("{table}");
} }
}, },
...@@ -280,7 +283,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE ...@@ -280,7 +283,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
Into::<&str>::into(SecretFormat::Substrate), Into::<&str>::into(SecretFormat::Substrate),
Into::<&str>::into(SecretFormat::Seed) 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(()); return Ok(());
} }
...@@ -537,9 +540,9 @@ where ...@@ -537,9 +540,9 @@ where
{ {
let mut table = Table::new(); let mut table = Table::new();
table.load_preset(comfy_table::presets::UTF8_BORDERS_ONLY); 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 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_address = "".to_string();
let mut current_root_name: Option<String> = None; let mut current_root_name: Option<String> = None;
...@@ -560,7 +563,7 @@ where ...@@ -560,7 +563,7 @@ where
.one(db) .one(db)
.await? .await?
.ok_or(GcliError::Input(format!( .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 { current_vault_format = match vault_account.crypto_type {
...@@ -643,7 +646,7 @@ pub async fn retrieve_vault_derivation<T: AddressOrVaultName>( ...@@ -643,7 +646,7 @@ pub async fn retrieve_vault_derivation<T: AddressOrVaultName>(
.await?; .await?;
let derivation = derivation.ok_or(GcliError::Input(format!( 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 { match derivation_path_opt {
...@@ -658,7 +661,7 @@ pub async fn retrieve_vault_derivation<T: AddressOrVaultName>( ...@@ -658,7 +661,7 @@ pub async fn retrieve_vault_derivation<T: AddressOrVaultName>(
.await?; .await?;
sub_derivation.ok_or(GcliError::Input(format!( 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>( ...@@ -668,7 +671,7 @@ pub async fn retrieve_vault_derivation<T: AddressOrVaultName>(
.await?; .await?;
derivation.ok_or(GcliError::Input(format!( derivation.ok_or(GcliError::Input(format!(
"No vault derivation found with Address:'{address}'" "No vault entry found with Address:'{address}'"
)))? )))?
} else { } else {
//Should never happen since clap enforces exactly one of the 2 options //Should never happen since clap enforces exactly one of the 2 options
......
...@@ -91,7 +91,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE ...@@ -91,7 +91,7 @@ pub async fn handle_command(data: Data, command: Subcommand) -> Result<(), GcliE
) )
.await? .await?
{ {
println!("(Vault derivation: {})", derivation); println!("(Vault: {})", derivation);
} }
} }
} }
......
...@@ -28,13 +28,21 @@ pub struct Model { ...@@ -28,13 +28,21 @@ pub struct Model {
impl Display for Model { impl Display for Model {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.path.is_none() {
write!( write!(
f, f,
"[address:\"{}\", name:{:?}, path:{:?}, root_address:\"{}\"]", "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 self.address, self.name, self.path, self.root_address
) )
} }
} }
}
#[derive(Copy, Clone, Debug, EnumIter)] #[derive(Copy, Clone, Debug, EnumIter)]
pub enum Relation { pub enum Relation {
......
...@@ -81,8 +81,8 @@ pub struct AddressOrVaultNameGroupOptional { ...@@ -81,8 +81,8 @@ pub struct AddressOrVaultNameGroupOptional {
/// SS58 Address /// SS58 Address
#[clap(short)] #[clap(short)]
address: Option<AccountId>, address: Option<AccountId>,
/// Derivation name for a SS58 Address (can be a <Root> derivation name) /// Name of an SS58 Address in the vault
#[clap(short = 'd')] #[clap(short = 'v')]
name: Option<String>, name: Option<String>,
} }
...@@ -101,8 +101,8 @@ pub struct AddressOrVaultNameGroup { ...@@ -101,8 +101,8 @@ pub struct AddressOrVaultNameGroup {
/// SS58 Address /// SS58 Address
#[clap(short)] #[clap(short)]
address: Option<AccountId>, address: Option<AccountId>,
/// Derivation name for a SS58 Address (can be a <Root> derivation name) /// Name of an SS58 Address in the vault
#[clap(short = 'd')] #[clap(short = 'v')]
name: Option<String>, name: Option<String>,
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment