Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
768 changes: 710 additions & 58 deletions Cargo.lock

Large diffs are not rendered by default.

44 changes: 17 additions & 27 deletions runtime-modules/content-directory/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,40 +1,30 @@
[package]
name = 'substrate-content-directory-module'
version = '1.0.1'
name = 'pallet-content-directory'
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'

[dependencies.serde]
features = ['derive']
optional = true
version = '1.0.101'
sp-std = { 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'}
codec = { package = 'parity-scale-codec', version = '1.3.1', default-features = false, features = ['derive'] }
serde = {version = '1.0.101', features = ['derive'], optional = true}

[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']
std = [
'serde',
'codec/std',
'rstd/std',
'runtime-io/std',
'runtime-primitives/std',
'srml-support/std',
'sp-std/std',
'sp-runtime/std',
'frame-support/std',
'system/std',
'timestamp/std',
'sp-arithmetic/std',
'codec/std',
'serde',
]
28 changes: 14 additions & 14 deletions runtime-modules/content-directory/src/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,26 +161,26 @@ impl<T: Trait> Class<T> {
}

/// Ensure `Class` `Schema` under given index exist, return corresponding `Schema`
pub fn ensure_schema_exists(&self, schema_index: SchemaId) -> Result<&Schema, &'static str> {
pub fn ensure_schema_exists(&self, schema_index: SchemaId) -> Result<&Schema, Error<T>> {
self.schemas
.get(schema_index as usize)
.ok_or(ERROR_UNKNOWN_CLASS_SCHEMA_ID)
.ok_or(Error::<T>::UnknownClassSchemaId)
}

/// 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) -> Result<(), Error<T>> {
ensure!(
schema_id < self.schemas.len() as SchemaId,
ERROR_UNKNOWN_CLASS_SCHEMA_ID
Error::<T>::UnknownClassSchemaId
);
Ok(())
}

/// 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) -> Result<(), Error<T>> {
ensure!(
(self.schemas.len() as MaxNumber) < T::MaxNumberOfSchemasPerClass::get(),
ERROR_CLASS_SCHEMAS_LIMIT_REACHED
Error::<T>::ClassSchemasLimitReached
);
Ok(())
}
Expand All @@ -189,20 +189,20 @@ impl<T: Trait> Class<T> {
pub fn ensure_properties_limit_not_reached(
&self,
new_properties: &[Property<T>],
) -> dispatch::Result {
) -> Result<(), Error<T>> {
ensure!(
T::MaxNumberOfPropertiesPerSchema::get()
>= (self.properties.len() + new_properties.len()) as MaxNumber,
ERROR_SCHEMA_PROPERTIES_LIMIT_REACHED
Error::<T>::SchemaPropertiesLimitReached
);
Ok(())
}

/// 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) -> Result<(), Error<T>> {
ensure!(
self.current_number_of_entities < self.maximum_entities_count,
ERROR_MAX_NUMBER_OF_ENTITIES_PER_CLASS_LIMIT_REACHED
Error::<T>::NumberOfEntitiesPerClassLimitReached
);
Ok(())
}
Expand All @@ -213,7 +213,7 @@ impl<T: Trait> Class<T> {
&self,
in_class_schema_property_id: PropertyId,
entity_access_level: EntityAccessLevel,
) -> Result<Property<T>, &'static str> {
) -> Result<Property<T>, Error<T>> {
// Ensure property values were not locked on Class level
self.ensure_property_values_unlocked()?;

Expand All @@ -223,7 +223,7 @@ impl<T: Trait> Class<T> {
.get(in_class_schema_property_id as usize)
// Throw an error if a property was not found on class
// by an in-class index of a property.
.ok_or(ERROR_CLASS_PROP_NOT_FOUND)?;
.ok_or(Error::<T>::ClassPropertyNotFound)?;

// Ensure Property is unlocked from Actor with given EntityAccessLevel
class_property.ensure_unlocked_from(entity_access_level)?;
Expand All @@ -232,12 +232,12 @@ 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) -> Result<(), Error<T>> {
ensure!(
!self
.get_permissions_ref()
.all_entity_property_values_locked(),
ERROR_ALL_PROP_WERE_LOCKED_ON_CLASS_LEVEL
Error::<T>::AllPropertiesWereLockedOnClassLevel
);
Ok(())
}
Expand Down
24 changes: 12 additions & 12 deletions runtime-modules/content-directory/src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Entity<T: Trait> {
/// The class id of this entity.
class_id: T::ClassId,

/// What schemas under which this entity of a class is available, think
/// What schemas under which entity of the respective class is available, think
/// v.2.0 Person schema for John, v3.0 Person schema for John
/// Unlikely to be more than roughly 20ish, assuming schemas for a given class eventually stableize,
/// or that very old schema are eventually removed.
Expand Down Expand Up @@ -104,22 +104,22 @@ 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) -> Result<(), Error<T>> {
let schema_not_added = !self.supported_schemas.contains(&schema_id);
ensure!(schema_not_added, ERROR_SCHEMA_ALREADY_ADDED_TO_THE_ENTITY);
ensure!(schema_not_added, Error::<T>::SchemaAlreadyAddedToTheEntity);
Ok(())
}

/// Ensure provided `property_values` are not added to the `Entity` `values` map yet
pub fn ensure_property_values_are_not_added(
&self,
property_values: &BTreeMap<PropertyId, InputPropertyValue<T>>,
) -> dispatch::Result {
) -> Result<(), Error<T>> {
ensure!(
property_values
.keys()
.all(|key| !self.values.contains_key(key)),
ERROR_ENTITY_ALREADY_CONTAINS_GIVEN_PROPERTY_ID
Error::<T>::EntityAlreadyContainsGivenPropertyId
);
Ok(())
}
Expand All @@ -128,32 +128,32 @@ impl<T: Trait> Entity<T> {
pub fn ensure_property_value_is_vec(
&self,
in_class_schema_property_id: PropertyId,
) -> Result<VecStoredPropertyValue<T>, &'static str> {
) -> Result<VecStoredPropertyValue<T>, Error<T>> {
self.values
.get(&in_class_schema_property_id)
// Throw an error if a property was not found on entity
// by an in-class index of a property.
.ok_or(ERROR_UNKNOWN_ENTITY_PROP_ID)?
.ok_or(Error::<T>::UnknownEntityPropertyId)?
.as_vec_property_value()
.map(|property_value_vec| property_value_vec.to_owned())
// Ensure prop value under given class schema property id is vector
.ok_or(ERROR_PROP_VALUE_UNDER_GIVEN_INDEX_IS_NOT_A_VECTOR)
.ok_or(Error::<T>::PropertyValueUnderGivenIndexIsNotAVector)
}

/// 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) -> Result<(), Error<T>> {
ensure!(
self.reference_counter.is_total_equal_to_zero(),
ERROR_ENTITY_RC_DOES_NOT_EQUAL_TO_ZERO
Error::<T>::EntityRcDoesNotEqualToZero
);
Ok(())
}

/// 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) -> Result<(), Error<T>> {
ensure!(
self.reference_counter.is_same_owner_equal_to_zero(),
ERROR_ENTITY_SAME_OWNER_RC_DOES_NOT_EQUAL_TO_ZERO
Error::<T>::EntityInboundSameOwnerRcDoesNotEqualToZero
);
Ok(())
}
Expand Down
Loading