From 8fa285030f16826b21d6aedc3dc8b36a9d78e317 Mon Sep 17 00:00:00 2001 From: lesa-telos Date: Thu, 10 Oct 2024 15:24:00 +0200 Subject: [PATCH] Remove debug flag. --- crates/antelope/src/api/client.rs | 15 -------- crates/antelope/src/api/default_provider.rs | 38 ++++---------------- crates/antelope/tests/client.rs | 4 +-- crates/antelope/tests/utils/mock_provider.rs | 4 --- 4 files changed, 8 insertions(+), 53 deletions(-) diff --git a/crates/antelope/src/api/client.rs b/crates/antelope/src/api/client.rs index 4e1574d..6474281 100644 --- a/crates/antelope/src/api/client.rs +++ b/crates/antelope/src/api/client.rs @@ -29,7 +29,6 @@ impl Display for HTTPMethod { #[async_trait::async_trait] pub trait Provider: Debug + Default + Sync + Send { - fn set_debug(&mut self, debug: bool); async fn post(&self, path: String, body: Option) -> Result; async fn get(&self, path: String) -> Result; } @@ -40,20 +39,6 @@ pub struct APIClient { } impl APIClient

{ - pub fn default_provider(base_url: String) -> Result, String> { - Self::default_provider_debug(base_url, false) - } - - pub fn default_provider_debug( - base_url: String, - debug: bool, - ) -> Result, String> { - let mut provider = DefaultProvider::new(base_url).unwrap(); - provider.set_debug(debug); - - APIClient::custom_provider(provider) - } - pub fn custom_provider(provider: P) -> Result { Ok(APIClient { v1_chain: ChainAPI::new(provider), diff --git a/crates/antelope/src/api/default_provider.rs b/crates/antelope/src/api/default_provider.rs index 76ed9b2..b06e33f 100644 --- a/crates/antelope/src/api/default_provider.rs +++ b/crates/antelope/src/api/default_provider.rs @@ -1,11 +1,10 @@ use crate::api::client::Provider; use reqwest::Client; use std::fmt::{Debug, Formatter}; -use tracing::info; +use tracing::{debug}; #[derive(Default, Clone)] pub struct DefaultProvider { - debug: bool, base_url: String, client: Client, } @@ -25,7 +24,6 @@ impl DefaultProvider { let url = base_url.trim_end_matches('/'); Ok(Self { - debug: false, base_url: String::from(url), client: client.unwrap(), }) @@ -41,10 +39,7 @@ impl Debug for DefaultProvider { #[async_trait::async_trait] impl Provider for DefaultProvider { async fn get(&self, path: String) -> Result { - if self.debug { - info!("GET {}", self.base_url.to_string() + &path); - } - + debug!("GET {}", self.base_url.to_string() + &path); let res = self .client .get(self.base_url.to_string() + &path) @@ -52,18 +47,12 @@ impl Provider for DefaultProvider { .await; if res.is_err() { let res_err = res.err().unwrap().to_string(); - if self.debug { - info!("Error: {}", res_err); - } - + debug!("Error: {}", res_err); return Err(res_err); } let response = res.unwrap().text().await.unwrap(); - if self.debug { - info!("Response: {}", response); - } - + debug!("Response: {}", response); Ok(response) } @@ -71,31 +60,18 @@ impl Provider for DefaultProvider { let mut builder = self.client.post(self.base_url.to_string() + &path); if body.is_some() { let body_str = body.unwrap(); - if self.debug { - info!("POST {} {}", self.base_url.to_string() + &path, body_str); - } - + debug!("POST {} {}", self.base_url.to_string() + &path, body_str); builder = builder.body(body_str); } let res = builder.send().await; if res.is_err() { let err_str = res.err().unwrap().to_string(); - if self.debug { - info!("Error: {}", err_str); - } - + debug!("Error: {}", err_str); return Err(err_str); } let response = res.unwrap().text().await.unwrap(); - if self.debug { - info!("Response: {}", response); - } - + debug!("Response: {}", response); Ok(response) } - - fn set_debug(&mut self, debug: bool) { - self.debug = debug; - } } diff --git a/crates/antelope/tests/client.rs b/crates/antelope/tests/client.rs index d4c4128..cc64201 100644 --- a/crates/antelope/tests/client.rs +++ b/crates/antelope/tests/client.rs @@ -1,6 +1,4 @@ -use tracing::info; -use antelope::api::client::DefaultProvider; -use antelope::api::v1::structs::{ErrorResponse, IndexPosition, TableIndexType}; +use antelope::api::v1::structs::{ErrorResponse}; use antelope::{ api::{ client::APIClient, diff --git a/crates/antelope/tests/utils/mock_provider.rs b/crates/antelope/tests/utils/mock_provider.rs index 3642757..affd7f0 100644 --- a/crates/antelope/tests/utils/mock_provider.rs +++ b/crates/antelope/tests/utils/mock_provider.rs @@ -53,10 +53,6 @@ impl Debug for MockProvider { #[async_trait::async_trait] impl Provider for MockProvider { - fn set_debug(&mut self, debug: bool) { - // TODO: Implement if we want debugging of the mock response in tests - } - async fn post(&self, path: String, body: Option) -> Result { self.call(HTTPMethod::POST, path, body) }