Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(iota)!: Set active env when adding new env if empty #5330

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from

Conversation

DaughterOfMars
Copy link
Contributor

@DaughterOfMars DaughterOfMars commented Feb 11, 2025

Description

Much like #5173, when we call iota client new-env we do not set the active env if there wasn't one already. This PR changes that (and does a little additional cleanup).

Additionally, this PR skips prompting for an env when you call iota client new-env with no config.

Before

iota client new-env --alias mynet --rpc https://api.devnet.iota.cafe 
Config file ["/Users/chloe/.iota/iota_config/client.yaml"] doesn't exist, do you want to connect to an IOTA Full node server [y/N]?y
IOTA Full node server URL (Defaults to IOTA Testnet if not specified) :                             
Select key scheme to generate keypair (0 for ed25519, 1 for secp256k1, 2: for secp256r1):
0
Keys saved as Bech32.
Generated new keypair and alias for address with scheme "ed25519" [recursing-amethyst: 0x039e3fb4e0176d491ff2dd6f5dfa87e2036fa3b61381d789ffc1b0d68e0705a6]
Secret Recovery Phrase : [judge smile grief seat lecture process critic tape firm reform dream real]
Added new IOTA env [mynet] to config.

client.yml

---
keystore:
  File: /Users/chloe/.iota/iota_config/iota.keystore
envs:
  - alias: testnet
    rpc: "https://api.testnet.iota.cafe"
    ws: ~
    basic_auth: ~
    faucet: "https://faucet.testnet.iota.cafe/v1/gas"
  - alias: mynet
    rpc: "https://api.devnet.iota.cafe"
    ws: ~
    basic_auth: ~
    faucet: ~
active_env: testnet
active_address: "0x039e3fb4e0176d491ff2dd6f5dfa87e2036fa3b61381d789ffc1b0d68e0705a6"

After

iota client new-env --alias mynet --rpc https://api.devnet.iota.cafe
Select key scheme to generate keypair (0 for ed25519, 1 for secp256k1, 2: for secp256r1):
0
Keys saved as Bech32.
Generated new keypair and alias for address with scheme "ed25519" [adoring-emerald: 0x784dd4048df1f9b6a64917b9b5c4a441c3d3d12549835836d1801154be435866]
Secret Recovery Phrase : [parrot bullet ice carpet blast seed similar craft toy eager virus flush]
Added new IOTA env [mynet] to config.

client.yml

---
keystore:
  File: /Users/chloe/.iota/iota_config/iota.keystore
envs:
  - alias: mynet
    rpc: "https://api.devnet.iota.cafe"
    ws: ~
    basic_auth: ~
    faucet: ~
active_env: mynet
active_address: "0xe5eea96541b1223b7513d022d5c78025ac7eaade0666ccdfa674d2e293f56325"

@DaughterOfMars DaughterOfMars requested a review from a team as a code owner February 11, 2025 12:57
Copy link

vercel bot commented Feb 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

4 Skipped Deployments
Name Status Preview Comments Updated (UTC)
apps-backend ⬜️ Ignored (Inspect) Visit Preview Feb 11, 2025 6:20pm
apps-ui-kit ⬜️ Ignored (Inspect) Visit Preview Feb 11, 2025 6:20pm
rebased-explorer ⬜️ Ignored (Inspect) Visit Preview Feb 11, 2025 6:20pm
wallet-dashboard ⬜️ Ignored (Inspect) Visit Preview Feb 11, 2025 6:20pm

@iota-ci iota-ci added dev-tools Issues related to the Developer Tools Team sc-platform Issues related to the Smart Contract Platform group. labels Feb 11, 2025
@thibault-martinez thibault-martinez linked an issue Feb 11, 2025 that may be closed by this pull request
Comment on lines 88 to 92
if let Some(active_env) = &self.active_env {
self.get_env(active_env)
} else {
self.envs.first()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also set self.active_env to self.envs.first() then? Feels weird that we claim to have an active env but the internal state of the object is different.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a mutable fn and I don't think it should be

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but the API is kind of lying to the user, because the object's internal state doesn't reflect what the method returns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's true. If there's no env the default is the first, which is represented in the state

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently get_active_env() and active_env() (autoimplemented getter) may return different values, and I don't think that's good.

Comment on lines 103 to 107
if self.get_env(&env.alias).is_none() {
if self.active_env.is_none() {
self.set_active_env(env.alias.clone());
}
self.envs.push(env);
Copy link
Contributor

@Alex6323 Alex6323 Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the environment should also be set to active in case the user tried to add the same environment again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand. You mean if the env exists and they try to add it again?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I agree

Copy link
Contributor

@Alex6323 Alex6323 Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay then ... I would still update the docs for this method to mention that it also sets the new env as active (but only if it was unknown before)

} else {
self.envs.first()
}
pub fn get_env(&self, alias: &str) -> Option<&IotaEnv> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know how to feel about this change tbh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How so?

@DaughterOfMars DaughterOfMars requested review from a team as code owners February 11, 2025 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dev-tools Issues related to the Developer Tools Team sc-platform Issues related to the Smart Contract Platform group.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set active env when adding new env if empty
4 participants