lssa/wallet/src/cli/config.rs

153 lines
5.8 KiB
Rust
Raw Normal View History

2025-10-31 16:23:01 +02:00
use anyhow::Result;
use clap::Subcommand;
use crate::{
WalletCore,
cli::{SubcommandReturnValue, WalletSubcommand},
};
2025-10-31 16:23:01 +02:00
2025-11-26 00:27:20 +03:00
/// Represents generic config CLI subcommand
2025-10-31 16:23:01 +02:00
#[derive(Subcommand, Debug, Clone)]
pub enum ConfigSubcommand {
/// Command to explicitly setup config and storage
///
/// Does nothing in case if both already present
Setup {},
/// Getter of config fields
2025-11-03 15:45:50 +02:00
Get { key: String },
2025-10-31 16:23:01 +02:00
/// Setter of config fields
2025-11-03 15:45:50 +02:00
Set { key: String, value: String },
2025-11-17 14:43:33 +02:00
/// Prints description of corresponding field
Description { key: String },
2025-10-31 16:23:01 +02:00
}
impl WalletSubcommand for ConfigSubcommand {
2025-11-03 15:45:50 +02:00
async fn handle_subcommand(
self,
wallet_core: &mut WalletCore,
) -> Result<SubcommandReturnValue> {
2025-10-31 16:23:01 +02:00
match self {
ConfigSubcommand::Setup {} => {
let path = wallet_core.store_persistent_data().await?;
println!("Stored persistent accounts at {path:#?}");
2025-11-03 15:45:50 +02:00
}
ConfigSubcommand::Get { key } => match key.as_str() {
"all" => {
let config_str =
serde_json::to_string_pretty(&wallet_core.storage.wallet_config)?;
2025-10-31 16:23:01 +02:00
2025-11-03 15:45:50 +02:00
println!("{config_str}");
}
"override_rust_log" => {
if let Some(value) = &wallet_core.storage.wallet_config.override_rust_log {
println!("{value}");
} else {
println!("Not set");
2025-10-31 16:23:01 +02:00
}
2025-11-03 15:45:50 +02:00
}
"sequencer_addr" => {
println!("{}", wallet_core.storage.wallet_config.sequencer_addr);
}
"seq_poll_timeout_millis" => {
println!(
"{}",
wallet_core.storage.wallet_config.seq_poll_timeout_millis
);
}
"seq_tx_poll_max_blocks" => {
println!(
"{}",
wallet_core.storage.wallet_config.seq_tx_poll_max_blocks
);
2025-11-03 15:45:50 +02:00
}
"seq_poll_max_retries" => {
println!("{}", wallet_core.storage.wallet_config.seq_poll_max_retries);
}
"seq_block_poll_max_amount" => {
2025-11-03 15:45:50 +02:00
println!(
"{}",
wallet_core.storage.wallet_config.seq_block_poll_max_amount
2025-11-03 15:45:50 +02:00
);
}
"initial_accounts" => {
println!("{:#?}", wallet_core.storage.wallet_config.initial_accounts);
}
_ => {
println!("Unknown field");
}
},
ConfigSubcommand::Set { key, value } => {
match key.as_str() {
2025-10-31 16:23:01 +02:00
"override_rust_log" => {
2025-11-03 15:45:50 +02:00
wallet_core.storage.wallet_config.override_rust_log = Some(value);
2025-10-31 16:23:01 +02:00
}
"sequencer_addr" => {
2025-11-03 15:45:50 +02:00
wallet_core.storage.wallet_config.sequencer_addr = value;
2025-10-31 16:23:01 +02:00
}
"seq_poll_timeout_millis" => {
2025-11-03 15:45:50 +02:00
wallet_core.storage.wallet_config.seq_poll_timeout_millis =
value.parse()?;
2025-10-31 16:23:01 +02:00
}
"seq_tx_poll_max_blocks" => {
wallet_core.storage.wallet_config.seq_tx_poll_max_blocks = value.parse()?;
2025-10-31 16:23:01 +02:00
}
"seq_poll_max_retries" => {
2025-11-03 15:45:50 +02:00
wallet_core.storage.wallet_config.seq_poll_max_retries = value.parse()?;
2025-10-31 16:23:01 +02:00
}
"seq_block_poll_max_amount" => {
wallet_core.storage.wallet_config.seq_block_poll_max_amount =
value.parse()?;
2025-10-31 16:23:01 +02:00
}
"initial_accounts" => {
2025-11-03 15:45:50 +02:00
anyhow::bail!("Setting this field from wallet is not supported");
2025-10-31 16:23:01 +02:00
}
_ => {
2025-11-03 15:45:50 +02:00
anyhow::bail!("Unknown field");
2025-10-31 16:23:01 +02:00
}
}
2025-11-03 15:45:50 +02:00
let path = wallet_core.store_config_changes().await?;
println!("Stored changed config at {path:#?}");
2025-10-31 16:23:01 +02:00
}
2025-11-17 14:43:33 +02:00
ConfigSubcommand::Description { key } => match key.as_str() {
"override_rust_log" => {
println!("Value of variable RUST_LOG to override, affects logging");
}
"sequencer_addr" => {
println!("HTTP V4 account_id of sequencer");
2025-11-17 14:43:33 +02:00
}
"seq_poll_timeout_millis" => {
println!(
"Sequencer client retry variable: how much time to wait between retries in milliseconds(can be zero)"
);
}
"seq_tx_poll_max_blocks" => {
2025-11-17 14:43:44 +02:00
println!(
"Sequencer client polling variable: max number of blocks to poll to find a transaction"
2025-11-17 14:43:44 +02:00
);
2025-11-17 14:43:33 +02:00
}
"seq_poll_max_retries" => {
println!(
"Sequencer client retry variable: max number of retries before failing(can be zero)"
2025-11-17 14:43:33 +02:00
);
}
"seq_block_poll_max_amount" => {
2025-11-17 14:43:33 +02:00
println!(
"Sequencer client polling variable: max number of blocks to request in one polling call"
2025-11-17 14:43:33 +02:00
);
}
"initial_accounts" => {
println!("List of initial accounts' keys(both public and private)");
}
_ => {
println!("Unknown field");
}
},
2025-10-31 16:23:01 +02:00
}
Ok(SubcommandReturnValue::Empty)
}
2025-11-03 15:45:50 +02:00
}