Browse Source

Refactoring: remove debug trait inheritance

iorveth 4 years ago
parent
commit
1f9b8c9140

+ 16 - 1
Cargo.lock

@@ -3274,6 +3274,21 @@ dependencies = [
  "sp-runtime",
 ]
 
+[[package]]
+name = "pallet-content-directory"
+version = "3.0.0"
+dependencies = [
+ "frame-support",
+ "frame-system",
+ "parity-scale-codec",
+ "serde",
+ "sp-arithmetic",
+ "sp-core",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+]
+
 [[package]]
 name = "pallet-content-working-group"
 version = "3.0.0"
@@ -7796,4 +7811,4 @@ dependencies = [
  "quote 1.0.7",
  "syn 1.0.17",
  "synstructure",
-]
+]

+ 1 - 1
runtime-modules/content-directory/src/lib.rs

@@ -162,7 +162,7 @@ use core::debug_assert;
 type MaxNumber = u32;
 
 /// Module configuration trait for this Substrate module.
-pub trait Trait: system::Trait + ActorAuthenticator + Debug + Clone {
+pub trait Trait: system::Trait + ActorAuthenticator + Clone {
     /// The overarching event type.
     type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
 

+ 49 - 7
runtime-modules/content-directory/src/operations.rs

@@ -4,7 +4,7 @@ use sp_std::collections::btree_map::BTreeMap;
 use sp_std::prelude::*;
 
 /// Parametrized entity property value
-#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)]
+#[derive(Encode, Decode, Eq, PartialEq, Clone)]
 pub enum ParametrizedPropertyValue<T: Trait> {
     /// Same fields as normal InputPropertyValue
     InputPropertyValue(InputPropertyValue<T>),
@@ -16,15 +16,27 @@ pub enum ParametrizedPropertyValue<T: Trait> {
     InternalEntityVec(Vec<ParameterizedEntity<T>>),
 }
 
+impl<T: Trait> core::fmt::Debug for ParametrizedPropertyValue<T> {
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(formatter, "ParametrizedPropertyValue {:?}", self)
+    }
+}
+
 /// Parametrized entity
-#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)]
+#[derive(Encode, Decode, Eq, PartialEq, Clone)]
 pub enum ParameterizedEntity<T: Trait> {
     InternalEntityJustAdded(u32),
     ExistingEntity(T::EntityId),
 }
 
+impl<T: Trait> core::fmt::Debug for ParameterizedEntity<T> {
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(formatter, "ParameterizedEntity {:?}", self)
+    }
+}
+
 /// Parametrized class property value
-#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)]
+#[derive(Encode, Decode, Eq, PartialEq, Clone)]
 pub struct ParametrizedClassPropertyValue<T: Trait> {
     /// Index is into properties vector of class.
     pub in_class_index: PropertyId,
@@ -33,15 +45,27 @@ pub struct ParametrizedClassPropertyValue<T: Trait> {
     pub value: ParametrizedPropertyValue<T>,
 }
 
+impl<T: Trait> core::fmt::Debug for ParametrizedClassPropertyValue<T> {
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(formatter, "ParametrizedClassPropertyValue {:?}", self)
+    }
+}
+
 /// Operation, that represents `Entity` creation
-#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)]
+#[derive(Encode, Decode, Eq, PartialEq, Clone)]
 pub struct CreateEntityOperation<T: Trait> {
     /// Class of an Entity
     pub class_id: T::ClassId,
 }
 
+impl<T: Trait> core::fmt::Debug for CreateEntityOperation<T> {
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(formatter, "CreateEntityOperation {:?}", self)
+    }
+}
+
 /// Operation, that represents property values update
-#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)]
+#[derive(Encode, Decode, Eq, PartialEq, Clone)]
 pub struct UpdatePropertyValuesOperation<T: Trait> {
     /// Entity id to perfrom operation
     pub entity_id: ParameterizedEntity<T>,
@@ -49,8 +73,14 @@ pub struct UpdatePropertyValuesOperation<T: Trait> {
     pub new_parametrized_property_values: Vec<ParametrizedClassPropertyValue<T>>,
 }
 
+impl<T: Trait> core::fmt::Debug for UpdatePropertyValuesOperation<T> {
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(formatter, "UpdatePropertyValuesOperation {:?}", self)
+    }
+}
+
 /// Operation, that represents adding `Entity` `Schema` support
