Browse Source

Merge pull request #1259 from iorveth/cont_directory_debug_trait_implementation

Cont directory debug trait implementation
Bedeho Mender 4 years ago
parent
commit
a345a2bc4b

+ 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",
-]
+]

+ 2 - 2
runtime-modules/content-directory/src/class.rs

@@ -1,7 +1,7 @@
 use super::*;
 
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+#[derive(Encode, Decode, Eq, PartialEq, Clone)]
 pub struct Class<T: Trait> {
     /// Permissions for an instance of a Class.
     class_permissions: ClassPermissions<T>,

+ 4 - 4
runtime-modules/content-directory/src/entity.rs

@@ -1,8 +1,8 @@
 use super::*;
 
 /// Represents `Entity`, related to a specific `Class`
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+#[derive(Encode, Decode, Clone, PartialEq, Eq)]
 pub struct Entity<T: Trait> {
     /// Permissions for an instance of an Entity.
     entity_permissions: EntityPermissions<T>,
@@ -165,8 +165,8 @@ impl<T: Trait> Entity<T> {
 }
 
 /// Structure, respresenting inbound entity rcs for each `Entity`
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Copy, Debug)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+#[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Copy)]
 pub struct InboundReferenceCounter {
     /// Total number of inbound references from another entities
     pub total: u32,

+ 7 - 7
runtime-modules/content-directory/src/helpers.rs

@@ -170,8 +170,8 @@ impl<'a, T: Trait> StoredValuesForExistingProperties<'a, T> {
 }
 
 /// Length constraint for input validation
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Default, Clone, Copy, PartialEq, Eq, Debug)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+#[derive(Encode, Decode, Default, Clone, Copy, PartialEq, Eq)]
 pub struct InputValidationLengthConstraint {
     /// Minimum length
     min: u16,
@@ -218,7 +218,7 @@ impl InputValidationLengthConstraint {
 }
 
 /// Enum, used to specify, which mode of operation should be chosen
-#[derive(Clone, PartialEq, Eq, Copy, Debug)]
+#[derive(Clone, PartialEq, Eq, Copy)]
 pub enum DeltaMode {
     Increment,
     Decrement,
@@ -231,8 +231,8 @@ impl Default for DeltaMode {
 }
 
 /// Representing delta on which respective `InboundReferenceCounter` should be changed.
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Default, PartialEq, Eq, Debug)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+#[derive(Encode, Decode, Default, PartialEq, Eq)]
 pub struct EntityReferenceCounterSideEffect {
     /// Delta number of all inbound references from another entities
     pub total: i32,
@@ -281,8 +281,8 @@ impl AddAssign for EntityReferenceCounterSideEffect {
 }
 
 /// The net side effect on a set of entities from some operations.
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+#[derive(Encode, Decode, Clone, PartialEq, Eq)]
 pub struct ReferenceCounterSideEffects<T: Trait>(
     BTreeMap<T::EntityId, EntityReferenceCounterSideEffect>,
 );

+ 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>;
 

+ 14 - 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>),
@@ -17,14 +17,14 @@ pub enum ParametrizedPropertyValue<T: Trait> {
 }
 
 /// 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),
 }
 
 /// 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,
@@ -34,14 +34,14 @@ pub struct ParametrizedClassPropertyValue<T: Trait> {
 }
 
 /// 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,
 }
 
 /// 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>,
@@ -50,7 +50,7 @@ pub struct UpdatePropertyValuesOperation<T: Trait> {
 }
 
 /// 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>,
@@ -61,13 +61,20 @@ pub struct AddSchemaSupportToEntityOperation<T: Trait> {
 }
 
 /// 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> {
+    #[cfg(feature = "std")]
+    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>,

+ 9 - 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,10 @@ impl<T: Trait> Default for Actor<T> {
         Self::Lead
     }
 }
