|
@@ -104,12 +104,6 @@ pub trait Trait:
|
|
|
|
|
|
/// Refund cap during cleanup
|
|
|
type BloatBondCap: Get<u32>;
|
|
|
-
|
|
|
- /// Video migrated in each block during migration
|
|
|
- type VideosMigrationsEachBlock: Get<u64>;
|
|
|
-
|
|
|
- /// Channel migrated in each block during migration
|
|
|
- type ChannelsMigrationsEachBlock: Get<u64>;
|
|
|
}
|
|
|
|
|
|
decl_storage! {
|
|
@@ -142,10 +136,6 @@ decl_storage! {
|
|
|
|
|
|
pub NextVideoPostId get(fn next_video_post_id) config(): T::VideoPostId;
|
|
|
|
|
|
- pub ChannelMigration get(fn channel_migration) config(): ChannelMigrationConfig<T>;
|
|
|
-
|
|
|
- pub VideoMigration get(fn video_migration) config(): VideoMigrationConfig<T>;
|
|
|
-
|
|
|
pub Commitment get(fn commitment): <T as frame_system::Trait>::Hash;
|
|
|
|
|
|
pub MaxRewardAllowed get(fn max_reward_allowed) config(): BalanceOf<T>;
|
|
@@ -346,9 +336,6 @@ decl_module! {
|
|
|
actor: ContentActor<T::CuratorGroupId, T::CuratorId, T::MemberId>,
|
|
|
params: ChannelCreationParameters<T>,
|
|
|
) {
|
|
|
- // ensure migration is done
|
|
|
- ensure!(Self::is_migration_done(), Error::<T>::MigrationNotFinished);
|
|
|
-
|
|
|
// channel creator account
|
|
|
let sender = ensure_signed(origin)?;
|
|
|
|
|
@@ -451,7 +438,7 @@ decl_module! {
|
|
|
let sender = ensure_signed(origin)?;
|
|
|
|
|
|
// check that channel exists
|
|
|
- let mut channel = Self::ensure_channel_validity(&channel_id)?;
|
|
|
+ let mut channel = Self::ensure_channel_exists(&channel_id)?;
|
|
|
|
|
|
ensure_actor_authorized_to_update_channel_assets::<T>(
|
|
|
&sender,
|
|
@@ -530,7 +517,7 @@ decl_module! {
|
|
|
let sender = ensure_signed(origin)?;
|
|
|
|
|
|
// check that channel exists
|
|
|
- let channel = Self::ensure_channel_validity(&channel_id)?;
|
|
|
+ let channel = Self::ensure_channel_exists(&channel_id)?;
|
|
|
|
|
|
ensure_actor_authorized_to_delete_channel::<T>(
|
|
|
&sender,
|
|
@@ -609,7 +596,7 @@ decl_module! {
|
|
|
rationale: Vec<u8>,
|
|
|
) {
|
|
|
// check that channel exists
|
|
|
- let channel = Self::ensure_channel_validity(&channel_id)?;
|
|
|
+ let channel = Self::ensure_channel_exists(&channel_id)?;
|
|
|
|
|
|
ensure_actor_authorized_to_censor::<T>(
|
|
|
origin,
|
|
@@ -700,7 +687,7 @@ decl_module! {
|
|
|
let sender = ensure_signed(origin)?;
|
|
|
|
|
|
// check that channel exists
|
|
|
- let channel = Self::ensure_channel_validity(&channel_id)?;
|
|
|
+ let channel = Self::ensure_channel_exists(&channel_id)?;
|
|
|
|
|
|
ensure_actor_authorized_to_update_channel_assets::<T>(
|
|
|
&sender,
|
|
@@ -768,7 +755,7 @@ decl_module! {
|
|
|
) {
|
|
|
let sender = ensure_signed(origin)?;
|
|
|
// check that video exists, retrieve corresponding channel id.
|
|
|
- let video = Self::ensure_video_validity(&video_id)?;
|
|
|
+ let video = Self::ensure_video_exists(&video_id)?;
|
|
|
|
|
|
let channel_id = video.in_channel;
|
|
|
let channel = ChannelById::<T>::get(&channel_id);
|
|
@@ -830,7 +817,7 @@ decl_module! {
|
|
|
let sender = ensure_signed(origin)?;
|
|
|
|
|
|
// check that video exists
|
|
|
- let video = Self::ensure_video_validity(&video_id)?;
|
|
|
+ let video = Self::ensure_video_exists(&video_id)?;
|
|
|
|
|
|
// get information regarding channel
|
|
|
let channel_id = video.in_channel;
|
|
@@ -970,7 +957,7 @@ decl_module! {
|
|
|
rationale: Vec<u8>,
|
|
|
) -> DispatchResult {
|
|
|
// check that video exists
|
|
|
- let video = Self::ensure_video_validity(&video_id)?;
|
|
|
+ let video = Self::ensure_video_exists(&video_id)?;
|
|
|
|
|
|
ensure_actor_authorized_to_censor::<T>(
|
|
|
origin,
|
|
@@ -1012,7 +999,7 @@ decl_module! {
|
|
|
let sender = ensure_signed(origin)?;
|
|
|
|
|
|
// ensure channel is valid
|
|
|
- let video = Self::ensure_video_validity(¶ms.video_reference)?;
|
|
|
+ let video = Self::ensure_video_exists(¶ms.video_reference)?;
|
|
|
let owner = ChannelById::<T>::get(video.in_channel).owner;
|
|
|
|
|
|
match params.post_type {
|
|
@@ -1220,7 +1207,7 @@ decl_module! {
|
|
|
) {
|
|
|
// ensure (origin, actor) is channel owner
|
|
|
let sender = ensure_signed(origin)?;
|
|
|
- let owner = Self::ensure_channel_validity(&channel_id)?.owner;
|
|
|
+ let owner = Self::ensure_channel_exists(&channel_id)?.owner;
|
|
|
|
|
|
ensure_actor_can_manage_moderators::<T>(
|
|
|
&sender,
|
|
@@ -1243,12 +1230,6 @@ decl_module! {
|
|
|
));
|
|
|
}
|
|
|
|
|
|
- fn on_initialize(_n: T::BlockNumber) -> frame_support::weights::Weight {
|
|
|
- Self::perform_video_migration();
|
|
|
- Self::perform_channel_migration();
|
|
|
- 10_000_000 // TODO: adjust Weight
|
|
|
- }
|
|
|
-
|
|
|
#[weight = 10_000_000] // TODO: adjust Weight
|
|
|
pub fn update_commitment(
|
|
|
origin,
|
|
@@ -1268,7 +1249,7 @@ decl_module! {
|
|
|
proof: Vec<ProofElement<T>>,
|
|
|
item: PullPayment<T>,
|
|
|
) -> DispatchResult {
|
|
|
- let channel = Self::ensure_channel_validity(&item.channel_id)?;
|
|
|
+ let channel = Self::ensure_channel_exists(&item.channel_id)?;
|
|
|
|
|
|
ensure!(channel.reward_account.is_some(), Error::<T>::RewardAccountIsNotSet);
|
|
|
ensure_actor_authorized_to_claim_payment::<T>(origin, &actor, &channel.owner)?;
|
|
@@ -1323,7 +1304,7 @@ decl_module! {
|
|
|
let sender = ensure_signed(origin)?;
|
|
|
|
|
|
// Ensure given video exists
|
|
|
- let video = Self::ensure_video_validity(&video_id)?;
|
|
|
+ let video = Self::ensure_video_exists(&video_id)?;
|
|
|
|
|
|
// Ensure have not been issued yet
|
|
|
video.ensure_nft_is_not_issued::<T>()?;
|
|
@@ -1331,7 +1312,7 @@ decl_module! {
|
|
|
let channel_id = video.in_channel;
|
|
|
|
|
|
// Ensure channel exists, retrieve channel owner
|
|
|
- let channel = Self::ensure_channel_validity(&channel_id)?;
|
|
|
+ let channel = Self::ensure_channel_exists(&channel_id)?;
|
|
|
|
|
|
ensure_actor_authorized_to_update_channel_assets::<T>(&sender, &actor, &channel)?;
|
|
|
|
|
@@ -1364,7 +1345,7 @@ decl_module! {
|
|
|
auction_params: AuctionParams<T::BlockNumber, CurrencyOf<T>, T::MemberId>,
|
|
|
) {
|
|
|
// Ensure given video exists
|
|
|
- let video = Self::ensure_video_validity(&video_id)?;
|
|
|
+ let video = Self::ensure_video_exists(&video_id)?;
|
|
|
|
|
|
// Ensure nft is already issued
|
|
|
let nft = video.ensure_nft_is_issued::<T>()?;
|
|
@@ -1408,7 +1389,7 @@ decl_module! {
|
|
|
video_id: T::VideoId,
|
|
|
) {
|
|
|
// Ensure given video exists
|
|
|
- let video = Self::ensure_video_validity(&video_id)?;
|
|
|
+ let video = Self::ensure_video_exists(&video_id)?;
|
|
|
|
|
|
// Ensure nft is already issued
|
|
|
let nft = video.ensure_nft_is_issued::<T>()?;
|
|
@@ -1444,7 +1425,7 @@ decl_module! {
|
|
|
video_id: T::VideoId,
|
|
|
) {
|
|
|
// Ensure given video exists
|
|
|
- let video = Self::ensure_video_validity(&video_id)?;
|
|
|
+ let video = Self::ensure_video_exists(&video_id)?;
|
|
|
|
|
|
// Ensure nft is already issued
|
|
|
let nft = video.ensure_nft_is_issued::<T>()?;
|
|
@@ -1477,7 +1458,7 @@ decl_module! {
|
|
|
video_id: T::VideoId,
|
|
|
) {
|
|
|
// Ensure given video exists
|
|
|
- let video = Self::ensure_video_validity(&video_id)?;
|
|
|
+ let video = Self::ensure_video_exists(&video_id)?;
|
|
|
|
|
|
// Ensure nft is already issued
|
|
|
let nft = video.ensure_nft_is_issued::<T>()?;
|
|
@@ -1519,7 +1500,7 @@ decl_module! {
|
|
|
Self::ensure_has_sufficient_balance(&participant_account_id, bid)?;
|
|
|
|
|
|
// Ensure given video exists
|
|
|
- let video = Self::ensure_video_validity(&video_id)?;
|
|
|
+ let video = Self::ensure_video_exists(&video_id)?;
|
|
|
|
|
|
// Ensure nft is already issued
|
|
|
let nft = video.ensure_nft_is_issued::<T>()?;
|
|
@@ -1599,7 +1580,7 @@ decl_module! {
|
|
|
ensure_member_auth_success::<T>(&participant_account_id, &participant_id)?;
|
|
|
|
|
|
// Ensure given video exists
|
|
|
- let video = Self::ensure_video_validity(&video_id)?;
|
|
|
+ let video = Self::ensure_video_exists(&video_id)?;
|
|
|
|
|
|
// Ensure nft is already issued
|
|
|
let nft = video.ensure_nft_is_issued::<T>()?;
|
|
@@ -1640,7 +1621,7 @@ decl_module! {
|
|
|
ensure_member_auth_success::<T>(&account_id, &member_id)?;
|
|
|
|
|
|
// Ensure given video exists
|
|
|
- let video = Self::ensure_video_validity(&video_id)?;
|
|
|
+ let video = Self::ensure_video_exists(&video_id)?;
|
|
|
|
|
|
// Ensure nft is already issued
|
|
|
let nft = video.ensure_nft_is_issued::<T>()?;
|
|
@@ -1683,7 +1664,7 @@ decl_module! {
|
|
|
) {
|
|
|
|
|
|
// Ensure given video exists
|
|
|
- let video = Self::ensure_video_validity(&video_id)?;
|
|
|
+ let video = Self::ensure_video_exists(&video_id)?;
|
|
|
|
|
|
// Ensure nft is already issued
|
|
|
let nft = video.ensure_nft_is_issued::<T>()?;
|
|
@@ -1727,7 +1708,7 @@ decl_module! {
|
|
|
) {
|
|
|
|
|
|
// Ensure given video exists
|
|
|
- let video = Self::ensure_video_validity(&video_id)?;
|
|
|
+ let video = Self::ensure_video_exists(&video_id)?;
|
|
|
|
|
|
// Ensure nft is already issued
|
|
|
let nft = video.ensure_nft_is_issued::<T>()?;
|
|
@@ -1761,7 +1742,7 @@ decl_module! {
|
|
|
) {
|
|
|
|
|
|
// Ensure given video exists
|
|
|
- let video = Self::ensure_video_validity(&video_id)?;
|
|
|
+ let video = Self::ensure_video_exists(&video_id)?;
|
|
|
|
|
|
// Ensure nft is already issued
|
|
|
let nft = video.ensure_nft_is_issued::<T>()?;
|
|
@@ -1795,7 +1776,7 @@ decl_module! {
|
|
|
let receiver_account_id = ensure_signed(origin)?;
|
|
|
|
|
|
// Ensure given video exists
|
|
|
- let video = Self::ensure_video_validity(&video_id)?;
|
|
|
+ let video = Self::ensure_video_exists(&video_id)?;
|
|
|
|
|
|
// Ensure nft is already issued
|
|
|
let nft = video.ensure_nft_is_issued::<T>()?;
|
|
@@ -1829,7 +1810,7 @@ decl_module! {
|
|
|
) {
|
|
|
|
|
|
// Ensure given video exists
|
|
|
- let video = Self::ensure_video_validity(&video_id)?;
|
|
|
+ let video = Self::ensure_video_exists(&video_id)?;
|
|
|
|
|
|
// Ensure nft is already issued
|
|
|
let nft = video.ensure_nft_is_issued::<T>()?;
|
|
@@ -1867,7 +1848,7 @@ decl_module! {
|
|
|
ensure_member_auth_success::<T>(&participant_account_id, &participant_id)?;
|
|
|
|
|
|
// Ensure given video exists
|
|
|
- let video = Self::ensure_video_validity(&video_id)?;
|
|
|
+ let video = Self::ensure_video_exists(&video_id)?;
|
|
|
|
|
|
// Ensure nft is already issued
|
|
|
let nft = video.ensure_nft_is_issued::<T>()?;
|
|
@@ -1894,83 +1875,6 @@ decl_module! {
|
|
|
}
|
|
|
|
|
|
impl<T: Trait> Module<T> {
|
|
|
- /// Migrate Videos
|
|
|
- fn perform_video_migration() {
|
|
|
- let MigrationConfigRecord {
|
|
|
- current_id,
|
|
|
- final_id,
|
|
|
- } = <VideoMigration<T>>::get();
|
|
|
-
|
|
|
- if current_id < final_id {
|
|
|
- // perform migration procedure
|
|
|
- let next_id = sp_std::cmp::min(
|
|
|
- current_id + T::VideosMigrationsEachBlock::get().into(),
|
|
|
- final_id,
|
|
|
- );
|
|
|
-
|
|
|
- //
|
|
|
- // == MUTATION SAFE ==
|
|
|
- //
|
|
|
-
|
|
|
- // clear maps: (iterator are lazy and do nothing unless consumed)
|
|
|
- for id in current_id.into()..next_id.into() {
|
|
|
- <VideoById<T>>::remove(T::VideoId::from(id));
|
|
|
- }
|
|
|
-
|
|
|
- // edit the current id
|
|
|
- <VideoMigration<T>>::mutate(|value| value.current_id = next_id);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// Migrate Channels
|
|
|
- fn perform_channel_migration() {
|
|
|
- let MigrationConfigRecord {
|
|
|
- current_id,
|
|
|
- final_id,
|
|
|
- } = <ChannelMigration<T>>::get();
|
|
|
-
|
|
|
- if current_id < final_id {
|
|
|
- // perform migration procedure
|
|
|
- let next_id = sp_std::cmp::min(
|
|
|
- current_id + T::ChannelsMigrationsEachBlock::get().into(),
|
|
|
- final_id,
|
|
|
- );
|
|
|
-
|
|
|
- //
|
|
|
- // == MUTATION SAFE ==
|
|
|
- //
|
|
|
-
|
|
|
- // clear maps: (iterator are lazy and do nothing unless consumed)
|
|
|
- for id in current_id.into()..next_id.into() {
|
|
|
- <ChannelById<T>>::remove(T::ChannelId::from(id));
|
|
|
- }
|
|
|
-
|
|
|
- // edit the current id
|
|
|
- <ChannelMigration<T>>::mutate(|value| value.current_id = next_id);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// Ensure Channel Migration Finished
|
|
|
-
|
|
|
- /// Ensure Video Migration Finished
|
|
|
- fn is_migration_done() -> bool {
|
|
|
- let MigrationConfigRecord {
|
|
|
- current_id,
|
|
|
- final_id,
|
|
|
- } = <VideoMigration<T>>::get();
|
|
|
-
|
|
|
- let video_migration_done = current_id == final_id;
|
|
|
-
|
|
|
- let MigrationConfigRecord {
|
|
|
- current_id,
|
|
|
- final_id,
|
|
|
- } = <ChannelMigration<T>>::get();
|
|
|
-
|
|
|
- let channel_migration_done = current_id == final_id;
|
|
|
-
|
|
|
- video_migration_done && channel_migration_done
|
|
|
- }
|
|
|
-
|
|
|
/// Ensure `CuratorGroup` under given id exists
|
|
|
fn ensure_curator_group_under_given_id_exists(
|
|
|
curator_group_id: &T::CuratorGroupId,
|
|
@@ -1990,30 +1894,6 @@ impl<T: Trait> Module<T> {
|
|
|
Ok(Self::curator_group_by_id(curator_group_id))
|
|
|
}
|
|
|
|
|
|
- fn ensure_channel_validity(channel_id: &T::ChannelId) -> Result<Channel<T>, Error<T>> {
|
|
|
- // ensure migration is done
|
|
|
- ensure!(Self::is_migration_done(), Error::<T>::MigrationNotFinished,);
|
|
|
-
|
|
|
- // ensure channel exists
|
|
|
- ensure!(
|
|
|
- ChannelById::<T>::contains_key(channel_id),
|
|
|
- Error::<T>::ChannelDoesNotExist
|
|
|
- );
|
|
|
- Ok(ChannelById::<T>::get(channel_id))
|
|
|
- }
|
|
|
-
|
|
|
- fn ensure_video_validity(video_id: &T::VideoId) -> Result<Video<T>, Error<T>> {
|
|
|
- // ensure migration is done
|
|
|
- ensure!(Self::is_migration_done(), Error::<T>::MigrationNotFinished,);
|
|
|
-
|
|
|
- // ensure video exists
|
|
|
- ensure!(
|
|
|
- VideoById::<T>::contains_key(video_id),
|
|
|
- Error::<T>::VideoDoesNotExist
|
|
|
- );
|
|
|
- Ok(VideoById::<T>::get(video_id))
|
|
|
- }
|
|
|
-
|
|
|
fn ensure_channel_category_exists(
|
|
|
channel_category_id: &T::ChannelCategoryId,
|
|
|
) -> Result<ChannelCategory, Error<T>> {
|
|
@@ -2034,6 +1914,22 @@ impl<T: Trait> Module<T> {
|
|
|
Ok(VideoCategoryById::<T>::get(video_category_id))
|
|
|
}
|
|
|
|
|
|
+ fn ensure_video_exists(video_id: &T::VideoId) -> Result<Video<T>, Error<T>> {
|
|
|
+ ensure!(
|
|
|
+ VideoById::<T>::contains_key(video_id),
|
|
|
+ Error::<T>::VideoDoesNotExist
|
|
|
+ );
|
|
|
+ Ok(VideoById::<T>::get(video_id))
|
|
|
+ }
|
|
|
+
|
|
|
+ fn ensure_channel_exists(channel_id: &T::ChannelId) -> Result<Channel<T>, Error<T>> {
|
|
|
+ ensure!(
|
|
|
+ ChannelById::<T>::contains_key(channel_id),
|
|
|
+ Error::<T>::ChannelDoesNotExist
|
|
|
+ );
|
|
|
+ Ok(ChannelById::<T>::get(channel_id))
|
|
|
+ }
|
|
|
+
|
|
|
fn ensure_post_exists(
|
|
|
video_id: T::VideoId,
|
|
|
post_id: T::VideoPostId,
|
|
@@ -2208,13 +2104,6 @@ impl<T: Trait> Module<T> {
|
|
|
|
|
|
Ok(())
|
|
|
}
|
|
|
-
|
|
|
- // Reset Videos and Channels on runtime upgrade but preserving next ids and categories.
|
|
|
- pub fn on_runtime_upgrade() {
|
|
|
- // setting final index triggers migration
|
|
|
- <VideoMigration<T>>::mutate(|config| config.final_id = <NextVideoId<T>>::get());
|
|
|
- <ChannelMigration<T>>::mutate(|config| config.final_id = <NextChannelId<T>>::get());
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
decl_event!(
|