Skip to content

Commit

Permalink
fix: remove KeyName will be added by ledger PR
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Jul 10, 2024
1 parent ba8eb74 commit 1767197
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 46 deletions.
34 changes: 4 additions & 30 deletions cmd/soroban-cli/src/commands/config/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<Self, Self::Err> {
if s == "ledger" {
return Err(Error::LedgerKeyName);
}
Ok(KeyName(s.to_string()))
}
}

impl AsRef<Path> for Location {
fn as_ref(&self) -> &Path {
match self {
Expand Down Expand Up @@ -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()?)
}

Expand Down Expand Up @@ -233,15 +207,15 @@ impl Args {
Ok(saved_networks.chain(default_networks).collect())
}

pub fn read_identity(&self, name: &KeyName) -> Result<SignerKind, Error> {
pub fn read_identity(&self, name: &str) -> Result<SignerKind, Error> {
KeyType::Identity.read_with_global(name, &self.local_config()?)
}

pub fn account(&self, account_str: &str) -> Result<SignerKind, Error> {
if let Ok(signer) = account_str.parse::<SignerKind>() {
Ok(signer)
} else {
self.read_identity(&account_str.parse()?)
self.read_identity(account_str)
}
}

Expand All @@ -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()?)
}

Expand Down
4 changes: 1 addition & 3 deletions cmd/soroban-cli/src/commands/keys/add.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use clap::command;

use crate::commands::config::locator::KeyName;

use super::super::config::{locator, secret};

#[derive(thiserror::Error, Debug)]
Expand All @@ -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,
Expand Down
10 changes: 4 additions & 6 deletions cmd/soroban-cli/src/commands/keys/address.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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)]
Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-cli/src/commands/keys/generate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::{arg, command};

use crate::commands::{config::locator::KeyName, network};
use crate::commands::network;

use super::super::config::{
locator,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-cli/src/commands/keys/rm.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions cmd/soroban-cli/src/commands/keys/show.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use clap::arg;

use crate::commands::config::locator::KeyName;

use super::super::config::{locator, secret};

#[derive(thiserror::Error, Debug)]
Expand All @@ -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)]
Expand Down

0 comments on commit 1767197

Please sign in to comment.