diff --git a/crates/iota/src/key_identity.rs b/crates/iota/src/key_identity.rs index eca7cff6d3f..9f3a8c0f6d6 100644 --- a/crates/iota/src/key_identity.rs +++ b/crates/iota/src/key_identity.rs @@ -62,3 +62,13 @@ pub fn get_identity_address_from_keystore( KeyIdentity::Alias(x) => Ok(*keystore.get_address_by_alias(x)?), } } + +pub fn get_identity_alias_from_keystore( + input: KeyIdentity, + keystore: &Keystore, +) -> Result { + match input { + KeyIdentity::Address(x) => Ok(keystore.get_alias_by_address(&x)?), + KeyIdentity::Alias(x) => Ok(x), + } +} diff --git a/crates/iota/src/keytool.rs b/crates/iota/src/keytool.rs index ca05ccd35f8..a8654f370de 100644 --- a/crates/iota/src/keytool.rs +++ b/crates/iota/src/keytool.rs @@ -58,7 +58,9 @@ use tabled::{ }; use tracing::info; -use crate::key_identity::{KeyIdentity, get_identity_address_from_keystore}; +use crate::key_identity::{ + KeyIdentity, get_identity_address_from_keystore, get_identity_alias_from_keystore, +}; #[derive(Subcommand)] #[command(rename_all = "kebab-case")] @@ -208,7 +210,8 @@ pub enum KeyToolCommand { /// Update an old alias to a new one. /// If a new alias is not provided, a random one will be generated. UpdateAlias { - old_alias: String, + /// An IOTA address or its alias. + key_identity: KeyIdentity, /// The alias must start with a letter and can contain only letters, /// digits, dots, hyphens (-), or underscores (_). new_alias: Option, @@ -800,9 +803,10 @@ impl KeyToolCommand { }) } KeyToolCommand::UpdateAlias { - old_alias, + key_identity, new_alias, } => { + let old_alias = get_identity_alias_from_keystore(key_identity, keystore)?; let new_alias = keystore.update_alias(&old_alias, new_alias.as_deref())?; CommandOutput::UpdateAlias(AliasUpdate { old_alias,