Skip to content

Commit 5846592

Browse files
committed
Add caching for new-env and when prompting if no wallet file exists
1 parent 1534c26 commit 5846592

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

crates/sui-cluster-test/src/cluster.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ pub async fn new_wallet_context_from_cluster(
377377
rpc: fullnode_url.into(),
378378
ws: None,
379379
basic_auth: None,
380+
chain_id: None,
380381
}],
381382
active_address: Some(address),
382383
active_env: Some("localnet".to_string()),

crates/sui-sdk/src/sui_client_config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ impl Display for SuiEnv {
165165
writeln!(writer)?;
166166
write!(writer, "Basic Auth: {}", basic_auth)?;
167167
}
168+
if let Some(chain_id) = &self.chain_id {
169+
writeln!(writer)?;
170+
write!(writer, "Chain ID: {}", chain_id)?;
171+
}
168172
write!(f, "{}", writer)
169173
}
170174
}

crates/sui/src/client_commands.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ impl SuiClientCommands {
18211821
"Environment config with name [{alias}] already exists."
18221822
));
18231823
}
1824-
let env = SuiEnv {
1824+
let mut env = SuiEnv {
18251825
alias,
18261826
rpc,
18271827
ws,
@@ -1833,7 +1833,8 @@ impl SuiClientCommands {
18331833
env.create_rpc_client(None, None).await?;
18341834
context.config.envs.push(env.clone());
18351835
context.config.save()?;
1836-
let _ = context.cache_chain_id(&context.get_client().await?).await?;
1836+
let chain_id = context.cache_chain_id(&context.get_client().await?).await?;
1837+
env.chain_id = Some(chain_id);
18371838
SuiClientCommandResult::NewEnv(env)
18381839
}
18391840
SuiClientCommands::ActiveEnv => SuiClientCommandResult::ActiveEnv(

crates/sui/src/sui_commands.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1625,6 +1625,9 @@ async fn prompt_if_no_config(
16251625
}
16261626
.persisted(wallet_conf_path)
16271627
.save()?;
1628+
1629+
let context = WalletContext::new(wallet_conf_path)?;
1630+
let _ = context.cache_chain_id(&context.get_client().await?).await?;
16281631
}
16291632
}
16301633
Ok(())

0 commit comments

Comments
 (0)