From 397cc90590d1d74f493e5707fcb6b50ddc84fe6d Mon Sep 17 00:00:00 2001 From: stellarsaur <126507441+stellarsaur@users.noreply.github.com> Date: Mon, 11 Dec 2023 11:21:54 -0800 Subject: [PATCH] soroban-cli: Only Give RC SDK Contract Compilation Warning/Errors if Using Pubnet (#1108) * Only warn/error on RC SDK version if pubnet * Cargo fmt --- .../src/commands/contract/install.rs | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/cmd/soroban-cli/src/commands/contract/install.rs b/cmd/soroban-cli/src/commands/contract/install.rs index d2f307103..905775298 100644 --- a/cmd/soroban-cli/src/commands/contract/install.rs +++ b/cmd/soroban-cli/src/commands/contract/install.rs @@ -15,6 +15,7 @@ use crate::rpc::{self, Client}; use crate::{commands::config, utils, wasm}; const CONTRACT_META_SDK_KEY: &str = "rssdkver"; +const PUBLIC_NETWORK_PASSPHRASE: &str = "Public Global Stellar Network ; September 2015"; #[derive(Parser, Debug, Clone)] #[group(skip)] @@ -70,29 +71,35 @@ impl Cmd { } pub async fn run_and_get_hash(&self) -> Result { + self.run_against_rpc_server(&self.wasm.read()?).await + } + + async fn run_against_rpc_server(&self, contract: &[u8]) -> Result { + let network = self.config.get_network()?; + let client = Client::new(&network.rpc_url)?; + client + .verify_network_passphrase(Some(&network.network_passphrase)) + .await?; let wasm_spec = &self.wasm.parse().map_err(|e| Error::CannotParseWasm { wasm: self.wasm.wasm.clone(), error: e, })?; + // Check Rust SDK version if using the public network. if let Some(rs_sdk_ver) = get_contract_meta_sdk_version(wasm_spec) { - if rs_sdk_ver.contains("rc") && !self.ignore_checks { + if rs_sdk_ver.contains("rc") + && !self.ignore_checks + && network.network_passphrase == PUBLIC_NETWORK_PASSPHRASE + { return Err(Error::ContractCompiledWithReleaseCandidateSdk { wasm: self.wasm.wasm.clone(), version: rs_sdk_ver, }); - } else if rs_sdk_ver.contains("rc") { + } else if rs_sdk_ver.contains("rc") + && network.network_passphrase == PUBLIC_NETWORK_PASSPHRASE + { tracing::warn!("the deployed smart contract {path} was built with Soroban Rust SDK v{rs_sdk_ver}, a release candidate version not intended for use with the Stellar Public Network", path = self.wasm.wasm.display()); } } - self.run_against_rpc_server(&self.wasm.read()?).await - } - - async fn run_against_rpc_server(&self, contract: &[u8]) -> Result { - let network = self.config.get_network()?; - let client = Client::new(&network.rpc_url)?; - client - .verify_network_passphrase(Some(&network.network_passphrase)) - .await?; let key = self.config.key_pair()?; // Get the account sequence number