+
+impl<T: Trait> core::fmt::Debug for Actor<T> {
+    #[cfg(feature = "std")]
+    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> {
+    #[cfg(feature = "std")]
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(formatter, "ClassPermissions {:?}", self)
+    }
+}
+
 impl<T: Trait> Default for ClassPermissions<T> {
     fn default() -> Self {
         Self {

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

@@ -1,8 +1,8 @@
 use super::*;
 
 /// A group, that consists of `curators` set
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Eq, PartialEq, Clone, Debug)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+#[derive(Encode, Decode, Eq, PartialEq, Clone)]
 pub struct CuratorGroup<T: Trait> {
     /// Curators set, associated with a iven curator group
     curators: BTreeSet<T::CuratorId>,

+ 11 - 4
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,9 +26,16 @@ impl<T: Trait> Default for EntityController<T> {
     }
 }
 
+impl<T: Trait> core::fmt::Debug for EntityController<T> {
+    #[cfg(feature = "std")]
+    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)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+#[derive(Encode, Decode, Clone, PartialEq, Eq)]
 pub struct EntityPermissions<T: Trait> {
     /// Current controller, which is initially set based on who created entity
     pub controller: EntityController<T>,
@@ -115,7 +122,7 @@ impl<T: Trait> EntityPermissions<T> {
 }
 
 /// Type, derived from dispatchable call, identifies the caller
-#[derive(Encode, Decode, Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Debug)]
+#[derive(Encode, Decode, Eq, PartialEq, Ord, PartialOrd, Clone, Copy)]
 pub enum EntityAccessLevel {
     /// Caller identified as the entity maintainer
     EntityMaintainer,

+ 18 - 11
runtime-modules/content-directory/src/schema.rs

@@ -31,8 +31,8 @@ pub type SchemaId = u16;
 pub type SameController = bool;
 
 /// Locking policy, representing `Property` locking status for both controller and maintainer
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Default, Decode, Clone, Copy, PartialEq, Eq, Debug)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+#[derive(Encode, Default, Decode, Clone, Copy, PartialEq, Eq)]
 pub struct PropertyLockingPolicy {
     /// If property is locked from maintainer
     pub is_locked_from_maintainer: bool,
@@ -41,8 +41,8 @@ pub struct PropertyLockingPolicy {
 }
 
 /// Enum, used for `PropertyType` representation
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, Debug)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq)]
 pub enum Type<T: Trait> {
     Bool,
     Uint16,
@@ -86,8 +86,8 @@ impl<T: Trait> Type<T> {
 }
 
 /// Vector property type representation
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, Debug)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, 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
@@ -134,8 +134,8 @@ 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)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+#[derive(Encode, Decode, Clone, Copy, PartialEq, Eq)]
 pub enum PropertyType<T: Trait> {
     Single(Type<T>),
     Vector(VecPropertyType<T>),
@@ -183,8 +183,8 @@ impl<T: Trait> PropertyType<T> {
 }
 
 /// A schema defines what properties describe an entity
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+#[derive(Encode, Decode, Clone, PartialEq, Eq)]
 pub struct Schema {
     /// Indices into properties vector for the corresponding class.
     properties: BTreeSet<PropertyId>,
@@ -257,7 +257,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 +286,13 @@ impl<T: Trait> Default for Property<T> {
     }
 }
 
+impl<T: Trait> core::fmt::Debug for Property<T> {
+    #[cfg(feature = "std")]
+    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 {

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

@@ -2,12 +2,19 @@ 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> {
+    #[cfg(feature = "std")]
+    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 +65,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 +80,13 @@ pub enum InputValue<T: Trait> {
     Reference(T::EntityId),
 }
 
+impl<T: Trait> core::fmt::Debug for InputValue<T> {
+    #[cfg(feature = "std")]
+    fn fmt(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+        write!(formatter, "InputValue {:?}", self)
+    }
+}
+
 impl<T: Trait> Default for InputValue<T> {
     fn default() -> InputValue<T> {
         Self::Bool(false)
@@ -91,8 +105,8 @@ impl<T: Trait> InputValue<T> {
 }
 
 /// Vector value enum representation
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+#[derive(Encode, Decode, Clone, PartialEq, Eq)]
 pub enum VecInputValue<T: Trait> {
     Bool(Vec<bool>),
     Uint16(Vec<u16>),

+ 8 - 8
runtime-modules/content-directory/src/schema/output.rs

@@ -2,8 +2,8 @@ use super::*;
 use sp_runtime::traits::Hash;
 
 /// Enum, representing either `StoredValue` or `VecStoredPropertyValue`
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+#[derive(Encode, Decode, Clone, PartialEq, Eq)]
 pub enum StoredPropertyValue<T: Trait> {
     Single(StoredValue<T>),
     Vector(VecStoredPropertyValue<T>),
@@ -84,8 +84,8 @@ impl<T: Trait> Default for StoredPropertyValue<T> {
 }
 
 /// StoredValue enum representation, related to corresponding `SingleStoredPropertyValue` structure
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Hash, Clone, PartialEq, PartialOrd, Ord, Eq, Debug)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+#[derive(Encode, Decode, Hash, Clone, PartialEq, PartialOrd, Ord, Eq)]
 pub enum StoredValue<T: Trait> {
     Bool(bool),
     Uint16(u16),
@@ -117,8 +117,8 @@ impl<T: Trait> StoredValue<T> {
 }
 
 /// Consists of `VecStoredPropertyValue` enum representation and `nonce`, used to avoid vector data race update conditions
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Default, Clone, Debug, PartialEq, Eq)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+#[derive(Encode, Decode, Default, Clone, PartialEq, Eq)]
 pub struct VecStoredPropertyValue<T: Trait> {
     vec_value: VecStoredValue<T>,
     nonce: T::Nonce,
@@ -276,8 +276,8 @@ impl<T: Trait> VecStoredPropertyValue<T> {
 }
 
 /// Vector value enum representation, related to corresponding `VecStoredPropertyValue` structure
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug)]
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
+#[derive(Encode, Decode, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
 pub enum VecStoredValue<T: Trait> {
     Bool(Vec<bool>),
     Uint16(Vec<u16>),