From ab3dd8f5a0276c91a5de1d97828f091e79d20fc7 Mon Sep 17 00:00:00 2001 From: Dhanraj30 Date: Tue, 15 Oct 2024 21:27:38 +0530 Subject: [PATCH 1/8] Fix: stellar contract info * commands require network when network not required --- cmd/soroban-cli/src/commands/network/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmd/soroban-cli/src/commands/network/mod.rs b/cmd/soroban-cli/src/commands/network/mod.rs index 8dd61b394..452cb50a7 100644 --- a/cmd/soroban-cli/src/commands/network/mod.rs +++ b/cmd/soroban-cli/src/commands/network/mod.rs @@ -97,6 +97,17 @@ impl Cmd { cmd.run(global_args).await?; } }; + + // Additional logic for checking network requirement + // If WASM file is provided, don't require network arguments + if global_args.wasm.is_some() { + return Ok(()); + } + + // If no wasm is provided, network arguments are required + if global_args.rpc_url.is_none() || global_args.network_passphrase.is_none() || global_args.network.is_none() { + return Err(Error::Network); + } Ok(()) } } From 21e45f1347900fe083c90c42335038f2f5bced87 Mon Sep 17 00:00:00 2001 From: Dhanraj30 Date: Tue, 22 Oct 2024 16:41:00 +0530 Subject: [PATCH 2/8] Added wasm field to Args struct and updated Cmd::run logic --- cmd/soroban-cli/src/commands/global.rs | 19 +++++++++++++++++++ cmd/soroban-cli/src/commands/network/mod.rs | 13 +++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/cmd/soroban-cli/src/commands/global.rs b/cmd/soroban-cli/src/commands/global.rs index be883b6fd..f29c2cecf 100644 --- a/cmd/soroban-cli/src/commands/global.rs +++ b/cmd/soroban-cli/src/commands/global.rs @@ -46,6 +46,22 @@ pub struct Args { /// Do not cache your simulations and transactions #[arg(long, env = "STELLAR_NO_CACHE", global = true)] pub no_cache: bool, + + /// RPC URL for the Stellar network + #[arg(long, env = "STELLAR_RPC_URL")] + pub rpc_url: Option, + + /// Network passphrase for the Stellar network + #[arg(long, env = "STELLAR_NETWORK_PASSPHRASE")] + pub network_passphrase: Option, + + /// Network name (e.g., 'testnet', 'mainnet') + #[arg(long, env = "STELLAR_NETWORK")] + pub network: Option, + + /// Path to the WebAssembly file + #[arg(long, env = "STELLAR_WASM", global = true)] + pub wasm: Option, } #[derive(thiserror::Error, Debug)] @@ -61,6 +77,9 @@ pub enum Error { filepath: PathBuf, error: soroban_ledger_snapshot::Error, }, + + #[error("network arg or rpc url and network passphrase are required if using the network")] + Network, } impl Args { diff --git a/cmd/soroban-cli/src/commands/network/mod.rs b/cmd/soroban-cli/src/commands/network/mod.rs index 452cb50a7..f630186c6 100644 --- a/cmd/soroban-cli/src/commands/network/mod.rs +++ b/cmd/soroban-cli/src/commands/network/mod.rs @@ -97,17 +97,18 @@ impl Cmd { cmd.run(global_args).await?; } }; - - // Additional logic for checking network requirement - // If WASM file is provided, don't require network arguments + + // Check if a WASM file is provided; if so, skip the network argument requirement if global_args.wasm.is_some() { - return Ok(()); + return Ok(()); // No further checks needed } - // If no wasm is provided, network arguments are required + // Ensure network arguments are provided when WASM is not specified if global_args.rpc_url.is_none() || global_args.network_passphrase.is_none() || global_args.network.is_none() { - return Err(Error::Network); + return Err(Error::Network); // Inform user that these arguments are required } + + Ok(()) } } From 824e43a11ff2c07455544759b9c1bc30a56d55e5 Mon Sep 17 00:00:00 2001 From: Dhanraj30 Date: Wed, 23 Oct 2024 23:35:20 +0530 Subject: [PATCH 3/8] fix: prevent network resolution when local wasm is provided in fetch_wasm --- .../src/commands/contract/info/shared.rs | 14 ++++++++++---- cmd/soroban-cli/src/commands/global.rs | 17 ----------------- cmd/soroban-cli/src/commands/network/mod.rs | 11 ----------- 3 files changed, 10 insertions(+), 32 deletions(-) diff --git a/cmd/soroban-cli/src/commands/contract/info/shared.rs b/cmd/soroban-cli/src/commands/contract/info/shared.rs index 0974632ae..402c9270d 100644 --- a/cmd/soroban-cli/src/commands/contract/info/shared.rs +++ b/cmd/soroban-cli/src/commands/contract/info/shared.rs @@ -59,11 +59,17 @@ pub enum Error { } pub async fn fetch_wasm(args: &Args) -> Result>, Error> { - let network = &args.network.get(&args.locator)?; + // Check if a local WASM file path is provided + if let Some(path) = &args.wasm { + // Read the WASM file and return its contents + let wasm_bytes = wasm::Args { wasm: path.clone() }.read()?; + return Ok(Some(wasm_bytes)); + } - let wasm = if let Some(path) = &args.wasm { - wasm::Args { wasm: path.clone() }.read()? - } else if let Some(wasm_hash) = &args.wasm_hash { + // If no local wasm, then check for wasm_hash and fetch from the network + let network = &args.network.get(&args.locator)?; + + let wasm = if let Some(wasm_hash) = &args.wasm_hash { let hash = hex::decode(wasm_hash) .map_err(|_| InvalidWasmHash(wasm_hash.clone()))? .try_into() diff --git a/cmd/soroban-cli/src/commands/global.rs b/cmd/soroban-cli/src/commands/global.rs index f29c2cecf..4f61f14e8 100644 --- a/cmd/soroban-cli/src/commands/global.rs +++ b/cmd/soroban-cli/src/commands/global.rs @@ -47,21 +47,6 @@ pub struct Args { #[arg(long, env = "STELLAR_NO_CACHE", global = true)] pub no_cache: bool, - /// RPC URL for the Stellar network - #[arg(long, env = "STELLAR_RPC_URL")] - pub rpc_url: Option, - - /// Network passphrase for the Stellar network - #[arg(long, env = "STELLAR_NETWORK_PASSPHRASE")] - pub network_passphrase: Option, - - /// Network name (e.g., 'testnet', 'mainnet') - #[arg(long, env = "STELLAR_NETWORK")] - pub network: Option, - - /// Path to the WebAssembly file - #[arg(long, env = "STELLAR_WASM", global = true)] - pub wasm: Option, } #[derive(thiserror::Error, Debug)] @@ -78,8 +63,6 @@ pub enum Error { error: soroban_ledger_snapshot::Error, }, - #[error("network arg or rpc url and network passphrase are required if using the network")] - Network, } impl Args { diff --git a/cmd/soroban-cli/src/commands/network/mod.rs b/cmd/soroban-cli/src/commands/network/mod.rs index f630186c6..d0b409857 100644 --- a/cmd/soroban-cli/src/commands/network/mod.rs +++ b/cmd/soroban-cli/src/commands/network/mod.rs @@ -98,17 +98,6 @@ impl Cmd { } }; - // Check if a WASM file is provided; if so, skip the network argument requirement - if global_args.wasm.is_some() { - return Ok(()); // No further checks needed - } - - // Ensure network arguments are provided when WASM is not specified - if global_args.rpc_url.is_none() || global_args.network_passphrase.is_none() || global_args.network.is_none() { - return Err(Error::Network); // Inform user that these arguments are required - } - - Ok(()) } } From b838367988e72020b780060bf5331a0c1344a118 Mon Sep 17 00:00:00 2001 From: Dhanraj Avhad <95683132+Dhanraj30@users.noreply.github.com> Date: Thu, 24 Oct 2024 23:30:57 +0530 Subject: [PATCH 4/8] Update cmd/soroban-cli/src/commands/global.rs Co-authored-by: Willem Wyndham --- cmd/soroban-cli/src/commands/global.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/soroban-cli/src/commands/global.rs b/cmd/soroban-cli/src/commands/global.rs index 4f61f14e8..89dcbb1ae 100644 --- a/cmd/soroban-cli/src/commands/global.rs +++ b/cmd/soroban-cli/src/commands/global.rs @@ -46,7 +46,6 @@ pub struct Args { /// Do not cache your simulations and transactions #[arg(long, env = "STELLAR_NO_CACHE", global = true)] pub no_cache: bool, - } #[derive(thiserror::Error, Debug)] From 2107c7478686f92d3a316f083d5ee13e8af822ab Mon Sep 17 00:00:00 2001 From: Dhanraj Avhad <95683132+Dhanraj30@users.noreply.github.com> Date: Thu, 24 Oct 2024 23:31:29 +0530 Subject: [PATCH 5/8] Update cmd/soroban-cli/src/commands/network/mod.rs Co-authored-by: Willem Wyndham --- cmd/soroban-cli/src/commands/network/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/soroban-cli/src/commands/network/mod.rs b/cmd/soroban-cli/src/commands/network/mod.rs index d0b409857..8dd61b394 100644 --- a/cmd/soroban-cli/src/commands/network/mod.rs +++ b/cmd/soroban-cli/src/commands/network/mod.rs @@ -97,7 +97,6 @@ impl Cmd { cmd.run(global_args).await?; } }; - Ok(()) } } From 7e8fffd8fa03c80199df9e8179db40044e79596d Mon Sep 17 00:00:00 2001 From: Dhanraj Avhad <95683132+Dhanraj30@users.noreply.github.com> Date: Thu, 24 Oct 2024 23:31:49 +0530 Subject: [PATCH 6/8] Update cmd/soroban-cli/src/commands/global.rs Co-authored-by: Willem Wyndham --- cmd/soroban-cli/src/commands/global.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/soroban-cli/src/commands/global.rs b/cmd/soroban-cli/src/commands/global.rs index 89dcbb1ae..be883b6fd 100644 --- a/cmd/soroban-cli/src/commands/global.rs +++ b/cmd/soroban-cli/src/commands/global.rs @@ -61,7 +61,6 @@ pub enum Error { filepath: PathBuf, error: soroban_ledger_snapshot::Error, }, - } impl Args { From 6db64c490ee7ceb789bfeaeb9c6cbde4ed14d61f Mon Sep 17 00:00:00 2001 From: Dhanraj Avhad <95683132+Dhanraj30@users.noreply.github.com> Date: Thu, 24 Oct 2024 23:31:56 +0530 Subject: [PATCH 7/8] Update cmd/soroban-cli/src/commands/contract/info/shared.rs Co-authored-by: Willem Wyndham --- cmd/soroban-cli/src/commands/contract/info/shared.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/soroban-cli/src/commands/contract/info/shared.rs b/cmd/soroban-cli/src/commands/contract/info/shared.rs index 402c9270d..b34ec7da8 100644 --- a/cmd/soroban-cli/src/commands/contract/info/shared.rs +++ b/cmd/soroban-cli/src/commands/contract/info/shared.rs @@ -68,7 +68,6 @@ pub async fn fetch_wasm(args: &Args) -> Result>, Error> { // If no local wasm, then check for wasm_hash and fetch from the network let network = &args.network.get(&args.locator)?; - let wasm = if let Some(wasm_hash) = &args.wasm_hash { let hash = hex::decode(wasm_hash) .map_err(|_| InvalidWasmHash(wasm_hash.clone()))? From 32ced654b7de5cb0f64c7d80b2be06727d334b18 Mon Sep 17 00:00:00 2001 From: Willem Wyndham Date: Fri, 1 Nov 2024 09:39:14 -0400 Subject: [PATCH 8/8] fix: make network args optional and postpone error until resolution --- cmd/soroban-cli/src/config/network.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/cmd/soroban-cli/src/config/network.rs b/cmd/soroban-cli/src/config/network.rs index ac7dc04bc..a7ea8cd68 100644 --- a/cmd/soroban-cli/src/config/network.rs +++ b/cmd/soroban-cli/src/config/network.rs @@ -48,8 +48,6 @@ pub struct Args { /// RPC server endpoint #[arg( long = "rpc-url", - requires = "network_passphrase", - required_unless_present = "network", env = "STELLAR_RPC_URL", help_heading = HEADING_RPC, )] @@ -68,8 +66,6 @@ pub struct Args { /// Network passphrase to sign the transaction sent to the rpc server #[arg( long = "network-passphrase", - requires = "rpc_url", - required_unless_present = "network", env = "STELLAR_NETWORK_PASSPHRASE", help_heading = HEADING_RPC, )] @@ -77,8 +73,6 @@ pub struct Args { /// Name of network to use from config #[arg( long, - required_unless_present = "rpc_url", - required_unless_present = "network_passphrase", env = "STELLAR_NETWORK", help_heading = HEADING_RPC, )]