diff --git a/crates/stellar-registry-cli/src/commands/create_alias.rs b/crates/stellar-registry-cli/src/commands/create_alias.rs index e445328..3005e19 100644 --- a/crates/stellar-registry-cli/src/commands/create_alias.rs +++ b/crates/stellar-registry-cli/src/commands/create_alias.rs @@ -7,6 +7,7 @@ use stellar_strkey::Contract; use crate::commands::global; #[derive(Parser, Debug, Clone)] +#[command(mut_arg("source_account", global::optional_source))] pub struct Cmd { /// Name of deployed contract. Can use prefix if not using verified registry. /// E.g. `unverified/` diff --git a/crates/stellar-registry-cli/src/commands/current_version.rs b/crates/stellar-registry-cli/src/commands/current_version.rs index 653ccd8..091f4dc 100644 --- a/crates/stellar-registry-cli/src/commands/current_version.rs +++ b/crates/stellar-registry-cli/src/commands/current_version.rs @@ -5,6 +5,7 @@ use stellar_registry_build::name::{Prefixed, RegistryAccess}; use crate::commands::global; #[derive(Parser, Debug, Clone)] +#[command(mut_arg("source_account", global::optional_source))] pub struct Cmd { /// Name of published Wasm pub wasm_name: Prefixed, diff --git a/crates/stellar-registry-cli/src/commands/download.rs b/crates/stellar-registry-cli/src/commands/download.rs index c39549e..cbd82bd 100644 --- a/crates/stellar-registry-cli/src/commands/download.rs +++ b/crates/stellar-registry-cli/src/commands/download.rs @@ -7,6 +7,7 @@ use stellar_registry_build::name::{Prefixed, RegistryAccess}; use crate::commands::global; #[derive(Parser, Debug, Clone)] +#[command(mut_arg("source_account", global::optional_source))] pub struct Cmd { /// Name of published Wasm pub wasm_name: Prefixed, diff --git a/crates/stellar-registry-cli/src/commands/fetch_account_id.rs b/crates/stellar-registry-cli/src/commands/fetch_account_id.rs index 9e4dc01..38e1f69 100644 --- a/crates/stellar-registry-cli/src/commands/fetch_account_id.rs +++ b/crates/stellar-registry-cli/src/commands/fetch_account_id.rs @@ -5,6 +5,7 @@ use stellar_registry_build::name::{Prefixed, RegistryAccess}; use crate::commands::global; #[derive(Parser, Debug, Clone)] +#[command(mut_arg("source_account", global::optional_source))] pub struct Cmd { /// Name of the registered account. Can use prefix if not using verified registry. /// E.g. `unverified/` diff --git a/crates/stellar-registry-cli/src/commands/fetch_account_owner.rs b/crates/stellar-registry-cli/src/commands/fetch_account_owner.rs index f6bcda3..4b1dbc9 100644 --- a/crates/stellar-registry-cli/src/commands/fetch_account_owner.rs +++ b/crates/stellar-registry-cli/src/commands/fetch_account_owner.rs @@ -5,6 +5,7 @@ use stellar_registry_build::name::{Prefixed, RegistryAccess}; use crate::commands::global; #[derive(Parser, Debug, Clone)] +#[command(mut_arg("source_account", global::optional_source))] pub struct Cmd { /// Name of the registered account. Can use prefix if not using verified registry. /// E.g. `unverified/` diff --git a/crates/stellar-registry-cli/src/commands/fetch_contract_id.rs b/crates/stellar-registry-cli/src/commands/fetch_contract_id.rs index b3bd4d7..45d4112 100644 --- a/crates/stellar-registry-cli/src/commands/fetch_contract_id.rs +++ b/crates/stellar-registry-cli/src/commands/fetch_contract_id.rs @@ -6,6 +6,7 @@ use stellar_strkey::Contract; use crate::commands::global; #[derive(Parser, Debug, Clone)] +#[command(mut_arg("source_account", global::optional_source))] pub struct Cmd { /// Name of deployed contract. Can use prefix if not using verified registry. /// E.g. `unverified/` diff --git a/crates/stellar-registry-cli/src/commands/fetch_hash.rs b/crates/stellar-registry-cli/src/commands/fetch_hash.rs index b59aba4..f430d31 100644 --- a/crates/stellar-registry-cli/src/commands/fetch_hash.rs +++ b/crates/stellar-registry-cli/src/commands/fetch_hash.rs @@ -5,6 +5,7 @@ use stellar_registry_build::name::{Prefixed, RegistryAccess}; use crate::commands::global; #[derive(Parser, Debug, Clone)] +#[command(mut_arg("source_account", global::optional_source))] pub struct Cmd { /// Name of published Wasm pub wasm_name: Prefixed, diff --git a/crates/stellar-registry-cli/src/commands/global.rs b/crates/stellar-registry-cli/src/commands/global.rs index 5812d4b..b660a3d 100644 --- a/crates/stellar-registry-cli/src/commands/global.rs +++ b/crates/stellar-registry-cli/src/commands/global.rs @@ -22,3 +22,32 @@ impl Args { Ok(rpc::Client::new(&self.config.get_network()?.rpc_url)?) } } + +/// Simulation accepts any public key as the source, even an unfunded one. +const READ_ONLY_SOURCE: &str = "GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWHF"; + +/// For `#[command(mut_arg("source_account", global::optional_source))]` on +/// commands that only simulate reads, so they run without an identity. +pub fn optional_source(arg: clap::Arg) -> clap::Arg { + arg.required(false) + .default_value(READ_ONLY_SOURCE) + .hide_default_value(true) +} + +#[cfg(test)] +mod tests { + use clap::Parser; + + #[derive(Parser)] + #[command(mut_arg("source_account", super::optional_source))] + struct Cmd { + #[command(flatten)] + config: super::Args, + } + + #[test] + fn optional_source_needs_no_identity() { + let cmd = Cmd::try_parse_from(["cmd", "--network", "testnet"]).unwrap(); + cmd.config.source_account().unwrap(); + } +}