From e6c6ee2550d52e43bdfc942b5657b8ef0d52c459 Mon Sep 17 00:00:00 2001 From: Brandon Kite Date: Thu, 14 Apr 2022 22:45:00 -0700 Subject: [PATCH 1/2] allow fuel-client to use strings as url's instead of socket addr in order to support https endpoints --- Cargo.lock | 1 + fuel-client/Cargo.toml | 1 + fuel-client/src/client.rs | 14 +++++++++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 18af12d8d47..fb0cada5f73 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2051,6 +2051,7 @@ dependencies = [ name = "fuel-gql-client" version = "0.5.0" dependencies = [ + "anyhow", "chrono", "clap 3.1.2", "cynic", diff --git a/fuel-client/Cargo.toml b/fuel-client/Cargo.toml index 6ff7a8b169c..fd4ee6325fa 100644 --- a/fuel-client/Cargo.toml +++ b/fuel-client/Cargo.toml @@ -15,6 +15,7 @@ name = "fuel-gql-cli" path = "src/main.rs" [dependencies] +anyhow = "1.0" chrono = { version = "0.4", features = ["serde"] } clap = { version = "3.1", features = ["derive"] } cynic = { version = "0.14", features = ["surf"] } diff --git a/fuel-client/src/client.rs b/fuel-client/src/client.rs index 993b5507d1e..0e62fe2d781 100644 --- a/fuel-client/src/client.rs +++ b/fuel-client/src/client.rs @@ -10,6 +10,7 @@ use std::{ pub mod schema; pub mod types; +use anyhow::anyhow; use schema::{ balance::BalanceArgs, block::BlockByIdArgs, @@ -28,10 +29,17 @@ pub struct FuelClient { } impl FromStr for FuelClient { - type Err = net::AddrParseError; + type Err = anyhow::Error; fn from_str(str: &str) -> Result { - str.parse().map(|s: net::SocketAddr| s.into()) + // lightweight url verification + if !str.contains("/graphql") { + Err(anyhow!("Url is missing /graphql path".to_string())) + } else { + Ok(Self { + url: surf::Url::parse(&str)?, + }) + } } } @@ -50,7 +58,7 @@ where } impl FuelClient { - pub fn new(url: impl AsRef) -> Result { + pub fn new(url: impl AsRef) -> Result { Self::from_str(url.as_ref()) } From cfb8d561c57d0509ea06d413535eefec1f1ce58b Mon Sep 17 00:00:00 2001 From: Brandon Kite Date: Thu, 14 Apr 2022 23:01:21 -0700 Subject: [PATCH 2/2] clippy --- fuel-client/src/client.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fuel-client/src/client.rs b/fuel-client/src/client.rs index 0e62fe2d781..b5833915871 100644 --- a/fuel-client/src/client.rs +++ b/fuel-client/src/client.rs @@ -37,7 +37,7 @@ impl FromStr for FuelClient { Err(anyhow!("Url is missing /graphql path".to_string())) } else { Ok(Self { - url: surf::Url::parse(&str)?, + url: surf::Url::parse(str)?, }) } }