storage.rs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. use crate::working_group::WorkingGroup;
  2. use codec::{Decode, Encode};
  3. #[cfg(feature = "std")]
  4. use serde::{Deserialize, Serialize};
  5. use sp_runtime::DispatchResult;
  6. use sp_std::vec::Vec;
  7. #[derive(Clone, Encode, Decode, PartialEq, Eq, Debug)]
  8. pub struct ContentParameters<ContentId, DataObjectTypeId> {
  9. pub content_id: ContentId,
  10. pub type_id: DataObjectTypeId,
  11. pub size: u64,
  12. pub ipfs_content_id: Vec<u8>,
  13. }
  14. // New owner type for storage object struct
  15. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  16. #[derive(Clone, Encode, Decode, PartialEq, Eq, Debug)]
  17. pub enum StorageObjectOwner<MemberId, ChannelId, DAOId> {
  18. Member(MemberId),
  19. Channel(ChannelId), // acts through content directory module, where again DAOs can own channels for example
  20. DAO(DAOId), // acts through upcoming `content_finance` module
  21. Council, // acts through proposal frame_system
  22. WorkingGroup(WorkingGroup), // acts through new extrinsic in working group
  23. }
  24. impl<MemberId, ChannelId, DAOId> Default for StorageObjectOwner<MemberId, ChannelId, DAOId> {
  25. fn default() -> Self {
  26. Self::Council
  27. }
  28. }
  29. // To be implemented by current storage data_directory runtime module.
  30. // Defined in 'common' package
  31. pub trait StorageSystem<T: crate::StorageOwnership + crate::MembershipTypes> {
  32. fn atomically_add_content(
  33. owner: StorageObjectOwner<T::MemberId, T::ChannelId, T::DAOId>,
  34. content_parameters: Vec<ContentParameters<T::ContentId, T::DataObjectTypeId>>,
  35. ) -> DispatchResult;
  36. // Checks if given owner can add provided content to the storage frame_system
  37. fn can_add_content(
  38. owner: StorageObjectOwner<T::MemberId, T::ChannelId, T::DAOId>,
  39. content_parameters: Vec<ContentParameters<T::ContentId, T::DataObjectTypeId>>,
  40. ) -> DispatchResult;
  41. fn atomically_remove_content(
  42. owner: &StorageObjectOwner<T::MemberId, T::ChannelId, T::DAOId>,
  43. content_ids: &[T::ContentId],
  44. ) -> DispatchResult;
  45. // Checks if given owner can remove content under given content ids from the storage frame_system
  46. fn can_remove_content(
  47. owner: &StorageObjectOwner<T::MemberId, T::ChannelId, T::DAOId>,
  48. content_ids: &[T::ContentId],
  49. ) -> DispatchResult;
  50. }