Browse Source

Merge pull request #119 from mnaamani/wg-fix-mint-config

content working group: create mint and optionaly lead at genesis
Bedeho Mender 5 years ago
parent
commit
aa7cc55380
2 changed files with 24 additions and 20 deletions
  1. 3 9
      src/content_working_group/genesis.rs
  2. 21 11
      src/content_working_group/lib.rs

+ 3 - 9
src/content_working_group/genesis.rs

@@ -13,8 +13,7 @@ use forum::InputValidationLengthConstraint;
 
 /// Builder of genesis configuration of content working group.
 pub struct GenesisConfigBuilder<T: Trait> {
-    mint: <T as minting::Trait>::MintId,
-
+    mint_capacity: minting::BalanceOf<T>,
     /*
     lead_by_id: GenesisConfigMap<LeadId<T>, Lead<T::AccountId, T::RewardRelationshipId, T::BlockNumber>>,
     next_lead_id: LeadId<T>,
@@ -65,12 +64,7 @@ impl<T: Trait> GenesisConfigBuilder<T> {
     */
     pub fn build(self) -> GenesisConfig<T> {
         GenesisConfig {
-            mint: self.mint,
-
-            // WE HAVE TO PROVIDE SOME VALUE FOR THESE FOR NOW
-            // USING DEFAULT FOR NOW.
-            lead_by_id: map![], //GenesisConfigMap<LeadId, Lead>,
-            next_lead_id: LeadId::<T>::default(),
+            mint_capacity: self.mint_capacity,
             curator_opening_by_id: map![], //GenesisConfigMap<CuratorOpeningId, Opening>,
             next_curator_opening_id: CuratorOpeningId::<T>::default(),
             curator_application_by_id: map![], //GenesisConfigMap<CuratorApplicationId,CuratorApplication>,
@@ -107,7 +101,7 @@ impl<T: Trait> Default for GenesisConfigBuilder<T> {
         };
 
         Self {
-            mint: <T as minting::Trait>::MintId::default(),
+            mint_capacity: minting::BalanceOf::<T>::from(10000),
 
             /*
             current_lead_id: LeadId::<T>::default(), //Option<LeadId>,

+ 21 - 11
src/content_working_group/lib.rs

@@ -994,17 +994,16 @@ decl_storage! {
     trait Store for Module<T: Trait> as ContentWorkingGroup {
 
         /// The mint currently funding the rewards for this module.
-        pub Mint get(mint) config(): <T as minting::Trait>::MintId;
+        pub Mint get(mint) : <T as minting::Trait>::MintId;
 
         /// The current lead.
-        /// Not configurable, because default set value breaks semantics: https://github.com/Joystream/joystream/issues/36#issuecomment-564560373
-        pub CurrentLeadId get(current_lead_id): Option<LeadId<T>>;
+        pub CurrentLeadId get(current_lead_id) : Option<LeadId<T>>;
 
         /// Maps identifier to corresponding lead.
-        pub LeadById get(lead_by_id) config(): linked_map LeadId<T> => Lead<T::AccountId, T::RewardRelationshipId, T::BlockNumber>;
+        pub LeadById get(lead_by_id): linked_map LeadId<T> => Lead<T::AccountId, T::RewardRelationshipId, T::BlockNumber>;
 
         /// Next identifier for new current lead.
-        pub NextLeadId get(next_lead_id) config(): LeadId<T>;
+        pub NextLeadId get(next_lead_id): LeadId<T>;
 
         /// Maps identifeir to curator opening.
         pub CuratorOpeningById get(curator_opening_by_id) config(): linked_map CuratorOpeningId<T> => CuratorOpening<T::OpeningId, T::BlockNumber, BalanceOf<T>, CuratorApplicationId<T>>;
@@ -1066,6 +1065,15 @@ decl_storage! {
         pub CuratorApplicationHumanReadableText get(curator_application_human_readable_text) config(): InputValidationLengthConstraint;
         pub CuratorExitRationaleText get(curator_exit_rationale_text) config(): InputValidationLengthConstraint;
     }
+    add_extra_genesis {
+        config(mint_capacity): minting::BalanceOf<T>;
+        // config(mint_adjustment): minting::Adjustment<BalanceOf<T>, T::BlockNumber> (add serialize/deserialize derivation for type)
+        build(|config: &GenesisConfig<T>| {
+            // create mint
+            let mint_id = <minting::Module<T>>::add_mint(config.mint_capacity, None).expect("Failed to create a mint for the content working group");
+            Mint::<T>::put(mint_id);
+        });
+    }
 }
 
 decl_event! {
@@ -1901,7 +1909,7 @@ decl_module! {
             // Ensure root is origin
             ensure_root(origin)?;
 
-            // Ensure there is no current lead
+                    // Ensure there is no current lead
             ensure!(
                 <CurrentLeadId<T>>::get().is_none(),
                 MSG_CURRENT_LEAD_ALREADY_SET
@@ -1910,11 +1918,12 @@ decl_module! {
             // Ensure that member can actually become lead
             let new_lead_id = <NextLeadId<T>>::get();
 
-            let new_lead_role = role_types::ActorInRole::new(role_types::Role::CuratorLead, new_lead_id);
+            let new_lead_role =
+                role_types::ActorInRole::new(role_types::Role::CuratorLead, new_lead_id);
 
             let _profile = <members::Module<T>>::can_register_role_on_member(
                 &member,
-                &role_types::ActorInRole::new(role_types::Role::CuratorLead, new_lead_id)
+                &role_types::ActorInRole::new(role_types::Role::CuratorLead, new_lead_id),
             )?;
 
             //
@@ -1922,11 +1931,11 @@ decl_module! {
             //
 
             // Construct lead
-            let new_lead = Lead{
+            let new_lead = Lead {
                 role_account: role_account.clone(),
                 reward_relationship: None,
                 inducted: <system::Module<T>>::block_number(),
-                stage: LeadRoleState::Active
+                stage: LeadRoleState::Active,
             };
 
             // Store lead
@@ -1939,7 +1948,8 @@ decl_module! {
             <NextLeadId<T>>::mutate(|id| *id += <LeadId<T> as One>::one());
 
             // Register in role
-            let registered_role = <members::Module<T>>::register_role_on_member(member, &new_lead_role).is_ok();
+            let registered_role =
+                <members::Module<T>>::register_role_on_member(member, &new_lead_role).is_ok();
 
             assert!(registered_role);