types.rs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. use crate::*;
  2. /// Specifies how a new asset will be provided on creating and updating
  3. /// Channels, Videos, Series and Person
  4. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  5. #[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
  6. pub enum NewAsset<ContentParameters> {
  7. /// Upload to the storage frame_system
  8. Upload(ContentParameters),
  9. /// Multiple url strings pointing at an asset
  10. Urls(Vec<Url>),
  11. }
  12. /// Data structure in order to keep track of the migration
  13. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  14. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  15. pub struct MigrationConfigRecord<NumericId> {
  16. // at each block the videos/channels removed will be those with id in the
  17. // half open range [current_id, final_id).
  18. // when migration is triggered final_id will be updated
  19. // when migration is performed current_id will be updated
  20. pub current_id: NumericId,
  21. pub final_id: NumericId,
  22. }
  23. pub type VideoMigrationConfig<T> = MigrationConfigRecord<<T as Trait>::VideoId>;
  24. pub type ChannelMigrationConfig<T> = MigrationConfigRecord<<T as storage::Trait>::ChannelId>;
  25. /// The owner of a channel, is the authorized "actor" that can update
  26. /// or delete or transfer a channel and its contents.
  27. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  28. #[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
  29. pub enum ChannelOwner<MemberId, CuratorGroupId> {
  30. /// A Member owns the channel
  31. Member(MemberId),
  32. /// A specific curation group owns the channel
  33. CuratorGroup(CuratorGroupId),
  34. }
  35. // Default trait implemented only because its used in a Channel which needs to implement a Default trait
  36. // since it is a StorageValue.
  37. impl<MemberId: Default, CuratorGroupId> Default for ChannelOwner<MemberId, CuratorGroupId> {
  38. fn default() -> Self {
  39. ChannelOwner::Member(MemberId::default())
  40. }
  41. }
  42. /// A category which channels can belong to.
  43. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  44. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  45. pub struct ChannelCategory {
  46. // No runtime information is currently stored for a Category.
  47. }
  48. /// Information on the category being created.
  49. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  50. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  51. pub struct ChannelCategoryCreationParameters {
  52. /// Metadata for the category.
  53. meta: Vec<u8>,
  54. }
  55. /// Information on the category being updated.
  56. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  57. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  58. pub struct ChannelCategoryUpdateParameters {
  59. // as this is the only field it is not an Option
  60. /// Metadata update for the category.
  61. new_meta: Vec<u8>,
  62. }
  63. /// Type representing an owned channel which videos, playlists, and series can belong to.
  64. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  65. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  66. pub struct ChannelRecord<MemberId: Ord, CuratorGroupId, AccountId, Balance> {
  67. /// The owner of a channel
  68. pub owner: ChannelOwner<MemberId, CuratorGroupId>,
  69. /// The videos under this channel
  70. pub num_videos: u64,
  71. /// If curators have censored this channel or not
  72. pub is_censored: bool,
  73. /// Reward account where revenue is sent if set.
  74. pub reward_account: Option<AccountId>,
  75. /// collaborator set
  76. pub collaborators: BTreeSet<MemberId>,
  77. /// moderator set
  78. pub moderators: BTreeSet<MemberId>,
  79. /// Cumulative cashout
  80. pub cumulative_payout_earned: Balance,
  81. }
  82. impl<MemberId: Ord, CuratorGroupId, AccountId, Balance>
  83. ChannelRecord<MemberId, CuratorGroupId, AccountId, Balance>
  84. {
  85. /// Ensure censorship status have been changed
  86. pub fn ensure_censorship_status_changed<T: Trait>(&self, is_censored: bool) -> DispatchResult {
  87. ensure!(
  88. self.is_censored != is_censored,
  89. Error::<T>::ChannelCensorshipStatusDidNotChange
  90. );
  91. Ok(())
  92. }
  93. }
  94. // Channel alias type for simplification.
  95. pub type Channel<T> = ChannelRecord<
  96. <T as common::MembershipTypes>::MemberId,
  97. <T as ContentActorAuthenticator>::CuratorGroupId,
  98. <T as frame_system::Trait>::AccountId,
  99. BalanceOf<T>,
  100. >;
  101. /// A request to buy a channel by a new ChannelOwner.
  102. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  103. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  104. pub struct ChannelOwnershipTransferRequestRecord<
  105. ChannelId,
  106. MemberId,
  107. CuratorGroupId,
  108. Balance,
  109. AccountId,
  110. > {
  111. pub channel_id: ChannelId,
  112. pub new_owner: ChannelOwner<MemberId, CuratorGroupId>,
  113. pub payment: Balance,
  114. pub new_reward_account: Option<AccountId>,
  115. }
  116. // ChannelOwnershipTransferRequest type alias for simplification.
  117. pub type ChannelOwnershipTransferRequest<T> = ChannelOwnershipTransferRequestRecord<
  118. <T as storage::Trait>::ChannelId,
  119. <T as common::MembershipTypes>::MemberId,
  120. <T as ContentActorAuthenticator>::CuratorGroupId,
  121. BalanceOf<T>,
  122. <T as frame_system::Trait>::AccountId,
  123. >;
  124. /// Information about channel being created.
  125. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  126. #[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
  127. pub struct ChannelCreationParametersRecord<StorageAssets, AccountId, MemberId: Ord> {
  128. /// Assets referenced by metadata
  129. pub assets: Option<StorageAssets>,
  130. /// Metadata about the channel.
  131. pub meta: Option<Vec<u8>>,
  132. /// optional reward account
  133. pub reward_account: Option<AccountId>,
  134. /// initial collaborator set
  135. pub collaborators: BTreeSet<MemberId>,
  136. /// initial moderator set
  137. pub moderators: BTreeSet<MemberId>,
  138. }
  139. pub type ChannelCreationParameters<T> = ChannelCreationParametersRecord<
  140. StorageAssets<T>,
  141. <T as frame_system::Trait>::AccountId,
  142. <T as common::MembershipTypes>::MemberId,
  143. >;
  144. /// Information about channel being updated.
  145. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  146. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  147. pub struct ChannelUpdateParametersRecord<StorageAssets, AccountId, DataObjectId: Ord, MemberId: Ord>
  148. {
  149. /// Asset collection for the channel, referenced by metadata
  150. pub assets_to_upload: Option<StorageAssets>,
  151. /// If set, metadata update for the channel.
  152. pub new_meta: Option<Vec<u8>>,
  153. /// If set, updates the reward account of the channel
  154. pub reward_account: Option<Option<AccountId>>,
  155. /// assets to be removed from channel
  156. pub assets_to_remove: BTreeSet<DataObjectId>,
  157. /// collaborator set
  158. pub collaborators: Option<BTreeSet<MemberId>>,
  159. }
  160. pub type ChannelUpdateParameters<T> = ChannelUpdateParametersRecord<
  161. StorageAssets<T>,
  162. <T as frame_system::Trait>::AccountId,
  163. DataObjectId<T>,
  164. <T as common::MembershipTypes>::MemberId,
  165. >;
  166. /// A category that videos can belong to.
  167. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  168. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  169. pub struct VideoCategory {
  170. // No runtime information is currently stored for a Category.
  171. }
  172. /// Information about the video category being created.
  173. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  174. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  175. pub struct VideoCategoryCreationParameters {
  176. /// Metadata about the video category.
  177. meta: Vec<u8>,
  178. }
  179. /// Information about the video category being updated.
  180. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  181. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  182. pub struct VideoCategoryUpdateParameters {
  183. // Because it is the only field it is not an Option
  184. /// Metadata update for the video category.
  185. new_meta: Vec<u8>,
  186. }
  187. /// Information regarding the content being uploaded
  188. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  189. #[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
  190. pub struct StorageAssetsRecord<Balance> {
  191. /// Data object parameters.
  192. pub object_creation_list: Vec<DataObjectCreationParameters>,
  193. /// Expected data size fee value for this extrinsic call.
  194. pub expected_data_size_fee: Balance,
  195. }
  196. pub type StorageAssets<T> = StorageAssetsRecord<BalanceOf<T>>;
  197. /// Information about the video being created.
  198. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  199. #[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
  200. pub struct VideoCreationParametersRecord<StorageAssets> {
  201. /// Asset collection for the video
  202. pub assets: Option<StorageAssets>,
  203. /// Metadata for the video.
  204. pub meta: Option<Vec<u8>>,
  205. /// Comments enabled or not
  206. pub enable_comments: bool,
  207. }
  208. pub type VideoCreationParameters<T> = VideoCreationParametersRecord<StorageAssets<T>>;
  209. /// Information about the video being updated
  210. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  211. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  212. pub struct VideoUpdateParametersRecord<StorageAssets, DataObjectId: Ord> {
  213. /// Assets referenced by metadata
  214. pub assets_to_upload: Option<StorageAssets>,
  215. /// If set, metadata update for the video.
  216. pub new_meta: Option<Vec<u8>>,
  217. /// video assets to be removed from channel
  218. pub assets_to_remove: BTreeSet<DataObjectId>,
  219. /// If set enable/disable comments to video
  220. pub enable_comments: Option<bool>,
  221. }
  222. pub type VideoUpdateParameters<T> = VideoUpdateParametersRecord<StorageAssets<T>, DataObjectId<T>>;
  223. /// A video which belongs to a channel. A video may be part of a series or playlist.
  224. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  225. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  226. pub struct VideoRecord<ChannelId, SeriesId, VideoPostId, OwnedNFT> {
  227. pub in_channel: ChannelId,
  228. pub in_series: Option<SeriesId>,
  229. /// Whether the curators have censored the video or not.
  230. pub is_censored: bool,
  231. /// enable or not comments
  232. pub enable_comments: bool,
  233. /// First post to a video works as a description
  234. pub video_post_id: Option<VideoPostId>,
  235. /// Whether nft for this video have been issued.
  236. pub nft_status: Option<OwnedNFT>,
  237. }
  238. pub type Video<T> = VideoRecord<
  239. <T as storage::Trait>::ChannelId,
  240. <T as Trait>::SeriesId,
  241. <T as Trait>::VideoPostId,
  242. Nft<T>,
  243. >;
  244. /// Information about the plyalist being created.
  245. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  246. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  247. pub struct PlaylistCreationParameters {
  248. /// Metadata about the playlist.
  249. meta: Vec<u8>,
  250. }
  251. /// Information about the playlist being updated.
  252. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  253. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  254. pub struct PlaylistUpdateParameters {
  255. // It is the only field so its not an Option
  256. /// Metadata update for the playlist.
  257. new_meta: Vec<u8>,
  258. }
  259. /// A playlist is an ordered collection of videos.
  260. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  261. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  262. pub struct Playlist<ChannelId> {
  263. /// The channel the playlist belongs to.
  264. in_channel: ChannelId,
  265. }
  266. /// Information about the episode being created or updated.
  267. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  268. #[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
  269. pub enum EpisodeParameters<VideoId, StorageAssets> {
  270. /// A new video is being added as the episode.
  271. NewVideo(VideoCreationParametersRecord<StorageAssets>),
  272. /// An existing video is being made into an episode.
  273. ExistingVideo(VideoId),
  274. }
  275. /// Information about the season being created or updated.
  276. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  277. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  278. pub struct SeasonParameters<VideoId, StorageAssets> {
  279. /// Season assets referenced by metadata
  280. assets: Option<StorageAssets>,
  281. // ?? It might just be more straighforward to always provide full list of episodes at cost of larger tx.
  282. /// If set, updates the episodes of a season. Extends the number of episodes in a season
  283. /// when length of new_episodes is greater than previously set. Last elements must all be
  284. /// 'Some' in that case.
  285. /// Will truncate existing season when length of new_episodes is less than previously set.
  286. episodes: Option<Vec<Option<EpisodeParameters<VideoId, StorageAssets>>>>,
  287. meta: Option<Vec<u8>>,
  288. }
  289. /// Information about the series being created or updated.
  290. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  291. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  292. pub struct SeriesParameters<VideoId, StorageAssets> {
  293. /// Series assets referenced by metadata
  294. assets: Option<StorageAssets>,
  295. // ?? It might just be more straighforward to always provide full list of seasons at cost of larger tx.
  296. /// If set, updates the seasons of a series. Extend a series when length of seasons is
  297. /// greater than previoulsy set. Last elements must all be 'Some' in that case.
  298. /// Will truncate existing series when length of seasons is less than previously set.
  299. seasons: Option<Vec<Option<SeasonParameters<VideoId, StorageAssets>>>>,
  300. meta: Option<Vec<u8>>,
  301. }
  302. /// A season is an ordered list of videos (episodes).
  303. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  304. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  305. pub struct Season<VideoId> {
  306. episodes: Vec<VideoId>,
  307. }
  308. /// A series is an ordered list of seasons that belongs to a channel.
  309. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  310. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  311. pub struct Series<ChannelId, VideoId> {
  312. in_channel: ChannelId,
  313. seasons: Vec<Season<VideoId>>,
  314. }
  315. /// The actor the caller/origin is trying to act as for Person creation and update and delete calls.
  316. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  317. #[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
  318. pub enum PersonActor<MemberId, CuratorId> {
  319. Member(MemberId),
  320. Curator(CuratorId),
  321. }
  322. /// The authorized actor that may update or delete a Person.
  323. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  324. #[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
  325. pub enum PersonController<MemberId> {
  326. /// Member controls the person
  327. Member(MemberId),
  328. /// Any curator controls the person
  329. Curators,
  330. }
  331. /// Default trait implemented only because its used in Person which needs to implement a Default trait
  332. /// since it is a StorageValue.
  333. impl<MemberId: Default> Default for PersonController<MemberId> {
  334. fn default() -> Self {
  335. PersonController::Member(MemberId::default())
  336. }
  337. }
  338. /// Information for Person being created.
  339. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  340. #[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
  341. pub struct PersonCreationParameters<StorageAssets> {
  342. /// Assets referenced by metadata
  343. assets: StorageAssets,
  344. /// Metadata for person.
  345. meta: Vec<u8>,
  346. }
  347. /// Information for Persion being updated.
  348. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  349. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  350. pub struct PersonUpdateParameters<StorageAssets> {
  351. /// Assets referenced by metadata
  352. assets: Option<StorageAssets>,
  353. /// Metadata to update person.
  354. new_meta: Option<Vec<u8>>,
  355. }
  356. /// A Person represents a real person that may be associated with a video.
  357. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  358. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  359. pub struct Person<MemberId> {
  360. /// Who can update or delete this person.
  361. controlled_by: PersonController<MemberId>,
  362. }
  363. pub type DataObjectId<T> = <T as storage::Trait>::DataObjectId;
  364. /// A VideoPost associated to a video
  365. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  366. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  367. pub struct VideoPostRecord<ContentActor, Balance, VideoPostId, VideoPostType, VideoId> {
  368. /// Author of post.
  369. pub author: ContentActor,
  370. /// Cleanup pay off
  371. pub bloat_bond: Balance,
  372. /// Overall replies counter
  373. pub replies_count: VideoPostId,
  374. /// video associated to the post (instead of the body hash as in the blog module)
  375. pub post_type: VideoPostType,
  376. /// video reference
  377. pub video_reference: VideoId,
  378. }
  379. /// alias for VideoPost
  380. pub type VideoPost<T> = VideoPostRecord<
  381. ContentActor<
  382. <T as ContentActorAuthenticator>::CuratorGroupId,
  383. <T as ContentActorAuthenticator>::CuratorId,
  384. <T as MembershipTypes>::MemberId,
  385. >,
  386. BalanceOf<T>,
  387. <T as Trait>::VideoPostId,
  388. VideoPostType<T>,
  389. <T as Trait>::VideoId,
  390. >;
  391. /// VideoPost type structured as linked list with the video post as beginning
  392. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  393. #[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
  394. pub enum VideoPostTypeRecord<ParentVideoPostId> {
  395. /// Equivalent to a video description
  396. Description,
  397. /// Comment to a post with specified id
  398. Comment(ParentVideoPostId),
  399. }
  400. impl<ParentVideoPostId> Default for VideoPostTypeRecord<ParentVideoPostId> {
  401. fn default() -> Self {
  402. VideoPostTypeRecord::<ParentVideoPostId>::Description
  403. }
  404. }
  405. pub type VideoPostType<T> = VideoPostTypeRecord<<T as Trait>::VideoPostId>;
  406. /// Side used to construct hash values during merkle proof verification
  407. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  408. #[derive(Encode, Decode, Clone, Copy, PartialEq, Eq, Debug)]
  409. pub enum Side {
  410. Left,
  411. Right,
  412. }
  413. impl Default for Side {
  414. fn default() -> Self {
  415. Side::Right
  416. }
  417. }
  418. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  419. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  420. /// Element used in for channel payout
  421. pub struct ProofElementRecord<Hash, Side> {
  422. // Node hash
  423. pub hash: Hash,
  424. // side in which *self* must be adjoined during proof verification
  425. pub side: Side,
  426. }
  427. // alias for the proof element
  428. pub type ProofElement<T> = ProofElementRecord<<T as frame_system::Trait>::Hash, Side>;
  429. /// An enum in order to differenciate between post author and moderator / owner
  430. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  431. #[derive(Encode, Decode, Clone, PartialEq, Eq, Debug)]
  432. pub enum CleanupActor {
  433. ChannelOwner,
  434. Moderator,
  435. VideoPostAuthor,
  436. }
  437. impl Default for CleanupActor {
  438. fn default() -> Self {
  439. CleanupActor::ChannelOwner
  440. }
  441. }
  442. /// Information on the post being created
  443. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  444. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  445. pub struct VideoPostCreationParametersRecord<VideoPostType, VideoId> {
  446. /// content
  447. pub post_type: VideoPostType,
  448. /// video reference
  449. pub video_reference: VideoId,
  450. }
  451. pub type VideoPostCreationParameters<T> =
  452. VideoPostCreationParametersRecord<VideoPostType<T>, <T as Trait>::VideoId>;
  453. /// Information on the post being deleted
  454. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  455. #[derive(Encode, Decode, Default, Clone, PartialEq, Eq, Debug)]
  456. pub struct VideoPostDeletionParametersRecord<HashOutput> {
  457. /// optional witnesses in case of video post deletion
  458. pub witness: Option<HashOutput>,
  459. /// rationale in case actor is moderator
  460. pub rationale: Option<Vec<u8>>,
  461. }
  462. pub type VideoPostDeletionParameters<T> =
  463. VideoPostDeletionParametersRecord<<T as frame_system::Trait>::Hash>;
  464. /// Payment claim by a channel
  465. #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
  466. #[derive(Encode, Decode, Default, Copy, Clone, PartialEq, Eq, Debug)]
  467. pub struct PullPaymentElement<ChannelId, Balance, Hash> {
  468. pub channel_id: ChannelId,
  469. pub cumulative_payout_claimed: Balance,
  470. pub reason: Hash,
  471. }
  472. pub type PullPayment<T> = PullPaymentElement<
  473. <T as storage::Trait>::ChannelId,
  474. BalanceOf<T>,
  475. <T as frame_system::Trait>::Hash,
  476. >;
  477. impl<ChannelId: Clone, SeriesId: Clone, VideoPostId: Clone, OwnedNFT>
  478. VideoRecord<ChannelId, SeriesId, VideoPostId, OwnedNFT>
  479. {
  480. /// Ensure nft is not issued
  481. pub fn ensure_nft_is_not_issued<T: Trait>(&self) -> DispatchResult {
  482. ensure!(self.nft_status.is_none(), Error::<T>::NFTAlreadyExists);
  483. Ok(())
  484. }
  485. /// Ensure nft is issued
  486. pub fn ensure_nft_is_issued<T: Trait>(&self) -> Result<OwnedNFT, Error<T>> {
  487. if let Some(owned_nft) = &self.nft_status {
  488. Ok(owned_nft.to_owned())
  489. } else {
  490. Err(Error::<T>::NFTDoesNotExist)
  491. }
  492. }
  493. /// Set video nft status
  494. pub fn set_nft_status(mut self, nft: OwnedNFT) -> Self {
  495. self.nft_status = Some(nft);
  496. self
  497. }
  498. /// Ensure censorship status have been changed
  499. pub fn ensure_censorship_status_changed<T: Trait>(&self, is_censored: bool) -> DispatchResult {
  500. ensure!(
  501. self.is_censored != is_censored,
  502. Error::<T>::VideoCensorshipStatusDidNotChange
  503. );
  504. Ok(())
  505. }
  506. }
  507. pub type Balances<T> = balances::Module<T>;
  508. pub type BalanceOf<T> = <Balances<T> as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
  509. pub type CurrencyOf<T> = Currency<<T as frame_system::Trait>::AccountId>::Balance;
  510. pub type Storage<T> = storage::Module<T>;
  511. /// Type, used in diffrent numeric constraints representations
  512. pub type MaxNumber = u32;
  513. /// A numeric identifier trait
  514. pub trait NumericIdentifier:
  515. Parameter
  516. + Member
  517. + BaseArithmetic
  518. + Codec
  519. + Default
  520. + Copy
  521. + Clone
  522. + MaybeSerializeDeserialize
  523. + Eq
  524. + PartialEq
  525. + Ord
  526. + Zero
  527. + From<u64>
  528. + Into<u64>
  529. {
  530. }
  531. impl NumericIdentifier for u64 {}
  532. /// Operations with local pallet account.
  533. pub trait ModuleAccount<T: balances::Trait> {
  534. /// The module id, used for deriving its sovereign account ID.
  535. type ModuleId: Get<ModuleId>;
  536. /// The account ID of the module account.
  537. fn module_account_id() -> T::AccountId {
  538. Self::ModuleId::get().into_sub_account(Vec::<u8>::new())
  539. }
  540. /// Transfer tokens from the module account to the destination account (spends from
  541. /// module account).
  542. fn withdraw(dest_account_id: &T::AccountId, amount: BalanceOf<T>) -> DispatchResult {
  543. <Balances<T> as Currency<T::AccountId>>::transfer(
  544. &Self::module_account_id(),
  545. dest_account_id,
  546. amount,
  547. ExistenceRequirement::AllowDeath,
  548. )
  549. }
  550. /// Transfer tokens from the destination account to the module account (fills module account).
  551. fn deposit(src_account_id: &T::AccountId, amount: BalanceOf<T>) -> DispatchResult {
  552. <Balances<T> as Currency<T::AccountId>>::transfer(
  553. src_account_id,
  554. &Self::module_account_id(),
  555. amount,
  556. ExistenceRequirement::AllowDeath,
  557. )
  558. }
  559. /// Displays usable balance for the module account.
  560. fn usable_balance() -> BalanceOf<T> {
  561. <Balances<T>>::usable_balance(&Self::module_account_id())
  562. }
  563. /// Mints the reward into the destination account provided
  564. fn transfer_reward(dest_account_id: &T::AccountId, amount: BalanceOf<T>) {
  565. let _ = <Balances<T> as Currency<T::AccountId>>::deposit_creating(dest_account_id, amount);
  566. }
  567. }
  568. /// Implementation of the ModuleAccountHandler.
  569. pub struct ModuleAccountHandler<T: balances::Trait, ModId: Get<ModuleId>> {
  570. /// Phantom marker for the trait.
  571. trait_marker: PhantomData<T>,
  572. /// Phantom marker for the module id type.
  573. module_id_marker: PhantomData<ModId>,
  574. }
  575. impl<T: balances::Trait, ModId: Get<ModuleId>> ModuleAccount<T> for ModuleAccountHandler<T, ModId> {
  576. type ModuleId = ModId;
  577. }
  578. /// Local module account handler.
  579. pub type ContentTreasury<T> = ModuleAccountHandler<T, <T as Trait>::ModuleId>;