diff --git a/crates/env/src/types.rs b/crates/env/src/types.rs index fff2d3a8868..a813d6016ca 100644 --- a/crates/env/src/types.rs +++ b/crates/env/src/types.rs @@ -211,22 +211,19 @@ pub type RentFraction = Perbill; /// This is a mirror of the `AccountId` type used in the default configuration /// of PALLET contracts. #[derive( - Debug, - Copy, - Clone, - PartialEq, - Eq, - Ord, - PartialOrd, - Hash, - Encode, - Decode, - From, - Default, + Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Encode, From, Default, )] #[cfg_attr(feature = "std", derive(TypeInfo))] pub struct AccountId([u8; 32]); +impl Decode for AccountId { + fn decode(input: &mut I) -> Result { + let mut account_id = AccountId { 0: [0; 32] }; + input.read(account_id.0.as_mut_slice())?; + Ok(account_id) + } +} + impl AsRef<[u8; 32]> for AccountId { #[inline] fn as_ref(&self) -> &[u8; 32] { @@ -271,22 +268,19 @@ impl<'a> TryFrom<&'a [u8]> for AccountId { /// This is a mirror of the `Hash` type used in the default configuration /// of PALLET contracts. #[derive( - Debug, - Copy, - Clone, - PartialEq, - Eq, - Ord, - PartialOrd, - Hash, - Encode, - Decode, - From, - Default, + Debug, Copy, Clone, PartialEq, Eq, Ord, PartialOrd, Hash, Encode, From, Default, )] #[cfg_attr(feature = "std", derive(TypeInfo))] pub struct Hash([u8; 32]); +impl Decode for Hash { + fn decode(input: &mut I) -> Result { + let mut hash = Hash { 0: [0; 32] }; + input.read(hash.0.as_mut_slice())?; + Ok(hash) + } +} + impl<'a> TryFrom<&'a [u8]> for Hash { type Error = TryFromSliceError; diff --git a/crates/primitives/src/key.rs b/crates/primitives/src/key.rs index fafb20e4e3a..86ff7d66690 100644 --- a/crates/primitives/src/key.rs +++ b/crates/primitives/src/key.rs @@ -179,8 +179,9 @@ impl scale::Decode for Key { where I: scale::Input, { - let bytes = <[u8; 32] as scale::Decode>::decode(input)?; - Ok(Self::from(bytes)) + let mut key = Key { 0: [0; 32] }; + input.read(key.0.as_mut_slice())?; + Ok(key) } #[inline]