Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 18 additions & 24 deletions crates/env/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<I: scale::Input>(input: &mut I) -> Result<Self, scale::Error> {
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] {
Expand Down Expand Up @@ -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<I: scale::Input>(input: &mut I) -> Result<Self, scale::Error> {
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;

Expand Down
5 changes: 3 additions & 2 deletions crates/primitives/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down