From 87a9f02619af81aa65a4e36737dbc6a289b636e0 Mon Sep 17 00:00:00 2001 From: Blaine Heffron Date: Fri, 17 May 2024 15:10:57 -0400 Subject: [PATCH] refactor to be similar to fetch for network retrieval --- .../tests/it/integration/bindings.rs | 1 - .../commands/contract/bindings/typescript.rs | 9 ++++----- cmd/soroban-cli/src/commands/contract/invoke.rs | 13 ++++++++++--- cmd/soroban-cli/src/get_spec.rs | 17 +++++++++++++++-- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/cmd/crates/soroban-test/tests/it/integration/bindings.rs b/cmd/crates/soroban-test/tests/it/integration/bindings.rs index 069951706d..3b76c274e1 100644 --- a/cmd/crates/soroban-test/tests/it/integration/bindings.rs +++ b/cmd/crates/soroban-test/tests/it/integration/bindings.rs @@ -31,5 +31,4 @@ async fn invoke_test_generate_typescript_bindings() { files.count() > 0, "No files generated in the output directory" ); - } diff --git a/cmd/soroban-cli/src/commands/contract/bindings/typescript.rs b/cmd/soroban-cli/src/commands/contract/bindings/typescript.rs index 90d1034d6f..be851e60da 100644 --- a/cmd/soroban-cli/src/commands/contract/bindings/typescript.rs +++ b/cmd/soroban-cli/src/commands/contract/bindings/typescript.rs @@ -83,7 +83,7 @@ impl NetworkRunnable for Cmd { async fn run_against_rpc_server( &self, global_args: Option<&global::Args>, - _config: Option<&config::Args>, + config: Option<&config::Args>, ) -> Result<(), Error> { let spec = if let Some(wasm) = &self.wasm { let wasm: wasm::Args = wasm.into(); @@ -93,11 +93,10 @@ impl NetworkRunnable for Cmd { .map_err(|e| Error::CannotParseContractId(self.contract_id.clone(), e))?; let spec_entries = get_remote_contract_spec( &contract_id, - self.network - .rpc_url - .as_deref() - .ok_or(Error::MissingRpcUrl)?, + self.locator.clone(), + self.network.clone(), global_args, + config, ) .await .map_err(Error::from)?; diff --git a/cmd/soroban-cli/src/commands/contract/invoke.rs b/cmd/soroban-cli/src/commands/contract/invoke.rs index f99eeac7e3..5622b0f2b6 100644 --- a/cmd/soroban-cli/src/commands/contract/invoke.rs +++ b/cmd/soroban-cli/src/commands/contract/invoke.rs @@ -320,6 +320,7 @@ impl NetworkRunnable for Cmd { global_args: Option<&global::Args>, config: Option<&config::Args>, ) -> Result, Error> { + let c = config; let config = config.unwrap_or(&self.config); let network = config.get_network()?; tracing::trace!(?network); @@ -346,9 +347,15 @@ impl NetworkRunnable for Cmd { let sequence: i64 = account_details.seq_num.into(); let AccountId(PublicKey::PublicKeyTypeEd25519(account_id)) = account_details.account_id; - let spec_entries = get_remote_contract_spec(&contract_id, &network.rpc_url, global_args) - .await - .map_err(Error::from)?; + let spec_entries = get_remote_contract_spec( + &contract_id, + config.locator.clone(), + config.network.clone(), + global_args, + c, + ) + .await + .map_err(Error::from)?; // Get the ledger footprint let (function, spec, host_function_params, signers) = diff --git a/cmd/soroban-cli/src/get_spec.rs b/cmd/soroban-cli/src/get_spec.rs index a6239b4ed5..7e60e38600 100644 --- a/cmd/soroban-cli/src/get_spec.rs +++ b/cmd/soroban-cli/src/get_spec.rs @@ -7,6 +7,8 @@ use soroban_env_host::xdr::{ use soroban_spec::read::FromWasmError; pub use soroban_spec_tools::contract as contract_spec; +use crate::commands::config::{self, locator}; +use crate::commands::network::{self, Network}; use crate::commands::{config::data, global}; use crate::rpc; @@ -22,16 +24,27 @@ pub enum Error { Data(#[from] data::Error), #[error(transparent)] Xdr(#[from] xdr::Error), + #[error(transparent)] + Network(#[from] network::Error), + #[error(transparent)] + Config(#[from] config::Error), } /// /// # Errors pub async fn get_remote_contract_spec( contract_id: &[u8; 32], - rpc_url: &str, + locator: locator::Args, + network: network::Args, global_args: Option<&global::Args>, + config: Option<&config::Args>, ) -> Result, Error> { - let client = rpc::Client::new(rpc_url)?; + fn net(network: network::Args, locator: locator::Args) -> Result { + Ok(network.get(&locator)?) + } + let network = config.map_or_else(|| net(network, locator), |c| Ok(c.get_network()?))?; + tracing::trace!(?network); + let client = rpc::Client::new(&network.rpc_url)?; // Get contract data let r = client.get_contract_data(&contract_id).await?; tracing::trace!("{r:?}");