Browse Source

Add comments to the data_directory storage module.

Shamil Gadelshin 4 years ago
parent
commit
27d0d148fe

+ 58 - 12
runtime-modules/storage/src/data_directory.rs

@@ -1,9 +1,29 @@
+//! # Data directory module
+//! Data directory module for the Joystream platform manages IPFS content id, storage providers,
+//! owners of the content. It allows to add and accept or reject the content in the system.
+//!
+//! ## Comments
+//!
+//! Data object type registry module uses bureaucracy module to authorize actions.
+//!
+//! ## Supported extrinsics
+//!
+//! ### Public extrinsic
+//! - [add_content](./struct.Module.html#method.add_content) - Adds the content to the system.
+//!
+//! ### Private extrinsics
+//! - accept_content - Storage provider accepts a content.
+//! - reject_content - Storage provider rejects a content.
+//! - remove_known_content_id - Removes the content id from the list of known content ids. Requires root privileges.
+//! - set_known_content_id - Sets the content id from the list of known content ids. Requires root privileges.
+//!
+
 // Do not delete! Cannot be uncommented by default, because of Parity decl_module! issue.
 //#![warn(missing_docs)]
 
-use codec::{Codec, Decode, Encode};
+use codec::{Decode, Encode};
 use rstd::prelude::*;
-use sr_primitives::traits::{MaybeSerialize, Member, SimpleArithmetic};
+use sr_primitives::traits::{MaybeSerialize, Member};
 use srml_support::{decl_event, decl_module, decl_storage, dispatch, ensure, Parameter};
 use system::{self, ensure_root};
 
@@ -16,6 +36,7 @@ use crate::{StorageBureaucracy, StorageProviderId, MemberId};
 
 // TODO: create a StorageProviderHelper implementation
 
+/// The _Data directory_ main _Trait_.
 pub trait Trait:
     timestamp::Trait
     + system::Trait
