storage.rs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #[allow(clippy::upper_case_acronyms)]
  21. DAO(DAOId), // acts through upcoming `content_finance` module
  22. Council, // acts through proposal frame_system
  23. WorkingGroup(WorkingGroup), // acts through new extrinsic in working group
  24. }
  25. impl<MemberId, ChannelId, DAOId> Default for StorageObjectOwner<MemberId, ChannelId, DAOId> {
  26. fn default() -> Self {
  27. Self::Council
  28. }
  29. }
  30. // To be implemented by current storage data_directory runtime module.
  31. // Defined in 'common' package
  32. pub trait StorageSystem<T: crate::StorageOwnership + crate::MembershipTypes> {
  33. fn atomically_add_content(
  34. owner: StorageObjectOwner<T::MemberId, T::ChannelId, T::DAOId>,
  35. content_parameters: Vec<ContentParameters<T::ContentId, T::DataObjectTypeId>>,
  36. ) -> DispatchResult;
  37. // Checks if given owner can add provided content to the storage frame_system
  38. fn can_add_content(
  39. owner: StorageObjectOwner<T::MemberId, T::ChannelId, T::DAOId>,
  40. content_parameters: Vec<ContentParameters<T::ContentId, T::DataObjectTypeId>>,
  41. ) -> DispatchResult;
  42. fn atomically_remove_content(
  43. owner: &StorageObjectOwner<T::MemberId, T::ChannelId, T::DAOId>,
  44. content_ids: &[T::ContentId],
  45. ) -> DispatchResult;
  46. // Checks if given owner can remove content under given content ids from the storage frame_system
  47. fn can_remove_content(
  48. owner: &StorageObjectOwner<T::MemberId, T::ChannelId, T::DAOId>,
  49. content_ids: &[T::ContentId],
  50. ) -> DispatchResult;
  51. }