|
@@ -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);
|