-#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)]
+#[derive(Encode, Decode, Eq, PartialEq, Clone)]
 pub struct AddSchemaSupportToEntityOperation<T: Trait> {
     /// Entity id to perfrom operation
     pub entity_id: ParameterizedEntity<T>,
@@ -60,14 +90,26 @@ pub struct AddSchemaSupportToEntityOperation<T: Trait> {
     pub parametrized_property_values: Vec<ParametrizedClassPropertyValue<T>>,
 }
 
+impl<T: Trait> core::fmt::Debug for AddSchemaSupportToEntityOperation<T> {
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(formatter, "AddSchemaSupportToEntityOperation {:?}", self)
+    }
+}
+
 /// The type of operation performed
-#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)]
+#[derive(Encode, Decode, Eq, PartialEq, Clone)]
 pub enum OperationType<T: Trait> {
     CreateEntity(CreateEntityOperation<T>),
     UpdatePropertyValues(UpdatePropertyValuesOperation<T>),
     AddSchemaSupportToEntity(AddSchemaSupportToEntityOperation<T>),
 }
 
+impl<T: Trait> core::fmt::Debug for OperationType<T> {
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(formatter, "OperationType {:?}", self)
+    }
+}
+
 /// Retrieve entity_id of parametrized `Entity`
 pub fn parametrized_entity_to_entity_id<T: Trait>(
     created_entities: &BTreeMap<usize, T::EntityId>,

+ 8 - 2
runtime-modules/content-directory/src/permissions.rs

@@ -19,7 +19,7 @@ use sp_arithmetic::traits::BaseArithmetic;
 use sp_runtime::traits::{MaybeSerializeDeserialize, Member};
 
 /// Model of authentication manager.
-pub trait ActorAuthenticator: system::Trait + Debug {
+pub trait ActorAuthenticator: system::Trait {
     /// Curator identifier
     type CuratorId: Parameter
         + Member
@@ -108,7 +108,7 @@ pub fn ensure_is_lead<T: Trait>(origin: T::Origin) -> DispatchResult {
 
 /// Enum, representing all possible `Actor`s
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Eq, PartialEq, Clone, Copy, Debug)]
+#[derive(Encode, Decode, Eq, PartialEq, Clone, Copy)]
 pub enum Actor<T: Trait> {
     Curator(T::CuratorGroupId, T::CuratorId),
     Member(T::MemberId),
@@ -120,3 +120,9 @@ impl<T: Trait> Default for Actor<T> {
         Self::Lead
     }
 }
+
+impl<T: Trait> core::fmt::Debug for Actor<T> {
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(formatter, "Actor {:?}", self)
+    }
+}

+ 8 - 1
runtime-modules/content-directory/src/permissions/class.rs

@@ -2,7 +2,7 @@ use super::*;
 
 /// Permissions for an instance of a `Class` in the versioned store.
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)]
+#[derive(Encode, Decode, Eq, PartialEq, Clone)]
 pub struct ClassPermissions<T: Trait> {
     /// For this permission, the individual member is allowed to create the entity and become controller.
     any_member: bool,
@@ -23,6 +23,13 @@ pub struct ClassPermissions<T: Trait> {
     maintainers: BTreeSet<T::CuratorGroupId>,
 }
 
+impl<T: Trait> core::fmt::Debug for ClassPermissions<T> {
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(formatter, "ClassPermissions {{ any_member {:?}, entity_creation_blocked {:?}, all_entity_property_values_locked {:?}, maintainers {:?} }}",
+         self.any_member, self.entity_creation_blocked, self.all_entity_property_values_locked, self.maintainers)
+    }
+}
+
 impl<T: Trait> Default for ClassPermissions<T> {
     fn default() -> Self {
         Self {

+ 7 - 1
runtime-modules/content-directory/src/permissions/entity.rs

@@ -2,7 +2,7 @@ use super::*;
 
 /// Owner of an `Entity`.
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, Debug)]
+#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq)]
 pub enum EntityController<T: Trait> {
     Maintainers,
     Member(T::MemberId),
@@ -26,6 +26,12 @@ impl<T: Trait> Default for EntityController<T> {
     }
 }
 
+impl<T: Trait> core::fmt::Debug for EntityController<T> {
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(formatter, "EntityController {:?}", self)
+    }
+}
+
 /// Permissions for a given entity.
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
 #[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]

