From 7bbdcca49a473b9f99bcae34ed6c4256598c16ea Mon Sep 17 00:00:00 2001 From: pgherveou Date: Thu, 18 Jan 2024 20:22:58 +0100 Subject: [PATCH 1/4] better debugging for accountid32 in debug build --- substrate/primitives/core/src/crypto.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index 2da38d44be4b..db4dbfc558df 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -593,13 +593,13 @@ impl std::fmt::Display for AccountId32 { } impl sp_std::fmt::Debug for AccountId32 { - #[cfg(feature = "std")] + #[cfg(any(feature = "std", debug_assertions))] fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result { let s = self.to_ss58check(); write!(f, "{} ({}...)", crate::hexdisplay::HexDisplay::from(&self.0), &s[0..8]) } - #[cfg(not(feature = "std"))] + #[cfg(not(any(feature = "std", debug_assertions)))] fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result { Ok(()) } From 6e85687de096ba9acdbe7b12fdf90aefadaa8360 Mon Sep 17 00:00:00 2001 From: PG Herveou Date: Thu, 18 Jan 2024 23:11:53 +0100 Subject: [PATCH 2/4] Fix --- substrate/primitives/core/src/crypto.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index db4dbfc558df..c74c88b73ee9 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -593,13 +593,13 @@ impl std::fmt::Display for AccountId32 { } impl sp_std::fmt::Debug for AccountId32 { - #[cfg(any(feature = "std", debug_assertions))] + #[cfg(any(feature = "std", all(debug_assertions, feature = "serde")))] fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result { let s = self.to_ss58check(); write!(f, "{} ({}...)", crate::hexdisplay::HexDisplay::from(&self.0), &s[0..8]) } - #[cfg(not(any(feature = "std", debug_assertions)))] + #[cfg(not(any(feature = "std", all(debug_assertions, feature = "serde"))))] fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result { Ok(()) } From 495f7cc629d6d4ea9f32cf159ff56fbd64c25046 Mon Sep 17 00:00:00 2001 From: PG Herveou Date: Thu, 18 Jan 2024 23:58:12 +0100 Subject: [PATCH 3/4] fix --- substrate/primitives/core/src/crypto.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index c74c88b73ee9..0e00b0faf58a 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -593,13 +593,21 @@ impl std::fmt::Display for AccountId32 { } impl sp_std::fmt::Debug for AccountId32 { - #[cfg(any(feature = "std", all(debug_assertions, feature = "serde")))] + #[cfg(any(feature = "std", debug_assertions))] fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result { - let s = self.to_ss58check(); - write!(f, "{} ({}...)", crate::hexdisplay::HexDisplay::from(&self.0), &s[0..8]) + #[cfg(feature = "serde")] + { + let s = self.to_ss58check(); + write!(f, "{} ({}...)", crate::hexdisplay::HexDisplay::from(&self.0), &s[0..8])?; + } + + #[cfg(not(feature = "serde"))] + write!(f, "{}", crate::hexdisplay::HexDisplay::from(&self.0))?; + + Ok(()) } - #[cfg(not(any(feature = "std", all(debug_assertions, feature = "serde"))))] + #[cfg(not(any(feature = "std", debug_assertions)))] fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result { Ok(()) } From e40e9a26bbd2b46134b99782cf1c166ac5bb0ba3 Mon Sep 17 00:00:00 2001 From: pgherveou Date: Fri, 19 Jan 2024 13:36:38 +0100 Subject: [PATCH 4/4] Same impl for release / debug build --- substrate/primitives/core/src/crypto.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/substrate/primitives/core/src/crypto.rs b/substrate/primitives/core/src/crypto.rs index 0e00b0faf58a..58d8616368eb 100644 --- a/substrate/primitives/core/src/crypto.rs +++ b/substrate/primitives/core/src/crypto.rs @@ -593,7 +593,6 @@ impl std::fmt::Display for AccountId32 { } impl sp_std::fmt::Debug for AccountId32 { - #[cfg(any(feature = "std", debug_assertions))] fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result { #[cfg(feature = "serde")] { @@ -606,11 +605,6 @@ impl sp_std::fmt::Debug for AccountId32 { Ok(()) } - - #[cfg(not(any(feature = "std", debug_assertions)))] - fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result { - Ok(()) - } } #[cfg(feature = "serde")]