Skip to content

Commit

Permalink
refactor: CallSenderFromWalletError
Browse files Browse the repository at this point in the history
  • Loading branch information
ericswanson-dfinity committed Sep 23, 2023
1 parent 85e63a2 commit 5c7e272
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
8 changes: 8 additions & 0 deletions src/dfx-core/src/error/identity/call_sender_from_wallet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use candid::types::principal::PrincipalError;
use thiserror::Error;

#[derive(Error, Debug)]
pub enum CallSenderFromWalletError {
#[error("Failed to read principal from id '{0}': {1}")]
ParsePrincipalFromIdFailed(String, PrincipalError),
}
5 changes: 1 addition & 4 deletions src/dfx-core/src/error/identity/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod call_sender_from_wallet;
pub mod convert_mnemonic_to_key;
pub mod create_identity_config;
pub mod create_new_identity;
Expand Down Expand Up @@ -25,7 +26,6 @@ pub mod validate_pem_file;
pub mod write_default_identity;
pub mod write_pem_to_file;

use ic_agent::export::PrincipalError;
use std::path::PathBuf;
use thiserror::Error;

Expand All @@ -34,9 +34,6 @@ pub enum IdentityError {
#[error("Identity {0} does not exist at '{1}'.")]
IdentityDoesNotExist(String, PathBuf),

#[error("Failed to read principal from id '{0}': {1}")]
ParsePrincipalFromIdFailed(String, PrincipalError),

#[error("An Identity named {0} cannot be created as it is reserved for internal use.")]
ReservedIdentityName(String),
}
8 changes: 4 additions & 4 deletions src/dfx-core/src/identity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! Wallets are a map of network-identity, but don't have their own types or manager
//! type.
use crate::config::directories::{get_config_dfx_dir_path, get_shared_network_data_directory};
use crate::error::identity::call_sender_from_wallet::CallSenderFromWalletError;
use crate::error::identity::call_sender_from_wallet::CallSenderFromWalletError::ParsePrincipalFromIdFailed;
use crate::error::identity::load_pem_identity::LoadPemIdentityError;
use crate::error::identity::load_pem_identity::LoadPemIdentityError::ReadIdentityFileFailed;
use crate::error::identity::map_wallets_to_renamed_identity::MapWalletsToRenamedIdentityError;
Expand All @@ -12,7 +14,6 @@ use crate::error::identity::new_hardware_identity::NewHardwareIdentityError::Ins
use crate::error::identity::new_identity::NewIdentityError;
use crate::error::identity::rename_wallet_global_config_key::RenameWalletGlobalConfigKeyError;
use crate::error::identity::rename_wallet_global_config_key::RenameWalletGlobalConfigKeyError::RenameWalletFailed;
use crate::error::identity::IdentityError;
use crate::error::wallet_config::WalletConfigError;
use crate::error::wallet_config::WalletConfigError::{
EnsureWalletConfigDirFailed, LoadWalletConfigFailed, SaveWalletConfigFailed,
Expand Down Expand Up @@ -304,11 +305,10 @@ pub enum CallSender {
// Determine whether the selected Identity
// or the provided wallet canister ID should be the Sender of the call.
impl CallSender {
pub fn from(wallet: &Option<String>) -> Result<Self, IdentityError> {
pub fn from(wallet: &Option<String>) -> Result<Self, CallSenderFromWalletError> {
let sender = if let Some(id) = wallet {
CallSender::Wallet(
Principal::from_text(id)
.map_err(|e| IdentityError::ParsePrincipalFromIdFailed(id.clone(), e))?,
Principal::from_text(id).map_err(|e| ParsePrincipalFromIdFailed(id.clone(), e))?,
)
} else {
CallSender::SelectedId
Expand Down

0 comments on commit 5c7e272

Please sign in to comment.