+ 28 - 4
runtime-modules/content-directory/src/schema.rs

@@ -42,7 +42,7 @@ pub struct PropertyLockingPolicy {
 
 /// Enum, used for `PropertyType` representation
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, Debug)]
+#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq)]
 pub enum Type<T: Trait> {
     Bool,
     Uint16,
@@ -58,6 +58,12 @@ pub enum Type<T: Trait> {
     Reference(T::ClassId, SameController),
 }
 
+impl<T: Trait> core::fmt::Debug for Type<T> {
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(formatter, "Type {:?}", self)
+    }
+}
+
 impl<T: Trait> Default for Type<T> {
     fn default() -> Self {
         Self::Bool
@@ -87,7 +93,7 @@ impl<T: Trait> Type<T> {
 
 /// Vector property type representation
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, Debug)]
+#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq)]
 pub struct VecPropertyType<T: Trait> {
     vec_type: Type<T>,
     /// Max length of vector, corresponding to a given type
@@ -103,6 +109,12 @@ impl<T: Trait> Default for VecPropertyType<T> {
     }
 }
 
+impl<T: Trait> core::fmt::Debug for VecPropertyType<T> {
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(formatter, "VecPropertyType {:?}", self)
+    }
+}
+
 impl<T: Trait> VecPropertyType<T> {
     /// Create new `VecPropertyType` from provided `type` and `max_length`
     pub fn new(vec_type: Type<T>, max_length: VecMaxLength) -> Self {
@@ -135,12 +147,18 @@ impl<T: Trait> VecPropertyType<T> {
 
 /// Enum, representing either `Type` or `VecPropertyType`
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, Debug)]
+#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq)]
 pub enum PropertyType<T: Trait> {
     Single(Type<T>),
     Vector(VecPropertyType<T>),
 }
 
+impl<T: Trait> core::fmt::Debug for PropertyType<T> {
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(formatter, "Type {:?}", self)
+    }
+}
+
 impl<T: Trait> Default for PropertyType<T> {
     fn default() -> Self {
         Self::Single(Type::default())
@@ -257,7 +275,7 @@ impl Schema {
 
 /// `Property` representation, related to a given `Class`
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
+#[derive(Encode, Decode, Clone, PartialEq, Eq)]
 pub struct Property<T: Trait> {
     /// The type of `Property`
     pub property_type: PropertyType<T>,
@@ -286,6 +304,12 @@ impl<T: Trait> Default for Property<T> {
     }
 }
 
+impl<T: Trait> core::fmt::Debug for Property<T> {
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(formatter, "Property {:?}", self)
+    }
+}
+
 impl<T: Trait> Property<T> {
     /// Check if property is locked from actor with provided `EntityAccessLevel`
     pub fn is_locked_from(&self, access_level: EntityAccessLevel) -> bool {

+ 67 - 3
runtime-modules/content-directory/src/schema/input.rs

@@ -2,12 +2,18 @@ use super::*;
 
 /// Enum, representing either `SingleInputPropertyValue` or `VecInputPropertyValue`
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
+#[derive(Encode, Decode, Clone, PartialEq, Eq)]
 pub enum InputPropertyValue<T: Trait> {
     Single(InputValue<T>),
     Vector(VecInputValue<T>),
 }
 
+impl<T: Trait> core::fmt::Debug for InputPropertyValue<T> {
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(formatter, "InputPropertyValue {{{:?}}}", self)
+    }
+}
+
 impl<T: Trait> InputPropertyValue<T> {
     pub fn as_single_value(&self) -> Option<&InputValue<T>> {
         if let InputPropertyValue::Single(single_value) = self {
@@ -58,7 +64,7 @@ impl<T: Trait> Default for InputPropertyValue<T> {
 
 /// InputValue enum representation, related to corresponding `SingleInputPropertyValue` structure
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
+#[derive(Encode, Decode, Clone, PartialEq, Eq)]
 pub enum InputValue<T: Trait> {
     Bool(bool),
     Uint16(u16),
@@ -73,6 +79,27 @@ pub enum InputValue<T: Trait> {
     Reference(T::EntityId),
 }
 
+impl<T: Trait> core::fmt::Debug for InputValue<T> {
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        match self {
+            InputValue::Bool(value) => write!(formatter, "InputValue {{ Bool {:?}}}", value),
+            InputValue::Uint16(value) => write!(formatter, "InputValue {{ Uint16 {:?}}}", value),
+            InputValue::Uint32(value) => write!(formatter, "InputValue {{ Uint32 {:?}}}", value),
+            InputValue::Uint64(value) => write!(formatter, "InputValue {{ Uint64 {:?}}}", value),
+            InputValue::Int16(value) => write!(formatter, "InputValue {{ Int16 {:?}}}", value),
+            InputValue::Int32(value) => write!(formatter, "InputValue {{ Int32 {:?}}}", value),
+            InputValue::Int64(value) => write!(formatter, "InputValue {{ Int64 {:?}}}", value),
+            InputValue::Text(value) => write!(formatter, "InputValue {{ Text {:?}}}", value),
+            InputValue::TextToHash(value) => {
+                write!(formatter, "InputValue {{ TextToHash {:?}}}", value)
+            }
+            InputValue::Reference(value) => {
+                write!(formatter, "InputValue {{ Reference {:?}}}", value)
+            }
+        }
+    }
+}
+
 impl<T: Trait> Default for InputValue<T> {
     fn default() -> InputValue<T> {
         Self::Bool(false)
@@ -92,7 +119,7 @@ impl<T: Trait> InputValue<T> {
 
 /// Vector value enum representation
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
+#[derive(Encode, Decode, Clone, PartialEq, Eq)]
 pub enum VecInputValue<T: Trait> {
     Bool(Vec<bool>),
     Uint16(Vec<u16>),
@@ -107,6 +134,43 @@ pub enum VecInputValue<T: Trait> {
     Reference(Vec<T::EntityId>),
 }
 
+impl<T: Trait> core::fmt::Debug for VecInputValue<T> {
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        match self {
+            VecInputValue::Bool(vec_value) => {
+                write!(formatter, "VecInputValue {{ Bool {:?}}}", vec_value)
+            }
+            VecInputValue::Uint16(vec_value) => {
+                write!(formatter, "VecInputValue {{ Uint16 {:?}}}", vec_value)
+            }
+            VecInputValue::Uint32(vec_value) => {
+                write!(formatter, "VecInputValue {{ Uint32 {:?}}}", vec_value)
+            }
+            VecInputValue::Uint64(vec_value) => {
+                write!(formatter, "VecInputValue {{ Uint64 {:?}}}", vec_value)
+            }
+            VecInputValue::Int16(vec_value) => {
+                write!(formatter, "VecInputValue {{ Int16 {:?}}}", vec_value)
+            }
+            VecInputValue::Int32(vec_value) => {
+                write!(formatter, "VecInputValue {{ Int32 {:?}}}", vec_value)
+            }
+            VecInputValue::Int64(vec_value) => {
+                write!(formatter, "VecInputValue {{ Int64 {:?}}}", vec_value)
+            }
+            VecInputValue::TextToHash(vec_value) => {
+                write!(formatter, "VecInputValue {{ TextToHash {:?}}}", vec_value)
+            }
+            VecInputValue::Text(vec_value) => {
+                write!(formatter, "VecInputValue {{ Text {:?}}}", vec_value)
+            }
+            VecInputValue::Reference(vec_value) => {
+                write!(formatter, "VecInputValue {{ Reference {:?}}}", vec_value)
+            }
+        }
+    }
+}
+
 impl<T: Trait> Default for VecInputValue<T> {
     fn default() -> Self {
         Self::Bool(vec![])