Skip to content

Commit 63dbc74

Browse files
committed
Remove unnecessary bounds on IdentityField
Signed-off-by: georgepisaltu <[email protected]>
1 parent a51abc4 commit 63dbc74

File tree

2 files changed

+7
-48
lines changed

2 files changed

+7
-48
lines changed

substrate/frame/identity/src/simple.rs

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::types::{Data, IdentityFields, IdentityInformationProvider, U64BitFlag
2828
/// in the `IdentityInfo` struct.
2929
#[bitflags]
3030
#[repr(u64)]
31-
#[derive(MaxEncodedLen, Clone, Copy, PartialEq, Eq, RuntimeDebug)]
31+
#[derive(Clone, Copy, PartialEq, Eq, RuntimeDebug)]
3232
pub enum IdentityField {
3333
Display = 1u64 << 0,
3434
Legal = 1u64 << 1,
@@ -58,38 +58,6 @@ impl TypeInfo for IdentityField {
5858
}
5959
}
6060

61-
impl Encode for IdentityField {
62-
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
63-
let x: u8 = match self {
64-
IdentityField::Display => 0,
65-
IdentityField::Legal => 1,
66-
IdentityField::Web => 2,
67-
IdentityField::Riot => 3,
68-
IdentityField::Email => 4,
69-
IdentityField::PgpFingerprint => 5,
70-
IdentityField::Image => 6,
71-
IdentityField::Twitter => 7,
72-
};
73-
f(&x.encode())
74-
}
75-
}
76-
77-
impl Decode for IdentityField {
78-
fn decode<I: codec::Input>(input: &mut I) -> Result<Self, codec::Error> {
79-
match u8::decode(input) {
80-
Ok(0) => Ok(IdentityField::Display),
81-
Ok(1) => Ok(IdentityField::Legal),
82-
Ok(2) => Ok(IdentityField::Web),
83-
Ok(3) => Ok(IdentityField::Riot),
84-
Ok(4) => Ok(IdentityField::Email),
85-
Ok(5) => Ok(IdentityField::PgpFingerprint),
86-
Ok(6) => Ok(IdentityField::Image),
87-
Ok(7) => Ok(IdentityField::Twitter),
88-
_ => Err("Invalid IdentityField representation".into()),
89-
}
90-
}
91-
}
92-
9361
impl U64BitFlag for IdentityField {}
9462

9563
/// Information concerning the identity of the controller of an account.

substrate/frame/identity/src/types.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -236,15 +236,7 @@ pub trait IdentityInformationProvider:
236236
{
237237
/// Type capable of representing all of the fields present in the identity information as bit
238238
/// flags in `u64` format.
239-
type IdentityField: Encode
240-
+ Decode
241-
+ MaxEncodedLen
242-
+ Clone
243-
+ Debug
244-
+ Eq
245-
+ PartialEq
246-
+ TypeInfo
247-
+ U64BitFlag;
239+
type IdentityField: Clone + Debug + Eq + PartialEq + TypeInfo + U64BitFlag;
248240

249241
fn has_identity(&self, fields: u64) -> bool;
250242
#[cfg(feature = "runtime-benchmarks")]
@@ -292,7 +284,7 @@ impl<
292284
pub struct RegistrarInfo<
293285
Balance: Encode + Decode + Clone + Debug + Eq + PartialEq,
294286
AccountId: Encode + Decode + Clone + Debug + Eq + PartialEq,
295-
IdField: Encode + Decode + MaxEncodedLen + Clone + Debug + Eq + PartialEq + TypeInfo + U64BitFlag,
287+
IdField: Clone + Debug + Eq + PartialEq + TypeInfo + U64BitFlag,
296288
> {
297289
/// The account of the registrar.
298290
pub account: AccountId,
@@ -325,21 +317,20 @@ where
325317
}
326318

327319
impl<IdField: U64BitFlag + PartialEq> Eq for IdentityFields<IdField> {}
328-
impl<IdField: Encode + Decode + U64BitFlag> Encode for IdentityFields<IdField> {
320+
impl<IdField: U64BitFlag> Encode for IdentityFields<IdField> {
329321
fn using_encoded<R, F: FnOnce(&[u8]) -> R>(&self, f: F) -> R {
330322
let bits: u64 = self.0.bits();
331323
bits.using_encoded(f)
332324
}
333325
}
334-
impl<IdField: Encode + Decode + U64BitFlag> Decode for IdentityFields<IdField> {
326+
impl<IdField: U64BitFlag> Decode for IdentityFields<IdField> {
335327
fn decode<I: codec::Input>(input: &mut I) -> sp_std::result::Result<Self, codec::Error> {
336328
let field = u64::decode(input)?;
337329
Ok(Self(<BitFlags<IdField>>::from_bits(field).map_err(|_| "invalid value")?))
338330
}
339331
}
340-
impl<
341-
IdField: Encode + Decode + MaxEncodedLen + Clone + Debug + Eq + PartialEq + TypeInfo + U64BitFlag,
342-
> TypeInfo for IdentityFields<IdField>
332+
impl<IdField: Clone + Debug + Eq + PartialEq + TypeInfo + U64BitFlag> TypeInfo
333+
for IdentityFields<IdField>
343334
{
344335
type Identity = Self;
345336

0 commit comments

Comments
 (0)