From 1767197538e9ce9ab4f356978bfda66aff30f87f Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Wed, 10 Jul 2024 15:14:19 -0400 Subject: [PATCH] fix: remove KeyName will be added by ledger PR --- .../src/commands/config/locator.rs | 34 +++---------------- cmd/soroban-cli/src/commands/keys/add.rs | 4 +-- cmd/soroban-cli/src/commands/keys/address.rs | 10 +++--- cmd/soroban-cli/src/commands/keys/generate.rs | 4 +-- cmd/soroban-cli/src/commands/keys/rm.rs | 4 +-- cmd/soroban-cli/src/commands/keys/show.rs | 4 +-- 6 files changed, 14 insertions(+), 46 deletions(-) diff --git a/cmd/soroban-cli/src/commands/config/locator.rs b/cmd/soroban-cli/src/commands/config/locator.rs index b82646d63..9054b7cc2 100644 --- a/cmd/soroban-cli/src/commands/config/locator.rs +++ b/cmd/soroban-cli/src/commands/config/locator.rs @@ -70,10 +70,6 @@ pub enum Error { CannotAccessConfigDir, #[error("cannot parse contract ID {0}: {1}")] CannotParseContractId(String, DecodeError), - #[error("Incorrect Key name")] - IncorrectKeyName, - #[error("Cannot name a Key ledger")] - LedgerKeyName, } #[derive(Debug, clap::Args, Default, Clone)] @@ -107,28 +103,6 @@ impl Display for Location { } } -#[derive(Clone, Debug)] -pub struct KeyName(String); - -impl std::ops::Deref for KeyName { - type Target = str; - - fn deref(&self) -> &Self::Target { - &self.0 - } -} - -impl FromStr for KeyName { - type Err = Error; - - fn from_str(s: &str) -> Result { - if s == "ledger" { - return Err(Error::LedgerKeyName); - } - Ok(KeyName(s.to_string())) - } -} - impl AsRef for Location { fn as_ref(&self) -> &Path { match self { @@ -175,7 +149,7 @@ impl Args { ) } - pub fn write_identity(&self, name: &KeyName, secret: &SignerKind) -> Result<(), Error> { + pub fn write_identity(&self, name: &str, secret: &SignerKind) -> Result<(), Error> { KeyType::Identity.write(name, secret, &self.config_dir()?) } @@ -233,7 +207,7 @@ impl Args { Ok(saved_networks.chain(default_networks).collect()) } - pub fn read_identity(&self, name: &KeyName) -> Result { + pub fn read_identity(&self, name: &str) -> Result { KeyType::Identity.read_with_global(name, &self.local_config()?) } @@ -241,7 +215,7 @@ impl Args { if let Ok(signer) = account_str.parse::() { Ok(signer) } else { - self.read_identity(&account_str.parse()?) + self.read_identity(account_str) } } @@ -256,7 +230,7 @@ impl Args { res } - pub fn remove_identity(&self, name: &KeyName) -> Result<(), Error> { + pub fn remove_identity(&self, name: &str) -> Result<(), Error> { KeyType::Identity.remove(name, &self.config_dir()?) } diff --git a/cmd/soroban-cli/src/commands/keys/add.rs b/cmd/soroban-cli/src/commands/keys/add.rs index ab8de6cf6..bf9ea2293 100644 --- a/cmd/soroban-cli/src/commands/keys/add.rs +++ b/cmd/soroban-cli/src/commands/keys/add.rs @@ -1,7 +1,5 @@ use clap::command; -use crate::commands::config::locator::KeyName; - use super::super::config::{locator, secret}; #[derive(thiserror::Error, Debug)] @@ -17,7 +15,7 @@ pub enum Error { #[group(skip)] pub struct Cmd { /// Name of identity - pub name: KeyName, + pub name: String, #[command(flatten)] pub secrets: secret::Args, diff --git a/cmd/soroban-cli/src/commands/keys/address.rs b/cmd/soroban-cli/src/commands/keys/address.rs index 3a12fc35d..766e948eb 100644 --- a/cmd/soroban-cli/src/commands/keys/address.rs +++ b/cmd/soroban-cli/src/commands/keys/address.rs @@ -1,9 +1,7 @@ -use clap::arg; +use crate::commands::config::secret; -use super::super::config::{ - locator::{self, KeyName}, - secret, -}; +use super::super::config::locator; +use clap::arg; #[derive(thiserror::Error, Debug)] pub enum Error { @@ -21,7 +19,7 @@ pub enum Error { #[group(skip)] pub struct Cmd { /// Name of identity to lookup, default test identity used if not provided - pub name: KeyName, + pub name: String, /// If identity is a seed phrase use this hd path, default is 0 #[arg(long)] diff --git a/cmd/soroban-cli/src/commands/keys/generate.rs b/cmd/soroban-cli/src/commands/keys/generate.rs index 28b01882e..29dbab5cc 100644 --- a/cmd/soroban-cli/src/commands/keys/generate.rs +++ b/cmd/soroban-cli/src/commands/keys/generate.rs @@ -1,6 +1,6 @@ use clap::{arg, command}; -use crate::commands::{config::locator::KeyName, network}; +use crate::commands::network; use super::super::config::{ locator, @@ -21,7 +21,7 @@ pub enum Error { #[group(skip)] pub struct Cmd { /// Name of identity - pub name: KeyName, + pub name: String, /// Do not fund address #[arg(long)] pub no_fund: bool, diff --git a/cmd/soroban-cli/src/commands/keys/rm.rs b/cmd/soroban-cli/src/commands/keys/rm.rs index 9d9c1be51..df48108d3 100644 --- a/cmd/soroban-cli/src/commands/keys/rm.rs +++ b/cmd/soroban-cli/src/commands/keys/rm.rs @@ -1,6 +1,6 @@ use clap::command; -use super::super::config::locator::{self, KeyName}; +use super::super::config::locator; #[derive(thiserror::Error, Debug)] pub enum Error { @@ -12,7 +12,7 @@ pub enum Error { #[group(skip)] pub struct Cmd { /// Identity to remove - pub name: KeyName, + pub name: String, #[command(flatten)] pub config: locator::Args, diff --git a/cmd/soroban-cli/src/commands/keys/show.rs b/cmd/soroban-cli/src/commands/keys/show.rs index 493d02a2f..b99478cbc 100644 --- a/cmd/soroban-cli/src/commands/keys/show.rs +++ b/cmd/soroban-cli/src/commands/keys/show.rs @@ -1,7 +1,5 @@ use clap::arg; -use crate::commands::config::locator::KeyName; - use super::super::config::{locator, secret}; #[derive(thiserror::Error, Debug)] @@ -20,7 +18,7 @@ pub enum Error { #[group(skip)] pub struct Cmd { /// Name of identity to lookup, default is test identity - pub name: KeyName, + pub name: String, /// If identity is a seed phrase use this hd path, default is 0 #[arg(long)]