From 04de9120e15da47320f27340d41f2dc2122cd674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Fri, 21 Jan 2022 20:21:36 +0100 Subject: [PATCH] Remove some last `AccountId32::default()` leftovers (#10655) * Remove some last `AccountId32::default()` leftovers As we removed `Default` of account id, we have overseen some last bits. This pr removes these last bits. * Fix --- frame/collective/src/lib.rs | 7 +++++-- primitives/core/src/crypto.rs | 10 ++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/frame/collective/src/lib.rs b/frame/collective/src/lib.rs index 3e3b923d6ee37..49328aa0bdc68 100644 --- a/frame/collective/src/lib.rs +++ b/frame/collective/src/lib.rs @@ -990,8 +990,8 @@ where pub struct EnsureMember(PhantomData<(AccountId, I)>); impl< O: Into, O>> + From>, - AccountId: Default, I, + AccountId: Decode, > EnsureOrigin for EnsureMember { type Success = AccountId; @@ -1004,7 +1004,10 @@ impl< #[cfg(feature = "runtime-benchmarks")] fn successful_origin() -> O { - O::from(RawOrigin::Member(Default::default())) + let zero_account_id = + AccountId::decode(&mut sp_runtime::traits::TrailingZeroInput::zeroes()) + .expect("infinite length input; no invalid inputs for type; qed"); + O::from(RawOrigin::Member(zero_account_id)) } } diff --git a/primitives/core/src/crypto.rs b/primitives/core/src/crypto.rs index 41ee9466ad93b..12f8397eee4a4 100644 --- a/primitives/core/src/crypto.rs +++ b/primitives/core/src/crypto.rs @@ -478,9 +478,7 @@ pub trait Public: ByteArray + Derive + CryptoType + PartialEq + Eq + Clone + Sen } /// An opaque 32-byte cryptographic identifier. -#[derive( - Clone, Eq, PartialEq, Ord, PartialOrd, Default, Encode, Decode, MaxEncodedLen, TypeInfo, -)] +#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, MaxEncodedLen, TypeInfo)] #[cfg_attr(feature = "std", derive(Hash))] pub struct AccountId32([u8; 32]); @@ -541,9 +539,9 @@ impl<'a> sp_std::convert::TryFrom<&'a [u8]> for AccountId32 { type Error = (); fn try_from(x: &'a [u8]) -> Result { if x.len() == 32 { - let mut r = AccountId32::default(); - r.0.copy_from_slice(x); - Ok(r) + let mut data = [0; 32]; + data.copy_from_slice(x); + Ok(AccountId32(data)) } else { Err(()) }