diff --git a/Cargo.lock b/Cargo.lock index 441d72d8d..84912b376 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1628,6 +1628,15 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-src" +version = "111.27.0+1.1.1v" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06e8f197c82d7511c5b014030c9b1efeda40d7d5f99d23b4ceed3524a5e63f02" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.90" @@ -1636,6 +1645,7 @@ checksum = "374533b0e45f3a7ced10fcaeccca020e66656bc03dac384f852e4e5a7a8104a6" dependencies = [ "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] @@ -2443,6 +2453,7 @@ dependencies = [ "jsonrpsee-core", "jsonrpsee-http-client", "num-bigint", + "openssl", "pathdiff", "predicates 2.1.5", "rand 0.8.5", diff --git a/cmd/soroban-cli/Cargo.toml b/cmd/soroban-cli/Cargo.toml index 1179a2c66..484c4a2ad 100644 --- a/cmd/soroban-cli/Cargo.toml +++ b/cmd/soroban-cli/Cargo.toml @@ -91,6 +91,8 @@ tracing-appender = { workspace = true } tracing-subscriber = { workspace = true, features = ["env-filter"] } cargo_metadata = "0.15.4" pathdiff = "0.2.1" +# For hyper-tls +openssl = { version = "0.10.55", features = ["vendored"] } [build-dependencies] crate-git-revision = "0.0.4" diff --git a/cmd/soroban-cli/src/commands/config/network/mod.rs b/cmd/soroban-cli/src/commands/config/network/mod.rs index 85bab15aa..0f6928881 100644 --- a/cmd/soroban-cli/src/commands/config/network/mod.rs +++ b/cmd/soroban-cli/src/commands/config/network/mod.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use stellar_strkey::ed25519::PublicKey; -use crate::{commands::HEADING_RPC, rpc}; +use crate::{commands::HEADING_RPC, rpc::{self, Client}}; use super::locator; @@ -81,14 +81,6 @@ pub struct Args { help_heading = HEADING_RPC, )] pub network_passphrase: Option, - /// Helper URL to use for funding accounts on test networks - #[arg( - long = "helper-url", - requires = "rpc_url", - env = "SOROBAN_NETWORK_PASSPHRASE", - help_heading = HEADING_RPC, - )] - pub helper_url: Option, /// Name of network to use from config #[arg( long, @@ -110,7 +102,6 @@ impl Args { Ok(Network { rpc_url, network_passphrase, - helper_url: self.helper_url.clone(), }) } else { Err(Error::Network) @@ -139,34 +130,21 @@ pub struct Network { help_heading = HEADING_RPC, )] pub network_passphrase: String, - - /// Network passphrase to sign the transaction sent to the rpc server - #[arg( - long, - env = "SOROBAN_HELPER_URL", - help_heading = HEADING_RPC, - )] - pub helper_url: Option, } impl Network { - pub fn helper_url(&self, addr: &str) -> Result { + pub async fn helper_url(&self, addr: &str) -> Result { tracing::debug!("address {addr:?}"); - let (url_root, path) = if let Some(helper_url) = &self.helper_url { - (helper_url, "") - } else { - (&self.rpc_url, "/friendbot") - }; - tracing::debug!("helper url {url_root:?}\npath: {path:?}"); - let uri = - http::Uri::from_str(url_root).map_err(|_| Error::InvalidUrl(url_root.to_string()))?; + let client = Client::new(&self.rpc_url)?; + let helper_url_root = client.friendbot_url().await?; + let uri = http::Uri::from_str(&helper_url_root).map_err(|_|Error::InvalidUrl(helper_url_root.to_string()))?; http::Uri::from_str(&format!("{uri:?}?addr={addr}")) - .map_err(|_| Error::InvalidUrl(url_root.to_string())) + .map_err(|_| Error::InvalidUrl(helper_url_root.to_string())) } #[allow(clippy::similar_names)] pub async fn fund_address(&self, addr: &PublicKey) -> Result<(), Error> { - let uri = self.helper_url(&addr.to_string())?; + let uri = self.helper_url(&addr.to_string()).await?; tracing::debug!("URL {uri:?}"); let response = match uri.scheme_str() { Some("http") => hyper::Client::new().get(uri.clone()).await?, @@ -200,8 +178,7 @@ impl Network { pub fn futurenet() -> Self { Network { rpc_url: "https://rpc-futurenet.stellar.org:443".to_owned(), - network_passphrase: "Test SDF Future Network ; October 2022".to_owned(), - helper_url: Some("https://friendbot-futurenet.stellar.org".to_owned()), + network_passphrase: "Test SDF Future Network ; October 2022".to_owned() } } } diff --git a/cmd/soroban-cli/src/rpc/mod.rs b/cmd/soroban-cli/src/rpc/mod.rs index b5a4f96d7..9bf0796cf 100644 --- a/cmd/soroban-cli/src/rpc/mod.rs +++ b/cmd/soroban-cli/src/rpc/mod.rs @@ -427,6 +427,17 @@ impl Client { .build(url)?) } + pub async fn friendbot_url(&self) -> Result { + let network = self.get_network().await?; + tracing::trace!("{network:#?}"); + network.friendbot_url.ok_or_else(|| { + Error::NotFound( + "Friendbot".to_string(), + "Friendbot is not available on this network".to_string(), + ) + }) + } + pub async fn verify_network_passphrase(&self, expected: Option<&str>) -> Result { let server = self.get_network().await?.passphrase; if expected.is_some() && expected != Some(&server) {