From 9222656871230da29814f4a00372543b566fd169 Mon Sep 17 00:00:00 2001 From: Mattie Conover Date: Thu, 9 Feb 2023 12:16:57 -0800 Subject: [PATCH 1/4] Update debug to be more readable in logs --- ethers-middleware/src/nonce_manager.rs | 7 +++++-- ethers-middleware/src/signer.rs | 2 +- ethers-providers/src/provider.rs | 19 +++++++++++++++++-- ethers-providers/src/transports/http.rs | 8 +++++++- ethers-providers/src/transports/mod.rs | 4 +++- ethers-providers/src/transports/quorum.rs | 2 +- 6 files changed, 34 insertions(+), 8 deletions(-) diff --git a/ethers-middleware/src/nonce_manager.rs b/ethers-middleware/src/nonce_manager.rs index f9e221a0a..50a5ae519 100644 --- a/ethers-middleware/src/nonce_manager.rs +++ b/ethers-middleware/src/nonce_manager.rs @@ -1,17 +1,20 @@ use async_trait::async_trait; use ethers_core::types::{transaction::eip2718::TypedTransaction, *}; use ethers_providers::{FromErr, Middleware, PendingTransaction}; -use std::sync::atomic::{AtomicBool, AtomicU64, Ordering}; +use std::{ + fmt::Debug, + sync::atomic::{AtomicBool, AtomicU64, Ordering}, +}; use thiserror::Error; #[derive(Debug)] /// Middleware used for calculating nonces locally, useful for signing multiple /// consecutive transactions without waiting for them to hit the mempool pub struct NonceManagerMiddleware { - inner: M, initialized: AtomicBool, nonce: AtomicU64, address: Address, + inner: M, } impl NonceManagerMiddleware diff --git a/ethers-middleware/src/signer.rs b/ethers-middleware/src/signer.rs index a6c79e15c..36af4f031 100644 --- a/ethers-middleware/src/signer.rs +++ b/ethers-middleware/src/signer.rs @@ -62,9 +62,9 @@ use thiserror::Error; /// /// [`Signer`]: ethers_signers::Signer pub struct SignerMiddleware { - pub(crate) inner: M, pub(crate) signer: S, pub(crate) address: Address, + pub(crate) inner: M, } impl FromErr for SignerMiddlewareError { diff --git a/ethers-providers/src/provider.rs b/ethers-providers/src/provider.rs index e38464da2..06b0f04cb 100644 --- a/ethers-providers/src/provider.rs +++ b/ethers-providers/src/provider.rs @@ -36,7 +36,12 @@ use url::{ParseError, Url}; use ethers_core::types::Chain; use futures_util::{lock::Mutex, try_join}; use std::{ - collections::VecDeque, convert::TryFrom, fmt::Debug, str::FromStr, sync::Arc, time::Duration, + collections::VecDeque, + convert::TryFrom, + fmt::{Debug, Display}, + str::FromStr, + sync::Arc, + time::Duration, }; use tracing::trace; use tracing_futures::Instrument; @@ -86,7 +91,7 @@ impl FromStr for NodeClient { /// # Ok(()) /// # } /// ``` -#[derive(Clone, Debug)] +#[derive(Clone)] pub struct Provider

{ inner: P, ens: Option

, @@ -110,6 +115,16 @@ impl FromErr for ProviderError { } } +impl Debug for Provider

{ + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "Provider {{ ens: {:?}, interval: {:?}, from: {:?}, inner: {:?} }}", + self.ens, self.interval, self.from, self.inner + ) + } +} + #[derive(Debug, Error)] /// An error thrown when making a call to the provider pub enum ProviderError { diff --git a/ethers-providers/src/transports/http.rs b/ethers-providers/src/transports/http.rs index 976aab648..e697bb896 100644 --- a/ethers-providers/src/transports/http.rs +++ b/ethers-providers/src/transports/http.rs @@ -5,6 +5,7 @@ use async_trait::async_trait; use reqwest::{header::HeaderValue, Client, Error as ReqwestError}; use serde::{de::DeserializeOwned, Serialize}; use std::{ + fmt::Debug, str::FromStr, sync::atomic::{AtomicU64, Ordering}, }; @@ -28,13 +29,18 @@ use super::common::{Authorization, JsonRpcError, Request, Response}; /// # Ok(()) /// # } /// ``` -#[derive(Debug)] pub struct Provider { id: AtomicU64, client: Client, url: Url, } +impl Debug for Provider { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "Http {{ id: {:?}, url: {} }}", self.id, self.url) + } +} + #[derive(Error, Debug)] /// Error thrown when sending an HTTP request pub enum ClientError { diff --git a/ethers-providers/src/transports/mod.rs b/ethers-providers/src/transports/mod.rs index b25190b7c..4ddd7e798 100644 --- a/ethers-providers/src/transports/mod.rs +++ b/ethers-providers/src/transports/mod.rs @@ -33,7 +33,9 @@ mod ws; pub use ws::{ClientError as WsClientError, Ws}; mod quorum; -pub use quorum::{JsonRpcClientWrapper, Quorum, QuorumError, QuorumProvider, WeightedProvider, WrappedParams}; +pub use quorum::{ + JsonRpcClientWrapper, Quorum, QuorumError, QuorumProvider, WeightedProvider, WrappedParams, +}; mod rw; pub use rw::{RwClient, RwClientError}; diff --git a/ethers-providers/src/transports/quorum.rs b/ethers-providers/src/transports/quorum.rs index ef96a0fd7..c564eb1fd 100644 --- a/ethers-providers/src/transports/quorum.rs +++ b/ethers-providers/src/transports/quorum.rs @@ -401,8 +401,8 @@ impl<'a, T> Future for QuorumRequest<'a, T> { /// The configuration of a provider for the `QuorumProvider` #[derive(Debug, Clone)] pub struct WeightedProvider { - inner: T, weight: u64, + inner: T, } impl WeightedProvider { From 93cc31412863a9e5025ba8c7b19ad691eea7d6b1 Mon Sep 17 00:00:00 2001 From: Mattie Conover Date: Thu, 9 Feb 2023 12:21:40 -0800 Subject: [PATCH 2/4] cleanup --- ethers-providers/src/provider.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethers-providers/src/provider.rs b/ethers-providers/src/provider.rs index 06b0f04cb..411635cac 100644 --- a/ethers-providers/src/provider.rs +++ b/ethers-providers/src/provider.rs @@ -38,7 +38,7 @@ use futures_util::{lock::Mutex, try_join}; use std::{ collections::VecDeque, convert::TryFrom, - fmt::{Debug, Display}, + fmt::Debug, str::FromStr, sync::Arc, time::Duration, From 502440e05935545832d850a35a5b0b0bca9922dc Mon Sep 17 00:00:00 2001 From: Mattie Conover Date: Thu, 9 Feb 2023 14:36:19 -0800 Subject: [PATCH 3/4] Address display --- ethers-core/src/types/address_or_bytes.rs | 12 +++++++++++- ethers-core/src/types/ens.rs | 13 +++++++++++-- ethers-providers/src/provider.rs | 7 +------ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/ethers-core/src/types/address_or_bytes.rs b/ethers-core/src/types/address_or_bytes.rs index c9112c1e2..b37aad3fa 100644 --- a/ethers-core/src/types/address_or_bytes.rs +++ b/ethers-core/src/types/address_or_bytes.rs @@ -1,6 +1,7 @@ use crate::types::{Address, Bytes}; +use std::fmt::Debug; -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq)] /// A type that can either be an `Address` or `Bytes`. pub enum AddressOrBytes { /// An address type @@ -9,6 +10,15 @@ pub enum AddressOrBytes { Bytes(Bytes), } +impl Debug for AddressOrBytes { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + AddressOrBytes::Address(addr) => write!(f, "{addr:?}"), + AddressOrBytes::Bytes(bytes) => write!(f, "0x{}", hex::encode(bytes)), + } + } +} + impl From

for AddressOrBytes { fn from(s: Address) -> Self { Self::Address(s) diff --git a/ethers-core/src/types/ens.rs b/ethers-core/src/types/ens.rs index 1ba9869f8..2407f44d8 100644 --- a/ethers-core/src/types/ens.rs +++ b/ethers-core/src/types/ens.rs @@ -1,10 +1,10 @@ use crate::types::Address; use rlp::{Decodable, Encodable, RlpStream}; use serde::{ser::Error as SerializationError, Deserialize, Deserializer, Serialize, Serializer}; -use std::{cmp::Ordering, convert::Infallible, str::FromStr}; +use std::{cmp::Ordering, convert::Infallible, fmt::Debug, str::FromStr}; /// ENS name or Ethereum Address. Not RLP encoded/serialized if it's a name. -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq)] pub enum NameOrAddress { /// An ENS Name (format does not get checked) Name(String), @@ -12,6 +12,15 @@ pub enum NameOrAddress { Address(Address), } +impl Debug for NameOrAddress { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + NameOrAddress::Name(name) => write!(f, "{name}"), + NameOrAddress::Address(addr) => write!(f, "{addr:?}"), + } + } +} + // Only RLP encode the Address variant since it doesn't make sense to ever RLP encode // an ENS name impl Encodable for &NameOrAddress { diff --git a/ethers-providers/src/provider.rs b/ethers-providers/src/provider.rs index 411635cac..ff4eb8b31 100644 --- a/ethers-providers/src/provider.rs +++ b/ethers-providers/src/provider.rs @@ -36,12 +36,7 @@ use url::{ParseError, Url}; use ethers_core::types::Chain; use futures_util::{lock::Mutex, try_join}; use std::{ - collections::VecDeque, - convert::TryFrom, - fmt::Debug, - str::FromStr, - sync::Arc, - time::Duration, + collections::VecDeque, convert::TryFrom, fmt::Debug, str::FromStr, sync::Arc, time::Duration, }; use tracing::trace; use tracing_futures::Instrument; From 80eecd4a25e7d756b4ca369e65530654e40bc739 Mon Sep 17 00:00:00 2001 From: Mattie Conover Date: Thu, 9 Feb 2023 14:37:20 -0800 Subject: [PATCH 4/4] ens display --- ethers-core/src/types/ens.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ethers-core/src/types/ens.rs b/ethers-core/src/types/ens.rs index 2407f44d8..046594919 100644 --- a/ethers-core/src/types/ens.rs +++ b/ethers-core/src/types/ens.rs @@ -15,7 +15,7 @@ pub enum NameOrAddress { impl Debug for NameOrAddress { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - NameOrAddress::Name(name) => write!(f, "{name}"), + NameOrAddress::Name(name) => write!(f, "\"{name}\""), NameOrAddress::Address(addr) => write!(f, "{addr:?}"), } }