Skip to content

Commit

Permalink
sdk: allow overriding the active_env in WalletContext
Browse files Browse the repository at this point in the history
  • Loading branch information
wbbradley committed Feb 5, 2025
1 parent 93f0205 commit 65a1da0
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion crates/sui-sdk/src/wallet_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,34 @@ impl WalletContext {
request_timeout: Option<std::time::Duration>,
max_concurrent_requests: Option<u64>,
) -> Result<Self, anyhow::Error> {
let config: SuiClientConfig = PersistedConfig::read(config_path).map_err(|err| {
Self::new_with_env_override(config_path, None, request_timeout, max_concurrent_requests)
}

pub fn new_with_env_override(
config_path: &Path,
env_override: Option<&str>,
request_timeout: Option<std::time::Duration>,
max_concurrent_requests: Option<u64>,
) -> Result<Self, anyhow::Error> {
let mut config: SuiClientConfig = PersistedConfig::read(config_path).map_err(|err| {
anyhow!(
"Cannot open wallet config file at {:?}. Err: {err}",
config_path
)
})?;

if let Some(env_override) = env_override {
// Allow caller to override the selection of the active env.
if !config.envs.iter().any(|env| env.alias == env_override) {
return Err(anyhow!(
"Env '{}' not found in wallet config file '{}'.",
env_override,
config_path.display()
));
}
config.active_env = Some(env_override.to_string());
}

let config = config.persisted(config_path);
let context = Self {
config,
Expand Down

0 comments on commit 65a1da0

Please sign in to comment.