|
@@ -40,6 +40,12 @@ use crate::data_object_type_registry;
|
|
|
use crate::data_object_type_registry::IsActiveDataObjectType;
|
|
|
use crate::{MemberId, StorageProviderId, StorageWorkingGroup, StorageWorkingGroupInstance};
|
|
|
|
|
|
+// Temporary representation.
|
|
|
+type ChannelId = u64;
|
|
|
+
|
|
|
+// Temporary representation.
|
|
|
+type DAOId = u64;
|
|
|
+
|
|
|
/// The _Data directory_ main _Trait_.
|
|
|
pub trait Trait:
|
|
|
pallet_timestamp::Trait
|
|
@@ -89,6 +95,31 @@ decl_error! {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
|
|
+#[derive(Clone, Encode, Decode, PartialEq, Debug)]
|
|
|
+enum WorkinGroupType {
|
|
|
+ Builders,
|
|
|
+ Marketers,
|
|
|
+ Membership,
|
|
|
+}
|
|
|
+
|
|
|
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
|
|
+#[derive(Clone, Encode, Decode, PartialEq, Debug)]
|
|
|
+enum AbstractStorageObjectOwner {
|
|
|
+ Channel(ChannelId), // acts through content directory module, where again DAOs can own channels for example
|
|
|
+ DAO(DAOId), // acts through upcoming `content_finance` module
|
|
|
+ Council, // acts through proposal system
|
|
|
+ WorkingGroup(WorkinGroupType), // acts through new extrinsic in working group
|
|
|
+}
|
|
|
+
|
|
|
+// New owner type for storage object struct
|
|
|
+#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
|
|
+#[derive(Clone, Encode, Decode, PartialEq, Debug)]
|
|
|
+enum StorageObjectOwner<MemberId> {
|
|
|
+ Member(MemberId),
|
|
|
+ AbstractStorageObjectOwner(AbstractStorageObjectOwner),
|
|
|
+}
|
|
|
+
|
|
|
/// The decision of the storage provider when it acts as liaison.
|
|
|
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
|
|
#[derive(Clone, Encode, Decode, PartialEq, Debug)]
|
|
@@ -123,7 +154,7 @@ pub type DataObject<T> = DataObjectInternal<
|
|
|
#[derive(Clone, Encode, Decode, PartialEq, Debug)]
|
|
|
pub struct DataObjectInternal<MemberId, BlockNumber, Moment, DataObjectTypeId, StorageProviderId> {
|
|
|
/// Content owner.
|
|
|
- pub owner: MemberId,
|
|
|
+ pub owner: StorageObjectOwner<MemberId>,
|
|
|
|
|
|
/// Content added at.
|
|
|
pub added_at: BlockAndTime<BlockNumber, Moment>,
|
|
@@ -162,14 +193,14 @@ decl_event! {
|
|
|
/// _Data directory_ events
|
|
|
pub enum Event<T> where
|
|
|
<T as Trait>::ContentId,
|
|
|
- MemberId = MemberId<T>,
|
|
|
+ StorageObjectOwner = StorageObjectOwner<T::MemberId>,
|
|
|
StorageProviderId = StorageProviderId<T>
|
|
|
{
|
|
|
/// Emits on adding of the content.
|
|
|
/// Params:
|
|
|
/// - Id of the relationship.
|
|
|
/// - Id of the member.
|
|
|
- ContentAdded(ContentId, MemberId),
|
|
|
+ ContentAdded(ContentId, StorageObjectOwner),
|
|
|
|
|
|
/// Emits when the storage provider accepts a content.
|
|
|
/// Params:
|
|
@@ -201,6 +232,48 @@ decl_module! {
|
|
|
/// awaits liaison to accept or reject it.
|
|
|
#[weight = 10_000_000] // TODO: adjust weight
|
|
|
pub fn add_content(
|
|
|
+ origin,
|
|
|
+ abstract_owner: AbstractStorageObjectOwner,
|
|
|
+ content_id: T::ContentId,
|
|
|
+ type_id: <T as data_object_type_registry::Trait>::DataObjectTypeId,
|
|
|
+ size: u64,
|
|
|
+ ipfs_content_id: Vec<u8>
|
|
|
+ ) {
|
|
|
+ ensure_root(origin)?;
|
|
|
+
|
|
|
+ ensure!(T::IsActiveDataObjectType::is_active_data_object_type(&type_id),
|
|
|
+ Error::<T>::DataObjectTypeMustBeActive);
|
|
|
+
|
|
|
+ ensure!(!<DataObjectByContentId<T>>::contains_key(content_id),
|
|
|
+ Error::<T>::DataObjectAlreadyAdded);
|
|
|
+
|
|
|
+ let liaison = T::StorageProviderHelper::get_random_storage_provider()?;
|
|
|
+
|
|
|
+ let owner = StorageObjectOwner::AbstractStorageObjectOwner(abstract_owner);
|
|
|
+
|
|
|
+ // Let's create the entry then
|
|
|
+ let data: DataObject<T> = DataObjectInternal {
|
|
|
+ type_id,
|
|
|
+ size,
|
|
|
+ added_at: common::current_block_time::<T>(),
|
|
|
+ owner,
|
|
|
+ liaison,
|
|
|
+ liaison_judgement: LiaisonJudgement::Pending,
|
|
|
+ ipfs_content_id,
|
|
|
+ };
|
|
|
+
|
|
|
+ //
|
|
|
+ // == MUTATION SAFE ==
|
|
|
+ //
|
|
|
+
|
|
|
+ <DataObjectByContentId<T>>::insert(&content_id, data);
|
|
|
+ Self::deposit_event(RawEvent::ContentAdded(content_id, owner));
|
|
|
+ }
|
|
|
+
|
|
|
+ /// Adds the content to the system. Member id should match its origin. The created DataObject
|
|
|
+ /// awaits liaison to accept or reject it.
|
|
|
+ #[weight = 10_000_000] // TODO: adjust weight
|
|
|
+ pub fn add_content_as_member(
|
|
|
origin,
|
|
|
member_id: MemberId<T>,
|
|
|
content_id: T::ContentId,
|
|
@@ -221,12 +294,14 @@ decl_module! {
|
|
|
|
|
|
let liaison = T::StorageProviderHelper::get_random_storage_provider()?;
|
|
|
|
|
|
+ let owner = StorageObjectOwner::Member(member_id);
|
|
|
+
|
|
|
// Let's create the entry then
|
|
|
let data: DataObject<T> = DataObjectInternal {
|
|
|
type_id,
|
|
|
size,
|
|
|
added_at: common::current_block_time::<T>(),
|
|
|
- owner: member_id,
|
|
|
+ owner,
|
|
|
liaison,
|
|
|
liaison_judgement: LiaisonJudgement::Pending,
|
|
|
ipfs_content_id,
|
|
@@ -237,7 +312,7 @@ decl_module! {
|
|
|
//
|
|
|
|
|
|
<DataObjectByContentId<T>>::insert(&content_id, data);
|
|
|
- Self::deposit_event(RawEvent::ContentAdded(content_id, member_id));
|
|
|
+ Self::deposit_event(RawEvent::ContentAdded(content_id, owner));
|
|
|
}
|
|
|
|
|
|
/// Storage provider accepts a content. Requires signed storage provider account and its id.
|