2025-10-31 16:23:01 +02:00
|
|
|
use anyhow::Result;
|
|
|
|
|
use clap::Subcommand;
|
|
|
|
|
|
2025-11-27 22:07:53 +03:00
|
|
|
use crate::{
|
|
|
|
|
WalletCore,
|
|
|
|
|
cli::{SubcommandReturnValue, WalletSubcommand},
|
|
|
|
|
};
|
2025-10-31 16:23:01 +02:00
|
|
|
|
2026-03-10 00:17:43 +03:00
|
|
|
/// Represents generic config CLI subcommand.
|
2025-10-31 16:23:01 +02:00
|
|
|
#[derive(Subcommand, Debug, Clone)]
|
|
|
|
|
pub enum ConfigSubcommand {
|
2026-03-10 00:17:43 +03:00
|
|
|
/// Getter of config fields.
|
2026-01-08 09:38:04 +01:00
|
|
|
Get {
|
2026-03-10 00:17:43 +03:00
|
|
|
/// Print all config fields.
|
2026-01-08 09:38:04 +01:00
|
|
|
#[arg(short, long)]
|
|
|
|
|
all: bool,
|
2026-03-10 00:17:43 +03:00
|
|
|
/// Config field key to get.
|
2026-01-08 09:38:04 +01:00
|
|
|
key: Option<String>,
|
|
|
|
|
},
|
2026-03-10 00:17:43 +03:00
|
|
|
/// Setter of config fields.
|
2025-11-03 15:45:50 +02:00
|
|
|
Set { key: String, value: String },
|
2026-03-10 00:17:43 +03:00
|
|
|
/// Prints description of corresponding field.
|
2025-11-17 14:43:33 +02:00
|
|
|
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> {
|
2026-04-10 20:23:25 +03:00
|
|
|
let config = wallet_core.config();
|
2025-10-31 16:23:01 +02:00
|
|
|
match self {
|
2026-03-09 18:27:56 +03:00
|
|
|
Self::Get { all, key } => {
|
2026-01-08 09:38:04 +01:00
|
|
|
if all {
|
2026-04-10 20:23:25 +03:00
|
|
|
let config_str = serde_json::to_string_pretty(&config)?;
|
2025-10-31 16:23:01 +02:00
|
|
|
|
2025-11-03 15:45:50 +02:00
|
|
|
println!("{config_str}");
|
2026-01-08 09:38:04 +01:00
|
|
|
} else if let Some(key) = key {
|
|
|
|
|
match key.as_str() {
|
|
|
|
|
"sequencer_addr" => {
|
2026-04-10 20:23:25 +03:00
|
|
|
println!("{}", config.sequencer_addr);
|
2026-01-08 09:38:04 +01:00
|
|
|
}
|
2026-02-24 20:52:14 +03:00
|
|
|
"seq_poll_timeout" => {
|
2026-04-10 20:23:25 +03:00
|
|
|
println!("{:?}", config.seq_poll_timeout);
|
2026-01-08 09:38:04 +01:00
|
|
|
}
|
|
|
|
|
"seq_tx_poll_max_blocks" => {
|
2026-04-10 20:23:25 +03:00
|
|
|
println!("{}", config.seq_tx_poll_max_blocks);
|
2026-01-08 09:38:04 +01:00
|
|
|
}
|
|
|
|
|
"seq_poll_max_retries" => {
|
2026-04-10 20:23:25 +03:00
|
|
|
println!("{}", config.seq_poll_max_retries);
|
2026-01-08 09:38:04 +01:00
|
|
|
}
|
|
|
|
|
"seq_block_poll_max_amount" => {
|
2026-04-10 20:23:25 +03:00
|
|
|
println!("{}", config.seq_block_poll_max_amount);
|
2026-01-08 09:38:04 +01:00
|
|
|
}
|
|
|
|
|
"basic_auth" => {
|
2026-04-10 20:23:25 +03:00
|
|
|
if let Some(basic_auth) = &config.basic_auth {
|
2026-01-08 09:38:04 +01:00
|
|
|
println!("{basic_auth}");
|
|
|
|
|
} else {
|
|
|
|
|
println!("Not set");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_ => {
|
|
|
|
|
println!("Unknown field");
|
|
|
|
|
}
|
2025-12-08 18:26:35 +03:00
|
|
|
}
|
2026-01-08 09:38:04 +01:00
|
|
|
} else {
|
|
|
|
|
println!("Please provide a key or use --all flag");
|
2025-12-08 18:26:35 +03:00
|
|
|
}
|
2026-01-08 09:38:04 +01:00
|
|
|
}
|
2026-03-09 18:27:56 +03:00
|
|
|
Self::Set { key, value } => {
|
2026-04-10 20:23:25 +03:00
|
|
|
let mut config = config.clone();
|
2025-11-03 15:45:50 +02:00
|
|
|
match key.as_str() {
|
2025-10-31 16:23:01 +02:00
|
|
|
"sequencer_addr" => {
|
2026-04-10 20:23:25 +03:00
|
|
|
config.sequencer_addr = value.parse()?;
|
2025-10-31 16:23:01 +02:00
|
|
|
}
|
2026-02-24 20:52:14 +03:00
|
|
|
"seq_poll_timeout" => {
|
2026-04-10 20:23:25 +03:00
|
|
|
config.seq_poll_timeout = humantime::parse_duration(&value)
|
|
|
|
|
.map_err(|e| anyhow::anyhow!("Invalid duration: {e}"))?;
|
2025-10-31 16:23:01 +02:00
|
|
|
}
|
2025-12-04 14:55:45 +03:00
|
|
|
"seq_tx_poll_max_blocks" => {
|
2026-04-10 20:23:25 +03:00
|
|
|
config.seq_tx_poll_max_blocks = value.parse()?;
|
2025-10-31 16:23:01 +02:00
|
|
|
}
|
|
|
|
|
"seq_poll_max_retries" => {
|
2026-04-10 20:23:25 +03:00
|
|
|
config.seq_poll_max_retries = value.parse()?;
|
2025-10-31 16:23:01 +02:00
|
|
|
}
|
2025-12-04 14:55:45 +03:00
|
|
|
"seq_block_poll_max_amount" => {
|
2026-04-10 20:23:25 +03:00
|
|
|
config.seq_block_poll_max_amount = value.parse()?;
|
2025-10-31 16:23:01 +02:00
|
|
|
}
|
2025-12-08 18:26:35 +03:00
|
|
|
"basic_auth" => {
|
2026-04-10 20:23:25 +03:00
|
|
|
config.basic_auth = Some(value.parse()?);
|
2025-12-08 18:26:35 +03:00
|
|
|
}
|
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
|
|
|
|
2026-04-10 20:23:25 +03:00
|
|
|
wallet_core.set_config(config);
|
2026-03-03 23:21:08 +03:00
|
|
|
wallet_core.store_config_changes().await?;
|
2025-10-31 16:23:01 +02:00
|
|
|
}
|
2026-03-09 18:27:56 +03:00
|
|
|
Self::Description { key } => match key.as_str() {
|
2025-11-17 14:43:33 +02:00
|
|
|
"override_rust_log" => {
|
|
|
|
|
println!("Value of variable RUST_LOG to override, affects logging");
|
|
|
|
|
}
|
|
|
|
|
"sequencer_addr" => {
|
2025-11-24 17:09:30 +03:00
|
|
|
println!("HTTP V4 account_id of sequencer");
|
2025-11-17 14:43:33 +02:00
|
|
|
}
|
2026-02-24 20:52:14 +03:00
|
|
|
"seq_poll_timeout" => {
|
2025-11-17 14:43:33 +02:00
|
|
|
println!(
|
2026-02-24 20:52:14 +03:00
|
|
|
"Sequencer client retry variable: how much time to wait between retries (human readable duration)"
|
2025-11-17 14:43:33 +02:00
|
|
|
);
|
|
|
|
|
}
|
2025-12-04 14:55:45 +03:00
|
|
|
"seq_tx_poll_max_blocks" => {
|
2025-11-17 14:43:44 +02:00
|
|
|
println!(
|
2025-12-04 14:55:45 +03:00
|
|
|
"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!(
|
2025-12-04 14:55:45 +03:00
|
|
|
"Sequencer client retry variable: max number of retries before failing(can be zero)"
|
2025-11-17 14:43:33 +02:00
|
|
|
);
|
|
|
|
|
}
|
2025-12-04 14:55:45 +03:00
|
|
|
"seq_block_poll_max_amount" => {
|
2025-11-17 14:43:33 +02:00
|
|
|
println!(
|
2025-12-04 14:55:45 +03:00
|
|
|
"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)");
|
|
|
|
|
}
|
2025-12-08 18:26:35 +03:00
|
|
|
"basic_auth" => {
|
|
|
|
|
println!("Basic authentication credentials for sequencer HTTP requests");
|
|
|
|
|
}
|
2025-11-17 14:43:33 +02:00
|
|
|
_ => {
|
|
|
|
|
println!("Unknown field");
|
|
|
|
|
}
|
|
|
|
|
},
|
2025-10-31 16:23:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(SubcommandReturnValue::Empty)
|
|
|
|
|
}
|
2025-11-03 15:45:50 +02:00
|
|
|
}
|