Browse Source

Cont dir 2.0 core logic migration completed

iorveth 4 years ago
parent
commit
f075c4385b

File diff suppressed because it is too large
+ 652 - 45
Cargo.lock


+ 12 - 18
runtime-modules/content-directory/Cargo.toml

@@ -1,21 +1,16 @@
 [package]
 name = 'substrate-content-directory-module'
-version = '1.0.1'
+version = '3.0.0'
 authors = ['Joystream contributors']
 edition = '2018'
 
 [dependencies]
-hex-literal = '0.1.0'
-codec = { package = 'parity-scale-codec', version = '1.0.0', default-features = false, features = ['derive'] }
-rstd = { package = 'sr-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-runtime-primitives = { package = 'sr-primitives', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-srml-support = { package = 'srml-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-srml-support-procedural = { package = 'srml-support-procedural', git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-system = { package = 'srml-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-timestamp = { package = 'srml-timestamp', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-runtime-io = { package = 'sr-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-# https://users.rust-lang.org/t/failure-derive-compilation-error/39062
-quote = '<=1.0.2'
+codec = { package = 'parity-scale-codec', version = '1.3.1', default-features = false, features = ['derive'] }
+rstd = { package = 'sp-std', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+sp-runtime = { package = 'sp-runtime', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+frame-support = { package = 'frame-support', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+system = { package = 'frame-system', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+sp-arithmetic = { package = 'sp-arithmetic', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
 
 [dependencies.serde]
 features = ['derive']
@@ -23,8 +18,8 @@ optional = true
 version = '1.0.101'
 
 [dev-dependencies]
-runtime-io = { package = 'sr-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
-primitives = { package = 'substrate-primitives', git = 'https://github.com/paritytech/substrate.git', rev = 'c37bb08535c49a12320af7facfd555ce05cce2e8'}
+sp-io = { package = 'sp-io', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
+sp-core = { package = 'sp-core', default-features = false, git = 'https://github.com/paritytech/substrate.git', rev = '00768a1f21a579c478fe5d4f51e1fa71f7db9fd4'}
 
 [features]
 default = ['std']
@@ -32,9 +27,8 @@ std = [
 	'serde',
 	'codec/std',
 	'rstd/std',
-	'runtime-io/std',
-	'runtime-primitives/std',
-	'srml-support/std',
+	'sp-arithmetic/std',
+	'sp-runtime/std',
+	'frame-support/std',
 	'system/std',
-	'timestamp/std',
 ]

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

@@ -168,7 +168,7 @@ impl<T: Trait> Class<T> {
     }
 
     /// Ensure `schema_id` is a valid index of `Class` schemas vector
-    pub fn ensure_schema_id_exists(&self, schema_id: SchemaId) -> dispatch::Result {
+    pub fn ensure_schema_id_exists(&self, schema_id: SchemaId) -> DispatchResult {
         ensure!(
             schema_id < self.schemas.len() as SchemaId,
             ERROR_UNKNOWN_CLASS_SCHEMA_ID
@@ -177,7 +177,7 @@ impl<T: Trait> Class<T> {
     }
 
     /// Ensure `Schema`s limit per `Class` not reached
-    pub fn ensure_schemas_limit_not_reached(&self) -> dispatch::Result {
+    pub fn ensure_schemas_limit_not_reached(&self) -> DispatchResult {
         ensure!(
             (self.schemas.len() as MaxNumber) < T::MaxNumberOfSchemasPerClass::get(),
             ERROR_CLASS_SCHEMAS_LIMIT_REACHED
@@ -189,7 +189,7 @@ impl<T: Trait> Class<T> {
     pub fn ensure_properties_limit_not_reached(
         &self,
         new_properties: &[Property<T>],
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         ensure!(
             T::MaxNumberOfPropertiesPerSchema::get()
                 >= (self.properties.len() + new_properties.len()) as MaxNumber,
@@ -199,7 +199,7 @@ impl<T: Trait> Class<T> {
     }
 
     /// Ensure `Class` specific entities limit not reached
-    pub fn ensure_maximum_entities_count_limit_not_reached(&self) -> dispatch::Result {
+    pub fn ensure_maximum_entities_count_limit_not_reached(&self) -> DispatchResult {
         ensure!(
             self.current_number_of_entities < self.maximum_entities_count,
             ERROR_MAX_NUMBER_OF_ENTITIES_PER_CLASS_LIMIT_REACHED
@@ -232,7 +232,7 @@ impl<T: Trait> Class<T> {
     }
 
     /// Ensure property values were not locked on `Class` level
-    pub fn ensure_property_values_unlocked(&self) -> dispatch::Result {
+    pub fn ensure_property_values_unlocked(&self) -> DispatchResult {
         ensure!(
             !self
                 .get_permissions_ref()

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

@@ -104,7 +104,7 @@ impl<T: Trait> Entity<T> {
     }
 
     /// Ensure `Schema` under given id is not added to given `Entity` yet
-    pub fn ensure_schema_id_is_not_added(&self, schema_id: SchemaId) -> dispatch::Result {
+    pub fn ensure_schema_id_is_not_added(&self, schema_id: SchemaId) -> DispatchResult {
         let schema_not_added = !self.supported_schemas.contains(&schema_id);
         ensure!(schema_not_added, ERROR_SCHEMA_ALREADY_ADDED_TO_THE_ENTITY);
         Ok(())
@@ -114,7 +114,7 @@ impl<T: Trait> Entity<T> {
     pub fn ensure_property_values_are_not_added(
         &self,
         property_values: &BTreeMap<PropertyId, InputPropertyValue<T>>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         ensure!(
             property_values
                 .keys()
@@ -141,7 +141,7 @@ impl<T: Trait> Entity<T> {
     }
 
     /// Ensure any `InputPropertyValue` from external entity does not point to the given `Entity`
-    pub fn ensure_rc_is_zero(&self) -> dispatch::Result {
+    pub fn ensure_rc_is_zero(&self) -> DispatchResult {
         ensure!(
             self.reference_counter.is_total_equal_to_zero(),
             ERROR_ENTITY_RC_DOES_NOT_EQUAL_TO_ZERO
@@ -150,7 +150,7 @@ impl<T: Trait> Entity<T> {
     }
 
     /// Ensure any inbound `InputPropertyValue` with `same_owner` flag set points to the given `Entity`
-    pub fn ensure_inbound_same_owner_rc_is_zero(&self) -> dispatch::Result {
+    pub fn ensure_inbound_same_owner_rc_is_zero(&self) -> DispatchResult {
         ensure!(
             self.reference_counter.is_same_owner_equal_to_zero(),
             ERROR_ENTITY_SAME_OWNER_RC_DOES_NOT_EQUAL_TO_ZERO

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

@@ -201,7 +201,7 @@ impl InputValidationLengthConstraint {
         len: usize,
         too_short_msg: &'static str,
         too_long_msg: &'static str,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         let length = len as u16;
         if length < self.min {
             Err(too_short_msg)

+ 106 - 72
runtime-modules/content-directory/src/lib.rs

@@ -27,13 +27,12 @@ use core::hash::Hash;
 use core::ops::AddAssign;
 
 use codec::{Codec, Decode, Encode};
+use frame_support::storage::IterableStorageMap;
+use frame_support::{decl_event, decl_module, decl_storage, ensure, traits::Get, Parameter};
 use rstd::collections::{btree_map::BTreeMap, btree_set::BTreeSet};
-use rstd::prelude::*;
-use runtime_primitives::traits::{MaybeSerializeDeserialize, Member, One, SimpleArithmetic, Zero};
-use srml_support::{
-    decl_event, decl_module, decl_storage, dispatch, ensure, traits::Get, Parameter,
-    StorageDoubleMap,
-};
+use rstd::vec::Vec;
+use sp_arithmetic::traits::{BaseArithmetic, One, Zero};
+use sp_runtime::traits::{MaybeSerializeDeserialize, Member};
 use system::ensure_signed;
 
 #[cfg(feature = "std")]
@@ -42,6 +41,10 @@ pub use serde::{Deserialize, Serialize};
 /// Type, used in diffrent numeric constraints representations
 type MaxNumber = u32;
 
+//TODO: Convert errors to the Substrate decl_error! macro.
+/// Result with string error message. This exists for backward compatibility purpose.
+pub type DispatchResult = Result<(), &'static str>;
+
 pub trait Trait: system::Trait + ActorAuthenticator + Debug + Clone {
     /// The overarching event type.
     type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
@@ -49,7 +52,7 @@ pub trait Trait: system::Trait + ActorAuthenticator + Debug + Clone {
     /// Nonce type is used to avoid data race update conditions, when performing property value vector operations
     type Nonce: Parameter
         + Member
-        + SimpleArithmetic
+        + BaseArithmetic
         + Codec
         + Default
         + Copy
@@ -65,7 +68,7 @@ pub trait Trait: system::Trait + ActorAuthenticator + Debug + Clone {
     /// Type of identifier for classes
     type ClassId: Parameter
         + Member
-        + SimpleArithmetic
+        + BaseArithmetic
         + Codec
         + Default
         + Copy
@@ -80,7 +83,7 @@ pub trait Trait: system::Trait + ActorAuthenticator + Debug + Clone {
     /// Type of identifier for entities
     type EntityId: Parameter
         + Member
-        + SimpleArithmetic
+        + BaseArithmetic
         + Codec
         + Default
         + Copy
@@ -145,30 +148,30 @@ decl_storage! {
     trait Store for Module<T: Trait> as ContentDirectory {
 
         /// Map, representing ClassId -> Class relation
-        pub ClassById get(class_by_id) config(): linked_map T::ClassId => Class<T>;
+        pub ClassById get(fn class_by_id) config(): map hasher(blake2_128_concat) T::ClassId => Class<T>;
 
         /// Map, representing EntityId -> Entity relation
-        pub EntityById get(entity_by_id) config(): map T::EntityId => Entity<T>;
+        pub EntityById get(fn entity_by_id) config(): map hasher(blake2_128_concat) T::EntityId => Entity<T>;
 
         /// Map, representing  CuratorGroupId -> CuratorGroup relation
-        pub CuratorGroupById get(curator_group_by_id) config(): map T::CuratorGroupId => CuratorGroup<T>;
+        pub CuratorGroupById get(fn curator_group_by_id) config(): map hasher(blake2_128_concat) T::CuratorGroupId => CuratorGroup<T>;
 
         /// Used to enforce uniqueness of a property value across all Entities that have this property in a given Class.
-        pub UniquePropertyValues get(unique_property_values) config(): double_map hasher(blake2_128) (T::ClassId, PropertyId), blake2_128(SimplifiedOutputPropertyValue<T>) => ();
+        pub UniquePropertyValues get(fn unique_property_values) config(): double_map hasher(blake2_128_concat) (T::ClassId, PropertyId), hasher(blake2_128_concat) SimplifiedOutputPropertyValue<T> => ();
 
         /// Next runtime storage values used to maintain next id value, used on creation of respective curator groups, classes and entities
 
-        pub NextClassId get(next_class_id) config(): T::ClassId;
+        pub NextClassId get(fn next_class_id) config(): T::ClassId;
 
-        pub NextEntityId get(next_entity_id) config(): T::EntityId;
+        pub NextEntityId get(fn next_entity_id) config(): T::EntityId;
 
-        pub NextCuratorGroupId get(next_curator_group_id) config(): T::CuratorGroupId;
+        pub NextCuratorGroupId get(fn next_curator_group_id) config(): T::CuratorGroupId;
 
         // The voucher associated with entity creation for a given class and controller.
         // Is updated whenever an entity is created in a given class by a given controller.
         // Constraint is updated by Root, an initial value comes from `ClassPermissions::default_entity_creation_voucher_upper_bound`.
-        pub EntityCreationVouchers get(entity_creation_vouchers):
-            double_map hasher(blake2_128) T::ClassId, blake2_128(EntityController<T>) => EntityCreationVoucher<T>;
+        pub EntityCreationVouchers get(fn entity_creation_vouchers):
+            double_map hasher(blake2_128_concat) T::ClassId, hasher(blake2_128_concat) EntityController<T> => EntityCreationVoucher<T>;
     }
 }
 
@@ -183,9 +186,10 @@ decl_module! {
         fn deposit_event() = default;
 
         /// Add new curator group to runtime storage
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn add_curator_group(
             origin,
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Ensure given origin is lead
             ensure_is_lead::<T>(origin)?;
@@ -208,10 +212,11 @@ decl_module! {
         }
 
         /// Remove curator group under given `curator_group_id` from runtime storage
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn remove_curator_group(
             origin,
             curator_group_id: T::CuratorGroupId,
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Ensure given origin is lead
             ensure_is_lead::<T>(origin)?;
@@ -236,11 +241,12 @@ decl_module! {
         }
 
         /// Set `is_active` status for curator group under given `curator_group_id`
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn set_curator_group_status(
             origin,
             curator_group_id: T::CuratorGroupId,
             is_active: bool,
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Ensure given origin is lead
             ensure_is_lead::<T>(origin)?;
@@ -263,11 +269,12 @@ decl_module! {
         }
 
         /// Add curator to curator group under given `curator_group_id`
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn add_curator_to_group(
             origin,
             curator_group_id: T::CuratorGroupId,
             curator_id: T::CuratorId,
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Ensure given origin is lead
             ensure_is_lead::<T>(origin)?;
@@ -293,11 +300,12 @@ decl_module! {
         }
 
         /// Remove curator from a given curator group
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn remove_curator_from_group(
             origin,
             curator_group_id: T::CuratorGroupId,
             curator_id: T::CuratorId,
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Ensure given origin is lead
             ensure_is_lead::<T>(origin)?;
@@ -323,11 +331,12 @@ decl_module! {
         }
 
         /// Add curator group under given `curator_group_id` as `Class` maintainer
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn add_maintainer_to_class(
             origin,
             class_id: T::ClassId,
             curator_group_id: T::CuratorGroupId,
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Ensure given origin is lead
             ensure_is_lead::<T>(origin)?;
@@ -367,11 +376,12 @@ decl_module! {
         }
 
         /// Remove curator group under given `curator_group_id` from `Class` maintainers set
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn remove_maintainer_from_class(
             origin,
             class_id: T::ClassId,
             curator_group_id: T::CuratorGroupId,
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Ensure given origin is lead
             ensure_is_lead::<T>(origin)?;
@@ -403,12 +413,13 @@ decl_module! {
         }
 
         /// Updates or creates new `EntityCreationVoucher` for given `EntityController` with individual limit
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn update_entity_creation_voucher(
             origin,
             class_id: T::ClassId,
             controller: EntityController<T>,
             maximum_entities_count: T::EntityId
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Ensure given origin is lead
             ensure_is_lead::<T>(origin)?;
@@ -420,7 +431,7 @@ decl_module! {
             Self::ensure_valid_number_of_class_entities_per_actor_constraint(maximum_entities_count)?;
 
             // Check voucher existance
-            let voucher_exists = <EntityCreationVouchers<T>>::exists(class_id, &controller);
+            let voucher_exists = <EntityCreationVouchers<T>>::contains_key(class_id, &controller);
 
             //
             // == MUTATION SAFE ==
@@ -453,6 +464,7 @@ decl_module! {
         }
 
         /// Create new `Class` with provided parameters
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn create_class(
             origin,
             name: Vec<u8>,
@@ -460,7 +472,7 @@ decl_module! {
             class_permissions: ClassPermissions<T>,
             maximum_entities_count: T::EntityId,
             default_entity_creation_voucher_upper_bound: T::EntityId
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Ensure given origin is lead
             ensure_is_lead::<T>(origin)?;
@@ -504,6 +516,7 @@ decl_module! {
         }
 
         /// Update `ClassPermissions` under specific `class_id`
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn update_class_permissions(
             origin,
             class_id: T::ClassId,
@@ -511,7 +524,7 @@ decl_module! {
             updated_entity_creation_blocked: Option<bool>,
             updated_all_entity_property_values_locked: Option<bool>,
             updated_maintainers: Option<BTreeSet<T::CuratorGroupId>>,
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Ensure given origin is lead
             ensure_is_lead::<T>(origin)?;
@@ -552,12 +565,13 @@ decl_module! {
         }
 
         /// Create new class schema from existing property ids and new properties
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn add_class_schema(
             origin,
             class_id: T::ClassId,
             existing_properties: BTreeSet<PropertyId>,
             new_properties: Vec<Property<T>>
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Ensure given origin is lead
             ensure_is_lead::<T>(origin)?;
@@ -611,12 +625,13 @@ decl_module! {
         }
 
         /// Update `schema_status` under specific `schema_id` in `Class`
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn update_class_schema_status(
             origin,
             class_id: T::ClassId,
             schema_id: SchemaId,
             schema_status: bool
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Ensure given origin is lead
             ensure_is_lead::<T>(origin)?;
@@ -642,12 +657,13 @@ decl_module! {
         }
 
         /// Update entity permissions
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn update_entity_permissions(
             origin,
             entity_id: T::EntityId,
             updated_frozen: Option<bool>,
             updated_referenceable: Option<bool>
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Ensure given origin is lead
             ensure_is_lead::<T>(origin)?;
@@ -680,12 +696,13 @@ decl_module! {
 
         /// Transfer ownership to new `EntityController` for `Entity` under given `entity_id`
         /// `new_property_value_references_with_same_owner_flag_set` should be provided manually
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn transfer_entity_ownership(
             origin,
             entity_id: T::EntityId,
             new_controller: EntityController<T>,
             new_property_value_references_with_same_owner_flag_set: BTreeMap<PropertyId, InputPropertyValue<T>>
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Ensure given origin is lead
             ensure_is_lead::<T>(origin)?;
@@ -809,11 +826,12 @@ decl_module! {
         /// Create an entity.
         /// If someone is making an entity of this class for first time,
         /// then a voucher is also added with the class limit as the default limit value.
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn create_entity(
             origin,
             class_id: T::ClassId,
             actor: Actor<T>,
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             let account_id = ensure_signed(origin)?;
 
@@ -834,7 +852,7 @@ decl_module! {
             let entity_controller = EntityController::from_actor(&actor);
 
             // Check if entity creation voucher exists
-            let voucher_exists = if <EntityCreationVouchers<T>>::exists(class_id, &entity_controller) {
+            let voucher_exists = if <EntityCreationVouchers<T>>::contains_key(class_id, &entity_controller) {
 
                 // Ensure voucher limit not reached
                 Self::entity_creation_vouchers(class_id, &entity_controller).ensure_voucher_limit_not_reached()?;
@@ -893,11 +911,12 @@ decl_module! {
         }
 
         /// Remove `Entity` under provided `entity_id`
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn remove_entity(
             origin,
             actor: Actor<T>,
             entity_id: T::EntityId,
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Retrieve Entity and EntityAccessLevel for the actor, attemting to perform operation
             let (class, entity, access_level) = Self::ensure_class_entity_and_access_level(origin, entity_id, &actor)?;
@@ -942,13 +961,14 @@ decl_module! {
         }
 
         /// Add schema support to entity under given `schema_id` and provided `property_values`
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn add_schema_support_to_entity(
             origin,
             actor: Actor<T>,
             entity_id: T::EntityId,
             schema_id: SchemaId,
             new_property_values: BTreeMap<PropertyId, InputPropertyValue<T>>
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Retrieve Class, Entity and ensure given have access to the Entity under given entity_id
             let (class, entity, _) = Self::ensure_class_entity_and_access_level(origin, entity_id, &actor)?;
@@ -1039,12 +1059,13 @@ decl_module! {
         }
 
         /// Update `Entity` `InputPropertyValue`'s with provided ones
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn update_entity_property_values(
             origin,
             actor: Actor<T>,
             entity_id: T::EntityId,
             new_property_values: BTreeMap<PropertyId, InputPropertyValue<T>>
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Retrieve Class, Entity and EntityAccessLevel for the actor, attemting to perform operation
             let (class, entity, access_level) = Self::ensure_class_entity_and_access_level(origin, entity_id, &actor)?;
@@ -1124,12 +1145,13 @@ decl_module! {
         }
 
         /// Clear `PropertyValueVec` under given `entity_id` & `in_class_schema_property_id`
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn clear_entity_property_vector(
             origin,
             actor: Actor<T>,
             entity_id: T::EntityId,
             in_class_schema_property_id: PropertyId
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Retrieve Class, Entity and EntityAccessLevel for the actor, attemting to perform operation
             let (class, entity, access_level) = Self::ensure_class_entity_and_access_level(origin, entity_id, &actor)?;
@@ -1185,7 +1207,8 @@ decl_module! {
         }
 
         /// Remove value at given `index_in_property_vector`
-        /// from `PropertyValueVec` under in_class_schema_property_id
+        /// from `PropertyValueVec` under in_`class_schema_property_id`
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn remove_at_entity_property_vector(
             origin,
             actor: Actor<T>,
@@ -1193,7 +1216,7 @@ decl_module! {
             in_class_schema_property_id: PropertyId,
             index_in_property_vector: VecMaxLength,
             nonce: T::Nonce
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Retrieve Class, Entity and EntityAccessLevel for the actor, attemting to perform operation
             let (class, entity, access_level) = Self::ensure_class_entity_and_access_level(origin, entity_id, &actor)?;
@@ -1274,6 +1297,7 @@ decl_module! {
 
         /// Insert `SingleInputPropertyValue` at given `index_in_property_vector`
         /// into `PropertyValueVec` under `in_class_schema_property_id`
+        #[weight = 10_000_000] // TODO: adjust weight
         pub fn insert_at_entity_property_vector(
             origin,
             actor: Actor<T>,
@@ -1282,7 +1306,7 @@ decl_module! {
             index_in_property_vector: VecMaxLength,
             value: InputValue<T>,
             nonce: T::Nonce
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
 
             // Retrieve Class, Entity and EntityAccessLevel for the actor, attemting to perform operation
             let (class, entity, access_level) = Self::ensure_class_entity_and_access_level(origin, entity_id, &actor)?;
@@ -1363,7 +1387,8 @@ decl_module! {
             Ok(())
         }
 
-        pub fn transaction(origin, actor: Actor<T>, operations: Vec<OperationType<T>>) -> dispatch::Result {
+        #[weight = 10_000_000] // TODO: adjust weight
+        pub fn transaction(origin, actor: Actor<T>, operations: Vec<OperationType<T>>) -> DispatchResult {
 
             // Ensure maximum number of operations during atomic batching limit not reached
             Self::ensure_number_of_operations_during_atomic_batching_limit_not_reached(&operations)?;
@@ -1785,9 +1810,9 @@ impl<T: Trait> Module<T> {
         class_id: T::ClassId,
         property_id: PropertyId,
         property_value: &SimplifiedOutputPropertyValue<T>,
-    ) -> Result<(), &'static str> {
+    ) -> DispatchResult {
         ensure!(
-            !<UniquePropertyValues<T>>::exists((class_id, property_id), property_value),
+            !<UniquePropertyValues<T>>::contains_key((class_id, property_id), property_value),
             ERROR_PROPERTY_VALUE_SHOULD_BE_UNIQUE
         );
         Ok(())
@@ -1797,7 +1822,7 @@ impl<T: Trait> Module<T> {
     pub fn ensure_properties_unique_option_satisfied(
         class_id: T::ClassId,
         unique_new_property_values: &BTreeMap<PropertyId, SimplifiedOutputPropertyValue<T>>,
-    ) -> Result<(), &'static str> {
+    ) -> DispatchResult {
         for (&property_id, property_value) in unique_new_property_values {
             Self::ensure_property_unique_option_satisfied(class_id, property_id, property_value)?;
         }
@@ -1806,7 +1831,10 @@ impl<T: Trait> Module<T> {
 
     /// Returns the stored `Class` if exist, error otherwise.
     fn ensure_class_exists(class_id: T::ClassId) -> Result<Class<T>, &'static str> {
-        ensure!(<ClassById<T>>::exists(class_id), ERROR_CLASS_NOT_FOUND);
+        ensure!(
+            <ClassById<T>>::contains_key(class_id),
+            ERROR_CLASS_NOT_FOUND
+        );
         Ok(Self::class_by_id(class_id))
     }
 
@@ -1879,7 +1907,7 @@ impl<T: Trait> Module<T> {
             PropertyId,
             InputPropertyValue<T>,
         >,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         let new_property_value_id_references_with_same_owner_flag_set: BTreeSet<PropertyId> =
             new_property_value_references_with_same_owner_flag_set
                 .keys()
@@ -1898,7 +1926,7 @@ impl<T: Trait> Module<T> {
     fn ensure_are_valid_references_with_same_owner_flag_set(
         new_property_value_references_with_same_owner_flag_set: InputValuesForExistingProperties<T>,
         new_controller: &EntityController<T>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         for updated_value_for_existing_property in
             new_property_value_references_with_same_owner_flag_set.values()
         {
@@ -1978,7 +2006,7 @@ impl<T: Trait> Module<T> {
     pub fn ensure_all_required_properties_provided(
         class_properties: &[Property<T>],
         unused_schema_property_ids: &BTreeSet<PropertyId>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         for &unused_schema_property_id in unused_schema_property_ids {
             let class_property = &class_properties
                 .get(unused_schema_property_id as usize)
@@ -1995,7 +2023,7 @@ impl<T: Trait> Module<T> {
     pub fn ensure_property_values_are_valid(
         entity_controller: &EntityController<T>,
         values_for_existing_properties: &InputValuesForExistingProperties<T>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         for value_for_existing_property in values_for_existing_properties.values() {
             let (property, value) = value_for_existing_property.unzip();
 
@@ -2010,7 +2038,7 @@ impl<T: Trait> Module<T> {
     pub fn ensure_all_property_values_are_already_added(
         entity_property_values: &BTreeMap<PropertyId, OutputPropertyValue<T>>,
         new_property_values: &BTreeMap<PropertyId, InputPropertyValue<T>>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         ensure!(
             new_property_values
                 .keys()
@@ -2024,7 +2052,7 @@ impl<T: Trait> Module<T> {
     pub fn ensure_all_property_values_are_unlocked_from(
         new_values_for_existing_properties: &InputValuesForExistingProperties<T>,
         access_level: EntityAccessLevel,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         for value_for_new_property in new_values_for_existing_properties.values() {
             // Ensure Property is unlocked from Actor with given EntityAccessLevel
             value_for_new_property
@@ -2120,22 +2148,28 @@ impl<T: Trait> Module<T> {
 
     /// Ensure `Class` under given id exists, return corresponding one
     pub fn ensure_known_class_id(class_id: T::ClassId) -> Result<Class<T>, &'static str> {
-        ensure!(<ClassById<T>>::exists(class_id), ERROR_CLASS_NOT_FOUND);
+        ensure!(
+            <ClassById<T>>::contains_key(class_id),
+            ERROR_CLASS_NOT_FOUND
+        );
         Ok(Self::class_by_id(class_id))
     }
 
     /// Ensure `Entity` under given id exists, return corresponding one
     pub fn ensure_known_entity_id(entity_id: T::EntityId) -> Result<Entity<T>, &'static str> {
-        ensure!(<EntityById<T>>::exists(entity_id), ERROR_ENTITY_NOT_FOUND);
+        ensure!(
+            <EntityById<T>>::contains_key(entity_id),
+            ERROR_ENTITY_NOT_FOUND
+        );
         Ok(Self::entity_by_id(entity_id))
     }
 
     /// Ensure `CuratorGroup` under given id exists
     pub fn ensure_curator_group_under_given_id_exists(
         curator_group_id: &T::CuratorGroupId,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         ensure!(
-            <CuratorGroupById<T>>::exists(curator_group_id),
+            <CuratorGroupById<T>>::contains_key(curator_group_id),
             ERROR_CURATOR_GROUP_DOES_NOT_EXIST
         );
         Ok(())
@@ -2152,7 +2186,7 @@ impl<T: Trait> Module<T> {
     /// Ensure `MaxNumberOfMaintainersPerClass` constraint satisfied
     pub fn ensure_maintainers_limit_not_reached(
         curator_groups: &BTreeSet<T::CuratorGroupId>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         ensure!(
             curator_groups.len() < T::MaxNumberOfMaintainersPerClass::get() as usize,
             ERROR_NUMBER_OF_MAINTAINERS_PER_CLASS_LIMIT_REACHED
@@ -2163,7 +2197,7 @@ impl<T: Trait> Module<T> {
     /// Ensure all `CuratorGroup`'s under given ids exist
     pub fn ensure_curator_groups_exist(
         curator_groups: &BTreeSet<T::CuratorGroupId>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         for curator_group in curator_groups {
             // Ensure CuratorGroup under given id exists
             Self::ensure_curator_group_exists(curator_group)?;
@@ -2174,7 +2208,7 @@ impl<T: Trait> Module<T> {
     /// Perform security checks to ensure provided `class_maintainers` are valid
     pub fn ensure_class_maintainers_are_valid(
         class_maintainers: &BTreeSet<T::CuratorGroupId>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         // Ensure max number of maintainers per Class constraint satisfied
         ensure!(
             class_maintainers.len() <= T::MaxNumberOfMaintainersPerClass::get() as usize,
@@ -2190,7 +2224,7 @@ impl<T: Trait> Module<T> {
     pub fn ensure_non_empty_schema(
         existing_properties: &BTreeSet<PropertyId>,
         new_properties: &[Property<T>],
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         // Schema is empty if both existing_properties and new_properties are empty
         let non_empty_schema = !existing_properties.is_empty() || !new_properties.is_empty();
         ensure!(non_empty_schema, ERROR_NO_PROPS_IN_CLASS_SCHEMA);
@@ -2198,7 +2232,7 @@ impl<T: Trait> Module<T> {
     }
 
     /// Ensure `ClassNameLengthConstraint` conditions satisfied
-    pub fn ensure_class_name_is_valid(text: &[u8]) -> dispatch::Result {
+    pub fn ensure_class_name_is_valid(text: &[u8]) -> DispatchResult {
         T::ClassNameLengthConstraint::get().ensure_valid(
             text.len(),
             ERROR_CLASS_NAME_TOO_SHORT,
@@ -2207,7 +2241,7 @@ impl<T: Trait> Module<T> {
     }
 
     /// Ensure `ClassDescriptionLengthConstraint` conditions satisfied
-    pub fn ensure_class_description_is_valid(text: &[u8]) -> dispatch::Result {
+    pub fn ensure_class_description_is_valid(text: &[u8]) -> DispatchResult {
         T::ClassDescriptionLengthConstraint::get().ensure_valid(
             text.len(),
             ERROR_CLASS_DESCRIPTION_TOO_SHORT,
@@ -2216,9 +2250,9 @@ impl<T: Trait> Module<T> {
     }
 
     /// Ensure `MaxNumberOfClasses` constraint satisfied
-    pub fn ensure_class_limit_not_reached() -> dispatch::Result {
+    pub fn ensure_class_limit_not_reached() -> DispatchResult {
         ensure!(
-            (<ClassById<T>>::enumerate().count() as MaxNumber) < T::MaxNumberOfClasses::get(),
+            (<ClassById<T>>::iter().count() as MaxNumber) < T::MaxNumberOfClasses::get(),
             ERROR_CLASS_LIMIT_REACHED
         );
         Ok(())
@@ -2227,7 +2261,7 @@ impl<T: Trait> Module<T> {
     /// Ensure `MaxNumberOfEntitiesPerClass` constraint satisfied
     pub fn ensure_valid_number_of_entities_per_class(
         maximum_entities_count: T::EntityId,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         ensure!(
             maximum_entities_count <= T::MaxNumberOfEntitiesPerClass::get(),
             ERROR_ENTITIES_NUMBER_PER_CLASS_CONSTRAINT_VIOLATED
@@ -2238,7 +2272,7 @@ impl<T: Trait> Module<T> {
     /// Ensure `IndividualEntitiesCreationLimit` constraint satisfied
     pub fn ensure_valid_number_of_class_entities_per_actor_constraint(
         number_of_class_entities_per_actor: T::EntityId,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         ensure!(
             number_of_class_entities_per_actor <= T::IndividualEntitiesCreationLimit::get(),
             ERROR_NUMBER_OF_CLASS_ENTITIES_PER_ACTOR_CONSTRAINT_VIOLATED
@@ -2250,7 +2284,7 @@ impl<T: Trait> Module<T> {
     pub fn ensure_entities_creation_limits_are_valid(
         maximum_entities_count: T::EntityId,
         default_entity_creation_voucher_upper_bound: T::EntityId,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         // Ensure `per_controller_entities_creation_limit` does not exceed
         ensure!(
             default_entity_creation_voucher_upper_bound < maximum_entities_count,
@@ -2269,7 +2303,7 @@ impl<T: Trait> Module<T> {
     /// Ensure maximum number of operations during atomic batching constraint satisfied
     pub fn ensure_number_of_operations_during_atomic_batching_limit_not_reached(
         operations: &[OperationType<T>],
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         ensure!(
             operations.len() <= T::MaxNumberOfOperationsDuringAtomicBatching::get() as usize,
             ERROR_MAX_NUMBER_OF_OPERATIONS_DURING_ATOMIC_BATCHING_LIMIT_REACHED
@@ -2278,7 +2312,7 @@ impl<T: Trait> Module<T> {
     }
 
     /// Complete all checks to ensure each `Property` is valid
-    pub fn ensure_all_properties_are_valid(new_properties: &[Property<T>]) -> dispatch::Result {
+    pub fn ensure_all_properties_are_valid(new_properties: &[Property<T>]) -> DispatchResult {
         for new_property in new_properties.iter() {
             // Ensure PropertyNameLengthConstraint satisfied
             new_property.ensure_name_is_valid()?;
@@ -2299,7 +2333,7 @@ impl<T: Trait> Module<T> {
     pub fn ensure_all_property_names_are_unique(
         class_properties: &[Property<T>],
         new_properties: &[Property<T>],
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         // Used to ensure all property names are unique within class
         let mut unique_prop_names = BTreeSet::new();
 
@@ -2324,7 +2358,7 @@ impl<T: Trait> Module<T> {
     pub fn ensure_schema_properties_are_valid_indices(
         existing_properties: &BTreeSet<PropertyId>,
         class_properties: &[Property<T>],
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         let has_unknown_properties = existing_properties
             .iter()
             .any(|&prop_id| prop_id >= class_properties.len() as PropertyId);

+ 26 - 37
runtime-modules/content-directory/src/mock.rs

@@ -483,14 +483,11 @@ pub fn next_curator_group_id() -> CuratorGroupId {
     TestModule::next_curator_group_id()
 }
 
-pub fn add_curator_group(lead_origin: u64) -> Result<(), &'static str> {
+pub fn add_curator_group(lead_origin: u64) -> DispatchResult {
     TestModule::add_curator_group(Origin::signed(lead_origin))
 }
 
-pub fn remove_curator_group(
-    lead_origin: u64,
-    curator_group_id: CuratorGroupId,
-) -> Result<(), &'static str> {
+pub fn remove_curator_group(lead_origin: u64, curator_group_id: CuratorGroupId) -> DispatchResult {
     TestModule::remove_curator_group(Origin::signed(lead_origin), curator_group_id)
 }
 
@@ -498,7 +495,7 @@ pub fn add_curator_to_group(
     lead_origin: u64,
     curator_group_id: CuratorGroupId,
     curator_id: CuratorId,
-) -> Result<(), &'static str> {
+) -> DispatchResult {
     TestModule::add_curator_to_group(Origin::signed(lead_origin), curator_group_id, curator_id)
 }
 
@@ -506,7 +503,7 @@ pub fn remove_curator_from_group(
     lead_origin: u64,
     curator_group_id: CuratorGroupId,
     curator_id: CuratorId,
-) -> Result<(), &'static str> {
+) -> DispatchResult {
     TestModule::remove_curator_from_group(Origin::signed(lead_origin), curator_group_id, curator_id)
 }
 
@@ -514,7 +511,7 @@ pub fn set_curator_group_status(
     lead_origin: u64,
     curator_group_id: CuratorGroupId,
     is_active: bool,
-) -> Result<(), &'static str> {
+) -> DispatchResult {
     TestModule::set_curator_group_status(Origin::signed(lead_origin), curator_group_id, is_active)
 }
 
@@ -523,7 +520,7 @@ pub fn curator_group_by_id(curator_group_id: CuratorGroupId) -> CuratorGroup<Run
 }
 
 pub fn curator_group_exists(curator_group_id: CuratorGroupId) -> bool {
-    CuratorGroupById::<Runtime>::exists(curator_group_id)
+    CuratorGroupById::<Runtime>::contains_key(curator_group_id)
 }
 
 // Classes
@@ -541,7 +538,7 @@ pub enum ClassType {
     CuratorGroupDoesNotExist,
 }
 
-pub fn create_simple_class(lead_origin: u64, class_type: ClassType) -> Result<(), &'static str> {
+pub fn create_simple_class(lead_origin: u64, class_type: ClassType) -> DispatchResult {
     let mut class = create_class_with_default_permissions();
     match class_type {
         ClassType::Valid => (),
@@ -614,7 +611,7 @@ pub fn add_maintainer_to_class(
     lead_origin: u64,
     class_id: ClassId,
     curator_group_id: CuratorGroupId,
-) -> Result<(), &'static str> {
+) -> DispatchResult {
     TestModule::add_maintainer_to_class(Origin::signed(lead_origin), class_id, curator_group_id)
 }
 
@@ -622,7 +619,7 @@ pub fn remove_maintainer_from_class(
     lead_origin: u64,
     class_id: ClassId,
     curator_group_id: CuratorGroupId,
-) -> Result<(), &'static str> {
+) -> DispatchResult {
     TestModule::remove_maintainer_from_class(
         Origin::signed(lead_origin),
         class_id,
@@ -637,7 +634,7 @@ pub fn update_class_permissions(
     updated_entity_creation_blocked: Option<bool>,
     updated_all_entity_property_values_locked: Option<bool>,
     updated_maintainers: Option<BTreeSet<CuratorGroupId>>,
-) -> Result<(), &'static str> {
+) -> DispatchResult {
     TestModule::update_class_permissions(
         Origin::signed(lead_origin),
         class_id,
@@ -653,7 +650,7 @@ pub fn add_class_schema(
     class_id: ClassId,
     existing_properties: BTreeSet<PropertyId>,
     new_properties: Vec<Property<Runtime>>,
-) -> Result<(), &'static str> {
+) -> DispatchResult {
     TestModule::add_class_schema(
         Origin::signed(lead_origin),
         class_id,
@@ -667,7 +664,7 @@ pub fn update_class_schema_status(
     class_id: ClassId,
     schema_id: SchemaId,
     status: bool,
-) -> Result<(), &'static str> {
+) -> DispatchResult {
     TestModule::update_class_schema_status(Origin::signed(lead_origin), class_id, schema_id, status)
 }
 
@@ -680,7 +677,7 @@ pub fn class_by_id(class_id: ClassId) -> Class<Runtime> {
 }
 
 pub fn class_exists(class_id: ClassId) -> bool {
-    ClassById::<Runtime>::exists(class_id)
+    ClassById::<Runtime>::contains_key(class_id)
 }
 
 // Vouchers
@@ -690,7 +687,7 @@ pub fn update_entity_creation_voucher(
     class_id: ClassId,
     controller: EntityController<Runtime>,
     maximum_entities_count: EntityId,
-) -> Result<(), &'static str> {
+) -> DispatchResult {
     TestModule::update_entity_creation_voucher(
         Origin::signed(lead_origin),
         class_id,
@@ -710,13 +707,13 @@ pub fn entity_creation_voucher_exists(
     class_id: ClassId,
     entity_controller: &EntityController<Runtime>,
 ) -> bool {
-    EntityCreationVouchers::<Runtime>::exists(class_id, entity_controller)
+    EntityCreationVouchers::<Runtime>::contains_key(class_id, entity_controller)
 }
 
 // Entities
 
 pub fn entity_exists(entity_id: EntityId) -> bool {
-    EntityById::<Runtime>::exists(entity_id)
+    EntityById::<Runtime>::contains_key(entity_id)
 }
 
 pub fn entity_by_id(entity_id: EntityId) -> Entity<Runtime> {
@@ -727,19 +724,11 @@ pub fn next_entity_id() -> EntityId {
     TestModule::next_entity_id()
 }
 
-pub fn create_entity(
-    origin: u64,
-    class_id: ClassId,
-    actor: Actor<Runtime>,
-) -> Result<(), &'static str> {
+pub fn create_entity(origin: u64, class_id: ClassId, actor: Actor<Runtime>) -> DispatchResult {
     TestModule::create_entity(Origin::signed(origin), class_id, actor)
 }
 
-pub fn remove_entity(
-    origin: u64,
-    actor: Actor<Runtime>,
-    entity_id: EntityId,
-) -> Result<(), &'static str> {
+pub fn remove_entity(origin: u64, actor: Actor<Runtime>, entity_id: EntityId) -> DispatchResult {
     TestModule::remove_entity(Origin::signed(origin), actor, entity_id)
 }
 
@@ -748,7 +737,7 @@ pub fn update_entity_permissions(
     entity_id: EntityId,
     updated_frozen: Option<bool>,
     updated_referenceable: Option<bool>,
-) -> Result<(), &'static str> {
+) -> DispatchResult {
     TestModule::update_entity_permissions(
         Origin::signed(lead_origin),
         entity_id,
@@ -763,7 +752,7 @@ pub fn add_schema_support_to_entity(
     entity_id: EntityId,
     schema_id: SchemaId,
     new_property_values: BTreeMap<PropertyId, InputPropertyValue<Runtime>>,
-) -> Result<(), &'static str> {
+) -> DispatchResult {
     TestModule::add_schema_support_to_entity(
         Origin::signed(origin),
         actor,
@@ -778,7 +767,7 @@ pub fn update_entity_property_values(
     actor: Actor<Runtime>,
     entity_id: EntityId,
     new_property_values: BTreeMap<PropertyId, InputPropertyValue<Runtime>>,
-) -> Result<(), &'static str> {
+) -> DispatchResult {
     TestModule::update_entity_property_values(
         Origin::signed(origin),
         actor,
@@ -792,7 +781,7 @@ pub fn clear_entity_property_vector(
     actor: Actor<Runtime>,
     entity_id: EntityId,
     in_class_schema_property_id: PropertyId,
-) -> Result<(), &'static str> {
+) -> DispatchResult {
     TestModule::clear_entity_property_vector(
         Origin::signed(origin),
         actor,
@@ -809,7 +798,7 @@ pub fn insert_at_entity_property_vector(
     index_in_property_vector: VecMaxLength,
     property_value: InputValue<Runtime>,
     nonce: Nonce,
-) -> Result<(), &'static str> {
+) -> DispatchResult {
     TestModule::insert_at_entity_property_vector(
         Origin::signed(origin),
         actor,
@@ -828,7 +817,7 @@ pub fn remove_at_entity_property_vector(
     in_class_schema_property_id: PropertyId,
     index_in_property_vector: VecMaxLength,
     nonce: Nonce,
-) -> Result<(), &'static str> {
+) -> DispatchResult {
     TestModule::remove_at_entity_property_vector(
         Origin::signed(origin),
         actor,
@@ -847,7 +836,7 @@ pub fn transfer_entity_ownership(
         PropertyId,
         InputPropertyValue<Runtime>,
     >,
-) -> Result<(), &'static str> {
+) -> DispatchResult {
     TestModule::transfer_entity_ownership(
         Origin::signed(origin),
         entity_id,
@@ -862,7 +851,7 @@ pub fn transaction(
     origin: u64,
     actor: Actor<Runtime>,
     operations: Vec<OperationType<Runtime>>,
-) -> Result<(), &'static str> {
+) -> DispatchResult {
     TestModule::transaction(Origin::signed(origin), actor, operations)
 }
 

+ 10 - 10
runtime-modules/content-directory/src/permissions.rs

@@ -12,18 +12,18 @@ pub use crate::errors::*;
 use crate::*;
 pub use codec::{Codec, Decode, Encode};
 use core::fmt::Debug;
-use runtime_primitives::traits::{MaybeSerializeDeserialize, Member, SimpleArithmetic};
-
+use frame_support::{ensure, Parameter};
 #[cfg(feature = "std")]
 pub use serde::{Deserialize, Serialize};
-use srml_support::{dispatch, ensure, Parameter};
+use sp_arithmetic::traits::BaseArithmetic;
+use sp_runtime::traits::{MaybeSerializeDeserialize, Member};
 
 /// Model of authentication manager.
 pub trait ActorAuthenticator: system::Trait + Debug {
     /// Curator identifier
     type CuratorId: Parameter
         + Member
-        + SimpleArithmetic
+        + BaseArithmetic
         + Codec
         + Default
         + Copy
@@ -36,7 +36,7 @@ pub trait ActorAuthenticator: system::Trait + Debug {
     /// Member identifier
     type MemberId: Parameter
         + Member
-        + SimpleArithmetic
+        + BaseArithmetic
         + Codec
         + Default
         + Copy
@@ -49,7 +49,7 @@ pub trait ActorAuthenticator: system::Trait + Debug {
     /// Curator group identifier
     type CuratorGroupId: Parameter
         + Member
-        + SimpleArithmetic
+        + BaseArithmetic
         + Codec
         + One
         + Default
@@ -74,7 +74,7 @@ pub trait ActorAuthenticator: system::Trait + Debug {
 pub fn ensure_curator_auth_success<T: ActorAuthenticator>(
     curator_id: &T::CuratorId,
     account_id: &T::AccountId,
-) -> dispatch::Result {
+) -> DispatchResult {
     ensure!(
         T::is_curator(curator_id, account_id),
         ERROR_CURATOR_AUTH_FAILED
@@ -86,7 +86,7 @@ pub fn ensure_curator_auth_success<T: ActorAuthenticator>(
 pub fn ensure_member_auth_success<T: ActorAuthenticator>(
     member_id: &T::MemberId,
     account_id: &T::AccountId,
-) -> dispatch::Result {
+) -> DispatchResult {
     ensure!(
         T::is_member(member_id, account_id),
         ERROR_MEMBER_AUTH_FAILED
@@ -97,13 +97,13 @@ pub fn ensure_member_auth_success<T: ActorAuthenticator>(
 /// Ensure lead authorization performed succesfully
 pub fn ensure_lead_auth_success<T: ActorAuthenticator>(
     account_id: &T::AccountId,
-) -> dispatch::Result {
+) -> DispatchResult {
     ensure!(T::is_lead(account_id), ERROR_LEAD_AUTH_FAILED);
     Ok(())
 }
 
 /// Ensure given `Origin` is lead
-pub fn ensure_is_lead<T: ActorAuthenticator>(origin: T::Origin) -> dispatch::Result {
+pub fn ensure_is_lead<T: ActorAuthenticator>(origin: T::Origin) -> DispatchResult {
     let account_id = ensure_signed(origin)?;
     ensure_lead_auth_success::<T>(&account_id)
 }

+ 4 - 7
runtime-modules/content-directory/src/permissions/class.rs

@@ -88,7 +88,7 @@ impl<T: Trait> ClassPermissions<T> {
         &self,
         account_id: &T::AccountId,
         actor: &Actor<T>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         let can_create = match &actor {
             Actor::Lead => {
                 // Ensure lead authorization performed succesfully
@@ -118,16 +118,13 @@ impl<T: Trait> ClassPermissions<T> {
     }
 
     /// Ensure entities creation is not blocked on `Class` level
-    pub fn ensure_entity_creation_not_blocked(&self) -> dispatch::Result {
+    pub fn ensure_entity_creation_not_blocked(&self) -> DispatchResult {
         ensure!(!self.entity_creation_blocked, ERROR_ENTITY_CREATION_BLOCKED);
         Ok(())
     }
 
     /// Ensure maintainer, associated with given `curator_group_id` is already added to `maintainers` set
-    pub fn ensure_maintainer_exists(
-        &self,
-        curator_group_id: &T::CuratorGroupId,
-    ) -> dispatch::Result {
+    pub fn ensure_maintainer_exists(&self, curator_group_id: &T::CuratorGroupId) -> DispatchResult {
         ensure!(
             self.maintainers.contains(curator_group_id),
             ERROR_MAINTAINER_DOES_NOT_EXIST
@@ -139,7 +136,7 @@ impl<T: Trait> ClassPermissions<T> {
     pub fn ensure_maintainer_does_not_exist(
         &self,
         curator_group_id: &T::CuratorGroupId,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         ensure!(
             !self.maintainers.contains(curator_group_id),
             ERROR_MAINTAINER_ALREADY_EXISTS

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

@@ -62,7 +62,7 @@ impl<T: Trait> CuratorGroup<T> {
     }
 
     /// Ensure curator group does not maintain any `Class`
-    pub fn ensure_curator_group_maintains_no_classes(&self) -> dispatch::Result {
+    pub fn ensure_curator_group_maintains_no_classes(&self) -> DispatchResult {
         ensure!(
             self.number_of_classes_maintained == 0,
             ERROR_CURATOR_GROUP_REMOVAL_FORBIDDEN
@@ -71,7 +71,7 @@ impl<T: Trait> CuratorGroup<T> {
     }
 
     /// Ensure `MaxNumberOfCuratorsPerGroup` constraint satisfied
-    pub fn ensure_max_number_of_curators_limit_not_reached(&self) -> dispatch::Result {
+    pub fn ensure_max_number_of_curators_limit_not_reached(&self) -> DispatchResult {
         ensure!(
             self.curators.len() < T::MaxNumberOfCuratorsPerGroup::get() as usize,
             ERROR_NUMBER_OF_CURATORS_PER_GROUP_LIMIT_REACHED
@@ -80,7 +80,7 @@ impl<T: Trait> CuratorGroup<T> {
     }
 
     /// Ensure curator under given `curator_id` exists in `CuratorGroup`
-    pub fn ensure_curator_in_group_exists(&self, curator_id: &T::CuratorId) -> dispatch::Result {
+    pub fn ensure_curator_in_group_exists(&self, curator_id: &T::CuratorId) -> DispatchResult {
         ensure!(
             self.get_curators().contains(curator_id),
             ERROR_CURATOR_IS_NOT_A_MEMBER_OF_A_GIVEN_CURATOR_GROUP
@@ -93,7 +93,7 @@ impl<T: Trait> CuratorGroup<T> {
         curator_id: &T::CuratorId,
         curator_group_id: &T::CuratorGroupId,
         account_id: &T::AccountId,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         // Ensure curator authorization performed succesfully
         ensure_curator_auth_success::<T>(curator_id, account_id)?;
 

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

@@ -93,7 +93,7 @@ impl<T: Trait> EntityPermissions<T> {
     }
 
     /// Ensure actor with given `EntityAccessLevel` can remove entity
-    pub fn ensure_group_can_remove_entity(access_level: EntityAccessLevel) -> dispatch::Result {
+    pub fn ensure_group_can_remove_entity(access_level: EntityAccessLevel) -> DispatchResult {
         match access_level {
             EntityAccessLevel::EntityController => Ok(()),
             EntityAccessLevel::EntityControllerAndMaintainer => Ok(()),
@@ -105,7 +105,7 @@ impl<T: Trait> EntityPermissions<T> {
     pub fn ensure_controllers_are_not_equal(
         &self,
         new_entity_controller: &EntityController<T>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         ensure!(
             !self.controller_is_equal_to(new_entity_controller),
             ERROR_PROVIDED_ENTITY_CONTROLLER_IS_EQUAL_TO_CURRENT_ONE

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

@@ -52,7 +52,7 @@ impl<T: Trait> EntityCreationVoucher<T> {
     pub fn ensure_new_max_entities_count_is_valid(
         self,
         maximum_entities_count: T::EntityId,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         ensure!(
             maximum_entities_count >= self.entities_created,
             ERROR_NEW_ENTITIES_MAX_COUNT_IS_LESS_THAN_NUMBER_OF_ALREADY_CREATED
@@ -61,7 +61,7 @@ impl<T: Trait> EntityCreationVoucher<T> {
     }
 
     /// Ensure voucher limit not reached
-    pub fn ensure_voucher_limit_not_reached(&self) -> dispatch::Result {
+    pub fn ensure_voucher_limit_not_reached(&self) -> DispatchResult {
         ensure!(self.limit_not_reached(), ERROR_VOUCHER_LIMIT_REACHED);
         Ok(())
     }

+ 21 - 21
runtime-modules/content-directory/src/schema.rs

@@ -89,7 +89,7 @@ impl<T: Trait> VecPropertyType<T> {
     }
 
     /// Ensure `Type` specific `TextMaxLengthConstraint` & `VecMaxLengthConstraint` satisfied
-    fn ensure_property_type_size_is_valid(&self) -> dispatch::Result {
+    fn ensure_property_type_size_is_valid(&self) -> DispatchResult {
         if let Type::Text(text_max_len) = self.vec_type {
             ensure!(
                 text_max_len <= T::TextMaxLengthConstraint::get(),
@@ -131,7 +131,7 @@ impl<T: Trait> Default for SingleValuePropertyType<T> {
 
 impl<T: Trait> SingleValuePropertyType<T> {
     /// Ensure `Type` specific `TextMaxLengthConstraint` or `HashedTextMaxLengthConstraint` satisfied
-    fn ensure_property_type_size_is_valid(&self) -> dispatch::Result {
+    fn ensure_property_type_size_is_valid(&self) -> DispatchResult {
         if let Type::Text(text_max_len) = self.0 {
             ensure!(
                 text_max_len <= T::TextMaxLengthConstraint::get(),
@@ -243,7 +243,7 @@ impl Schema {
     }
 
     /// Ensure schema in `active` status
-    pub fn ensure_is_active(&self) -> dispatch::Result {
+    pub fn ensure_is_active(&self) -> DispatchResult {
         ensure!(self.is_active, ERROR_CLASS_SCHEMA_NOT_ACTIVE);
         Ok(())
     }
@@ -257,7 +257,7 @@ impl Schema {
     pub fn ensure_has_properties<T: Trait>(
         &self,
         property_values: &BTreeMap<PropertyId, InputPropertyValue<T>>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         let property_value_indices: BTreeSet<PropertyId> =
             property_values.keys().cloned().collect();
 
@@ -322,7 +322,7 @@ impl<T: Trait> Property<T> {
     }
 
     /// Ensure `Property` is unlocked from `Actor` with given `EntityAccessLevel`
-    pub fn ensure_unlocked_from(&self, access_level: EntityAccessLevel) -> dispatch::Result {
+    pub fn ensure_unlocked_from(&self, access_level: EntityAccessLevel) -> DispatchResult {
         ensure!(
             !self.is_locked_from(access_level),
             ERROR_CLASS_PROPERTY_TYPE_IS_LOCKED_FOR_GIVEN_ACTOR
@@ -336,7 +336,7 @@ impl<T: Trait> Property<T> {
         &self,
         value: &InputPropertyValue<T>,
         current_entity_controller: &EntityController<T>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         // Ensure provided InputPropertyValue matches its Type
         self.ensure_property_value_matches_its_type(value)?;
 
@@ -359,7 +359,7 @@ impl<T: Trait> Property<T> {
         vec_value: &VecOutputPropertyValue<T>,
         index_in_property_vec: VecMaxLength,
         current_entity_controller: &EntityController<T>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         // Ensure, provided index_in_property_vec is valid index of VecInputValue
         vec_value.ensure_index_in_property_vector_is_valid(index_in_property_vec)?;
 
@@ -367,7 +367,7 @@ impl<T: Trait> Property<T> {
         fn validate_property_vector_length_after_value_insert<T>(
             vec: &[T],
             max_len: VecMaxLength,
-        ) -> dispatch::Result {
+        ) -> DispatchResult {
             ensure!(
                 vec.len() < max_len as usize,
                 ERROR_ENTITY_PROP_VALUE_VECTOR_IS_TOO_LONG
@@ -448,7 +448,7 @@ impl<T: Trait> Property<T> {
     pub fn validate_max_len_if_text_property(
         &self,
         value: &InputPropertyValue<T>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         let single_value = value.as_single_value();
 
         match (single_value, &self.property_type.as_single_value_type()) {
@@ -466,7 +466,7 @@ impl<T: Trait> Property<T> {
         }
     }
 
-    pub fn validate_max_len_of_text(text: &[u8], text_max_len: TextMaxLength) -> dispatch::Result {
+    pub fn validate_max_len_of_text(text: &[u8], text_max_len: TextMaxLength) -> DispatchResult {
         ensure!(
             text.len() <= text_max_len as usize,
             ERROR_TEXT_PROP_IS_TOO_LONG
@@ -477,7 +477,7 @@ impl<T: Trait> Property<T> {
     pub fn validate_max_len_of_text_to_be_hashed(
         text_to_be_hashed: &[u8],
         text_to_be_hashed_max_len: u16,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         ensure!(
             text_to_be_hashed.len() <= text_to_be_hashed_max_len as usize,
             ERROR_HASHED_TEXT_PROP_IS_TOO_LONG
@@ -485,7 +485,7 @@ impl<T: Trait> Property<T> {
         Ok(())
     }
 
-    fn validate_vec_len<V>(vec: &[V], max_len: VecMaxLength) -> dispatch::Result {
+    fn validate_vec_len<V>(vec: &[V], max_len: VecMaxLength) -> DispatchResult {
         ensure!(vec.len() <= max_len as usize, ERROR_VEC_PROP_IS_TOO_LONG);
         Ok(())
     }
@@ -494,7 +494,7 @@ impl<T: Trait> Property<T> {
     pub fn validate_max_len_if_vec_property(
         &self,
         value: &InputPropertyValue<T>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         let (vec_value, vec_property_type) = if let (Some(vec_value), Some(vec_property_type)) =
             (value.as_vec_value(), self.property_type.as_vec_type())
         {
@@ -544,7 +544,7 @@ impl<T: Trait> Property<T> {
     pub fn ensure_property_value_matches_its_type(
         &self,
         value: &InputPropertyValue<T>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         ensure!(
             self.does_prop_value_match_type(value),
             ERROR_PROP_VALUE_DONT_MATCH_TYPE
@@ -601,7 +601,7 @@ impl<T: Trait> Property<T> {
         &self,
         value: &InputPropertyValue<T>,
         current_entity_controller: &EntityController<T>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         match (value, &self.property_type) {
             (
                 InputPropertyValue::Single(single_property_value),
@@ -676,7 +676,7 @@ impl<T: Trait> Property<T> {
         entity: Entity<T>,
         same_controller_status: bool,
         current_entity_controller: &EntityController<T>,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         let entity_permissions = entity.get_permissions();
 
         // Ensure Entity is referencable
@@ -696,7 +696,7 @@ impl<T: Trait> Property<T> {
     }
 
     /// Ensure `PropertyNameLengthConstraint` satisfied
-    pub fn ensure_name_is_valid(&self) -> dispatch::Result {
+    pub fn ensure_name_is_valid(&self) -> DispatchResult {
         T::PropertyNameLengthConstraint::get().ensure_valid(
             self.name.len(),
             ERROR_PROPERTY_NAME_TOO_SHORT,
@@ -705,7 +705,7 @@ impl<T: Trait> Property<T> {
     }
 
     /// Ensure `PropertyDescriptionLengthConstraint` satisfied
-    pub fn ensure_description_is_valid(&self) -> dispatch::Result {
+    pub fn ensure_description_is_valid(&self) -> DispatchResult {
         T::PropertyDescriptionLengthConstraint::get().ensure_valid(
             self.description.len(),
             ERROR_PROPERTY_DESCRIPTION_TOO_SHORT,
@@ -714,7 +714,7 @@ impl<T: Trait> Property<T> {
     }
 
     /// Ensure `Type` specific constraints satisfied
-    pub fn ensure_property_type_size_is_valid(&self) -> dispatch::Result {
+    pub fn ensure_property_type_size_is_valid(&self) -> DispatchResult {
         match &self.property_type {
             PropertyType::Single(single_property_type) => {
                 // Ensure Type specific TextMaxLengthConstraint satisfied
@@ -728,10 +728,10 @@ impl<T: Trait> Property<T> {
     }
 
     /// Ensure refers to existing `class_id`, if If `Property` `Type` is `Reference`,
-    pub fn ensure_property_type_reference_is_valid(&self) -> dispatch::Result {
+    pub fn ensure_property_type_reference_is_valid(&self) -> DispatchResult {
         let has_unknown_reference =
             if let Type::Reference(other_class_id, _) = self.property_type.get_inner_type() {
-                !<ClassById<T>>::exists(other_class_id)
+                !<ClassById<T>>::contains_key(other_class_id)
             } else {
                 false
             };

+ 1 - 1
runtime-modules/content-directory/src/schema/convert.rs

@@ -1,5 +1,5 @@
 use super::*;
-use runtime_primitives::traits::Hash;
+use sp_runtime::traits::Hash;
 
 impl<T: Trait> From<InputPropertyValue<T>> for OutputPropertyValue<T> {
     fn from(input_property_value: InputPropertyValue<T>) -> Self {

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

@@ -69,6 +69,7 @@ impl<T: Trait> OutputPropertyValue<T> {
         }
     }
 
+    /// Make `SimplifiedOutputPropertyValue` from `OutputPropertyValue`
     pub fn simplify(&self) -> SimplifiedOutputPropertyValue<T> {
         self.clone().into()
     }
@@ -243,7 +244,7 @@ impl<T: Trait> VecOutputPropertyValue<T> {
 
     /// Ensure `VecOutputPropertyValue` nonce is equal to the provided one.
     /// Used to to avoid possible data races, when performing vector specific operations
-    pub fn ensure_nonce_equality(&self, new_nonce: T::Nonce) -> dispatch::Result {
+    pub fn ensure_nonce_equality(&self, new_nonce: T::Nonce) -> DispatchResult {
         ensure!(
             self.nonce == new_nonce,
             ERROR_PROP_VALUE_VEC_NONCES_DOES_NOT_MATCH
@@ -255,7 +256,7 @@ impl<T: Trait> VecOutputPropertyValue<T> {
     pub fn ensure_index_in_property_vector_is_valid(
         &self,
         index_in_property_vec: VecMaxLength,
-    ) -> dispatch::Result {
+    ) -> DispatchResult {
         ensure!(
             (index_in_property_vec as usize) <= self.len(),
             ERROR_ENTITY_PROP_VALUE_VECTOR_INDEX_IS_OUT_OF_RANGE

Some files were not shown because too many files changed in this diff