mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-07-09 15:29:34 +00:00
Merge 6bce9572df645b3a91171931fe707ef825a6bb6b into 1b4d8fbcf4caa1448473fd99b4ac9d386abf3bc3
This commit is contained in:
commit
f7ab80665a
@ -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()?;
|
||||
|
||||
52
lez/wallet/src/cli/network.rs
Normal file
52
lez/wallet/src/cli/network.rs
Normal 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())
|
||||
}
|
||||
@ -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,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user