Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(iota): KeyToolCommand::UpdateAlias accepts a key identity instead of an alias #5040

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions crates/iota/src/key_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Error> {
match input {
KeyIdentity::Address(x) => Ok(keystore.get_alias_by_address(&x)?),
KeyIdentity::Alias(x) => Ok(x),
}
}
10 changes: 7 additions & 3 deletions crates/iota/src/keytool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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<String>,
Expand Down Expand Up @@ -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,
Expand Down
Loading