@@ -23,20 +44,16 @@ pub trait Trait:
     + membership::members::Trait
     + bureaucracy::Trait<bureaucracy::Instance2>
 {
+    /// _Data directory_ event type.
     type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
 
+    /// Content id.
     type ContentId: Parameter + Member + MaybeSerialize + Copy + Ord + Default;
 
-    type SchemaId: Parameter
-        + Member
-        + SimpleArithmetic
-        + Codec
-        + Default
-        + Copy
-        + MaybeSerialize
-        + PartialEq;
-
+    /// Provides random storage provider id.
     type StorageProviderHelper: StorageProviderHelper<Self>;
+
+    ///Active data object type validator.
     type IsActiveDataObjectType: data_object_type_registry::IsActiveDataObjectType<Self>;
 
     /// Validates member id and origin combination.
@@ -59,10 +76,16 @@ pub struct BlockAndTime<T: Trait> {
     pub time: T::Moment,
 }
 
+/// The decision of the storage provider when it acts as liaison.
 #[derive(Clone, Encode, Decode, PartialEq, Debug)]
 pub enum LiaisonJudgement {
+    /// Content awaits for a judgment.
     Pending,
+
+    /// Content accepted.
     Accepted,
+
+    /// Content rejected.
     Rejected,
 }
 
@@ -75,15 +98,30 @@ impl Default for LiaisonJudgement {
 /// Manages content ids, type and storage provider decision about it.
 #[derive(Clone, Encode, Decode, PartialEq, Debug)]
 pub struct DataObject<T: Trait> {
+    /// Content owner.
     pub owner: MemberId<T>,
+
+    /// Content added at.
     pub added_at: BlockAndTime<T>,
+
+    /// Content type id.
     pub type_id: <T as data_object_type_registry::Trait>::DataObjectTypeId,
+
+    /// Content size in bytes.
     pub size: u64,
+
+    /// Storage provider id of the liaison.
     pub liaison: StorageProviderId<T>,
+
+    /// Storage provider as liaison judgment.
     pub liaison_judgement: LiaisonJudgement,
+
+    /// IPFS content id.
     pub ipfs_content_id: Vec<u8>,
 }
 
+//TODO consider to remove
+
 #[derive(Clone, Encode, Decode, PartialEq, Debug)]
 pub enum ContentVisibility {
     Draft,
@@ -98,8 +136,10 @@ impl Default for ContentVisibility {
 
 decl_storage! {
     trait Store for Module<T: Trait> as DataDirectory {
-        pub KnownContentIds get(known_content_ids): Vec<T::ContentId> = vec![];
+        /// List of ids known to the system.
+        pub KnownContentIds get(known_content_ids): Vec<T::ContentId> = Vec::new();
 
+        /// Maps data objects by their content id.
         pub DataObjectByContentId get(data_object_by_content_id):
             map T::ContentId => Option<DataObject<T>>;
     }
@@ -133,9 +173,13 @@ decl_event! {
 }
 
 decl_module! {
+    /// _Data directory_ substrate module.
     pub struct Module<T: Trait> for enum Call where origin: T::Origin {
+        /// Default deposit_event() handler
         fn deposit_event() = default;
 
+        /// Adds the content to the system. Member id should match its origin. The created DataObject
+        /// awaits liaison to accept or reject it.
         pub fn add_content(
             origin,
             member_id: MemberId<T>,
@@ -211,6 +255,7 @@ decl_module! {
 
         // Sudo methods
 
+        /// Removes the content id from the list of known content ids. Requires root privileges.
         fn remove_known_content_id(origin, content_id: T::ContentId) {
             ensure_root(origin)?;
 
@@ -223,6 +268,7 @@ decl_module! {
             <KnownContentIds<T>>::put(upd_content_ids);
         }
 
+        /// Sets the content id from the list of known content ids. Requires root privileges.
         fn set_known_content_id(origin, content_ids: Vec<T::ContentId>) {
             ensure_root(origin)?;
 

+ 3 - 4
runtime-modules/storage/src/data_object_storage_registry.rs

@@ -1,7 +1,6 @@
 //! # Data object storage registry module
-//! Data object storage registry module for the Joystream platform.
-//! It allows to set relationships between the content and the storage providers.
-//! All extrinsics require storage working group registration.
+//! Data object storage registry module for the Joystream platform allows to set relationships
+//! between the content and the storage providers. All extrinsics require storage working group registration.
 //!
 //! ## Comments
 //!
@@ -33,7 +32,7 @@ use crate::{StorageBureaucracy, StorageProviderId};
 
 const DEFAULT_FIRST_RELATIONSHIP_ID: u32 = 1;
 
-/// The _Data object storage registry_ main _Trait_
+/// The _Data object storage registry_ main _Trait_.
 pub trait Trait:
     timestamp::Trait
     + system::Trait

+ 2 - 3
runtime-modules/storage/src/data_object_type_registry.rs

@@ -1,6 +1,5 @@
 //! # Data object type registry module
-//! Data object type registry module for the Joystream platform.
-//! It allows to set constraints for the data objects. All extrinsics require leader
+//! Data object type registry module for the Joystream platform allows to set constraints for the data objects. All extrinsics require leader.
 //!
 //! ## Comments
 //!
@@ -32,7 +31,7 @@ use srml_support::{decl_error, decl_event, decl_module, decl_storage, Parameter}
 const DEFAULT_TYPE_DESCRIPTION: &str = "Default data object type for audio and video content.";
 const DEFAULT_FIRST_DATA_OBJECT_TYPE_ID: u32 = 1;
 
-/// The _Data object type registry_ main _Trait_
+/// The _Data object type registry_ main _Trait_.
 pub trait Trait: system::Trait + bureaucracy::Trait<bureaucracy::Instance2> {
     /// _Data object type registry_ event type.
     type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;

+ 0 - 1
runtime/src/lib.rs

@@ -695,7 +695,6 @@ impl storage::data_object_type_registry::Trait for Runtime {
 impl storage::data_directory::Trait for Runtime {
     type Event = Event;
     type ContentId = ContentId;
-    type SchemaId = u64;
     type StorageProviderHelper = integration::storage::StorageProviderHelper;
     type IsActiveDataObjectType = DataObjectTypeRegistry;
     type MemberOriginValidator = MembershipOriginValidator<Self>;