diff --git a/CLI.md b/CLI.md index 1981011ba002..b1a0999766aa 100644 --- a/CLI.md +++ b/CLI.md @@ -109,7 +109,7 @@ A Byzantine-fault tolerant sidechain with low-latency finality and high throughp * `--wallet ` — Sets the file storing the private state of user chains (an empty one will be created if missing) * `--storage ` — Storage configuration for the blockchain history -* `-w`, `--with-wallet ` — Given an integer value `N`, read the wallet state and the wallet storage config from the environment variables `LINERA_WALLET_{N}` and `LINERA_STORAGE_{N}` instead of `LINERA_WALLET` and `LINERA_STORAGE` +* `-w`, `--with-wallet ` — Given an ASCII alphanumeric parameter `X`, read the wallet state and the wallet storage config from the environment variables `LINERA_WALLET_{X}` and `LINERA_STORAGE_{X}` instead of `LINERA_WALLET` and `LINERA_STORAGE` * `--send-timeout-ms ` — Timeout for sending queries (milliseconds) Default value: `4000` diff --git a/linera-client/src/client_options.rs b/linera-client/src/client_options.rs index feb2ba351caf..4923b09054e3 100644 --- a/linera-client/src/client_options.rs +++ b/linera-client/src/client_options.rs @@ -78,11 +78,12 @@ pub struct ClientOptions { #[arg(long = "storage")] pub storage_config: Option, - /// Given an integer value `N`, read the wallet state and the wallet storage config from the - /// environment variables `LINERA_WALLET_{N}` and `LINERA_STORAGE_{N}` instead of - /// `LINERA_WALLET` and `LINERA_STORAGE`. - #[arg(long, short = 'w')] - pub with_wallet: Option, + /// Given an ASCII alphanumeric parameter `X`, read the wallet state and the wallet + /// storage config from the environment variables `LINERA_WALLET_{X}` and + /// `LINERA_STORAGE_{X}` instead of `LINERA_WALLET` and + /// `LINERA_STORAGE`. + #[arg(long, short = 'w', value_parser = util::parse_ascii_alphanumeric_string)] + pub with_wallet: Option, /// Timeout for sending queries (milliseconds) #[arg(long = "send-timeout-ms", default_value = "4000", value_parser = util::parse_millis)] @@ -174,7 +175,8 @@ impl ClientOptions { let mut options = ::parse(); let suffix = options .with_wallet - .map(|n| format!("_{}", n)) + .as_ref() + .map(|x| format!("_{}", x)) .unwrap_or_default(); let wallet_env_var = env::var(format!("LINERA_WALLET{suffix}")).ok(); let storage_env_var = env::var(format!("LINERA_STORAGE{suffix}")).ok(); diff --git a/linera-client/src/util.rs b/linera-client/src/util.rs index b5c2cc07e9f9..0a2147943511 100644 --- a/linera-client/src/util.rs +++ b/linera-client/src/util.rs @@ -32,6 +32,14 @@ pub fn parse_chain_set(s: &str) -> Result, CryptoError> { } } +pub fn parse_ascii_alphanumeric_string(s: &str) -> Result { + if s.chars().all(|x| x.is_ascii_alphanumeric()) { + Ok(s.to_string()) + } else { + Err("Expecting ASCII alphanumeric characters") + } +} + /// Returns after the specified time or if we receive a notification that a new round has started. pub async fn wait_for_next_round(stream: &mut NotificationStream, timeout: RoundTimeout) { let mut stream = stream.filter(|notification| match ¬ification.reason { diff --git a/linera-service/src/linera/main.rs b/linera-service/src/linera/main.rs index 66b7311f8868..5c19f040db19 100644 --- a/linera-service/src/linera/main.rs +++ b/linera-service/src/linera/main.rs @@ -1353,7 +1353,7 @@ fn main() -> anyhow::Result<()> { }; let span = tracing::info_span!("linera::main"); - if let Some(wallet_id) = options.with_wallet { + if let Some(wallet_id) = &options.with_wallet { span.record("wallet_id", wallet_id); }