feat(lez/wallet): add change-network command

This commit is contained in:
Sergio Chouhy 2026-07-03 23:57:14 -03:00
parent a0ba6008c3
commit 6bce9572df
3 changed files with 62 additions and 1 deletions

View File

@ -19,6 +19,7 @@ use crate::{
config::ConfigSubcommand,
group::GroupSubcommand,
keycard::KeycardSubcommand,
network::handle_change_network,
programs::{
amm::AmmProgramAgnosticSubcommand, ata::AtaSubcommand, bridge::BridgeSubcommand,
native_token_transfer::AuthTransferSubcommand, pinata::PinataProgramAgnosticSubcommand,
@ -33,6 +34,7 @@ pub mod chain;
pub mod config;
pub mod group;
pub mod keycard;
pub mod network;
pub mod programs;
pub(crate) trait WalletSubcommand {
@ -80,6 +82,8 @@ pub enum Command {
/// Command to setup config, get and set config fields.
#[command(subcommand)]
Config(ConfigSubcommand),
/// Change the network the wallet points to (testnet, local, or a custom URL).
ChangeNetwork,
/// Restoring keys from given password at given `depth`.
///
/// !!!WARNING!!! will rewrite current storage.
@ -271,6 +275,11 @@ pub async fn execute_subcommand(
Command::Config(config_subcommand) => {
config_subcommand.handle_subcommand(wallet_core).await?
}
Command::ChangeNetwork => {
handle_change_network(wallet_core).await?;
SubcommandReturnValue::Empty
}
Command::RestoreKeys { depth } => {
let mnemonic = read_mnemonic_from_stdin()?;
let password = read_password_from_stdin()?;

View File

@ -0,0 +1,52 @@
use std::io::Write as _;
use anyhow::{Context as _, Result};
use url::Url;
use crate::WalletCore;
const TESTNET_SEQUENCER_ADDR: &str = "https://testnet.lez.logos.co";
const LOCAL_SEQUENCER_ADDR: &str = "http://127.0.0.1:3040";
/// Prompt the user to pick a network and update the wallet's `sequencer_addr` accordingly.
pub async fn handle_change_network(wallet_core: &mut WalletCore) -> Result<()> {
println!("Select network:");
println!("1) testnet");
println!("2) local");
println!("3) custom");
let sequencer_addr = match prompt("Enter choice [1-3]: ")?.as_str() {
"1" => TESTNET_SEQUENCER_ADDR
.parse()
.expect("testnet sequencer addr must be a valid URL"),
"2" => LOCAL_SEQUENCER_ADDR
.parse()
.expect("local sequencer addr must be a valid URL"),
"3" => prompt("Enter sequencer URL: ")?
.parse::<Url>()
.context("Invalid sequencer URL")?,
other => anyhow::bail!("Invalid choice: {other}"),
};
let mut config = wallet_core.config().clone();
config.sequencer_addr = sequencer_addr;
wallet_core.set_config(config);
wallet_core.store_config_changes().await?;
println!(
"Sequencer address set to {}",
wallet_core.config().sequencer_addr
);
Ok(())
}
fn prompt(message: &str) -> Result<String> {
print!("{message}");
std::io::stdout().flush()?;
let mut input = String::new();
std::io::stdin().read_line(&mut input)?;
Ok(input.trim().to_owned())
}

View File

@ -47,7 +47,7 @@ pub struct WalletConfig {
impl Default for WalletConfig {
fn default() -> Self {
Self {
sequencer_addr: "http://127.0.0.1:3040".parse().unwrap(),
sequencer_addr: "https://testnet.lez.logos.co".parse().unwrap(),
seq_poll_timeout: Duration::from_secs(12),
seq_tx_poll_max_blocks: 5,
seq_poll_max_retries: 5,