Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/stellar-registry-cli/src/commands/create_alias.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions crates/stellar-registry-cli/src/commands/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name>`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/<name>`
Expand Down
1 change: 1 addition & 0 deletions crates/stellar-registry-cli/src/commands/fetch_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 29 additions & 0 deletions crates/stellar-registry-cli/src/commands/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Loading