Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update client URL parsing #293

Merged
merged 2 commits into from
Apr 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 16 additions & 24 deletions fuel-client/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
use cynic::{http::SurfExt, MutationBuilder, Operation, QueryBuilder};
use fuel_vm::prelude::*;
use itertools::Itertools;
use std::{
convert::TryInto,
io, net,
str::{self, FromStr},
};

pub mod schema;
pub mod types;

use anyhow::anyhow;
use schema::{
balance::BalanceArgs,
block::BlockByIdArgs,
Expand All @@ -19,10 +9,19 @@ use schema::{
tx::{TxArg, TxIdArgs},
Bytes, ConversionError, HexString, IdArg, MemoryArgs, RegisterArgs, TransactionId,
};
pub use schema::{PageDirection, PaginatedResult, PaginationRequest};
use std::io::ErrorKind;
use std::{
convert::TryInto,
io::{self, ErrorKind},
net,
str::{self, FromStr},
};
use types::{TransactionResponse, TransactionStatus};

pub use schema::{PageDirection, PaginatedResult, PaginationRequest};

pub mod schema;
pub mod types;

#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct FuelClient {
url: surf::Url,
Expand All @@ -32,14 +31,9 @@ impl FromStr for FuelClient {
type Err = anyhow::Error;

fn from_str(str: &str) -> Result<Self, Self::Err> {
// lightweight url verification
if !str.contains("/graphql") {
Err(anyhow!("Url is missing /graphql path".to_string()))
} else {
Ok(Self {
url: surf::Url::parse(str)?,
})
}
let mut url = surf::Url::parse(str)?;
url.set_path("/graphql");
Ok(Self { url })
}
}

Expand All @@ -48,12 +42,10 @@ where
S: Into<net::SocketAddr>,
{
fn from(socket: S) -> Self {
let url = format!("http://{}/graphql", socket.into())
format!("http://{}", socket.into())
.as_str()
.parse()
.unwrap();

Self { url }
.unwrap()
}
}

Expand Down