Skip to content
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
2 changes: 1 addition & 1 deletion src/dfx-core/src/error/root_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pub enum FetchRootKeyError {
AgentError(#[from] ic_agent::AgentError),

#[error("This command only runs on local instances. Cannot run this on the real IC.")]
NetworkMustBeLocal,
MustNotFetchRootKeyOnMainnet,
}
18 changes: 17 additions & 1 deletion src/dfx-core/src/network/root_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ use crate::{
};
use ic_agent::Agent;

#[deprecated(note = "use fetch_root_key_when_non_mainnet() instead")]
pub async fn fetch_root_key_when_local(
agent: &Agent,
network: &NetworkDescriptor,
) -> Result<(), FetchRootKeyError> {
fetch_root_key_when_non_mainnet(agent, network).await
}

pub async fn fetch_root_key_when_non_mainnet(
agent: &Agent,
network: &NetworkDescriptor,
) -> Result<(), FetchRootKeyError> {
if !network.is_ic {
agent
Expand All @@ -16,16 +24,24 @@ pub async fn fetch_root_key_when_local(
Ok(())
}

#[deprecated(note = "use fetch_root_key_when_non_mainnet_or_error() instead")]
pub async fn fetch_root_key_when_local_or_error(
agent: &Agent,
network: &NetworkDescriptor,
) -> Result<(), FetchRootKeyError> {
fetch_root_key_when_non_mainnet_or_error(agent, network).await
}

pub async fn fetch_root_key_when_non_mainnet_or_error(
agent: &Agent,
network: &NetworkDescriptor,
) -> Result<(), FetchRootKeyError> {
if !network.is_ic {
agent
.fetch_root_key()
.await
.map_err(FetchRootKeyError::AgentError)
} else {
Err(FetchRootKeyError::NetworkMustBeLocal)
Err(FetchRootKeyError::MustNotFetchRootKeyOnMainnet)
}
}
4 changes: 2 additions & 2 deletions src/dfx/src/lib/root_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use dfx_core::network::root_key;
pub async fn fetch_root_key_if_needed(env: &dyn Environment) -> DfxResult {
let agent = env.get_agent();
let network = env.get_network_descriptor();
root_key::fetch_root_key_when_local(agent, network).await?;
root_key::fetch_root_key_when_non_mainnet(agent, network).await?;
Ok(())
}

Expand All @@ -14,6 +14,6 @@ pub async fn fetch_root_key_if_needed(env: &dyn Environment) -> DfxResult {
pub async fn fetch_root_key_or_anyhow(env: &dyn Environment) -> DfxResult {
let agent = env.get_agent();
let network = env.get_network_descriptor();
root_key::fetch_root_key_when_local_or_error(agent, network).await?;
root_key::fetch_root_key_when_non_mainnet_or_error(agent, network).await?;
Ok(())
}