Browse Source

Remove unused types from the bureaucracy module

- remove unused types from the bureaucracy module
- add an event
Shamil Gadelshin 4 years ago
parent
commit
291490ef75

+ 0 - 1
Cargo.lock

@@ -4479,7 +4479,6 @@ dependencies = [
  "substrate-hiring-module",
  "substrate-membership-module",
  "substrate-primitives",
- "substrate-recurring-reward-module",
  "substrate-stake-module",
  "substrate-token-mint-module",
 ]

+ 0 - 6
runtime-modules/bureaucracy/Cargo.toml

@@ -17,7 +17,6 @@ std = [
     'stake/std',
     'membership/std',
     'minting/std',
-    'recurringrewards/std',
 ]
 
 [dependencies.primitives]
@@ -76,11 +75,6 @@ default_features = false
 package = 'substrate-membership-module'
 path = '../membership'
 
-[dependencies.recurringrewards]
-default_features = false
-package = 'substrate-recurring-reward-module'
-path = '../recurring-reward'
-
 [dependencies.minting]
 default_features = false
 package = 'substrate-token-mint-module'

+ 51 - 70
runtime-modules/bureaucracy/src/lib.rs

@@ -3,12 +3,10 @@
 
 mod types;
 
-use sr_primitives::traits::One;
-use srml_support::traits::Currency;
-use srml_support::{decl_module, decl_storage, dispatch, ensure};
+use srml_support::{decl_module, decl_event, decl_storage, dispatch};
 use system::ensure_root;
 
-use types::{Lead, LeadRoleState};
+use types::Lead;
 
 //TODO: convert messages to the decl_error! entries
 pub static MSG_ORIGIN_IS_NOT_LEAD: &str = "Origin is not lead";
@@ -16,101 +14,84 @@ pub static MSG_CURRENT_LEAD_NOT_SET: &str = "Current lead is not set";
 pub static MSG_CURRENT_LEAD_ALREADY_SET: &str = "Current lead is already set";
 pub static MSG_IS_NOT_LEAD_ACCOUNT: &str = "Not a lead account";
 
-/// Type identifier for lead role, which must be same as membership actor identifier
-pub type LeadId<T> = <T as membership::members::Trait>::ActorId;
-
-/// Type of minting reward relationship identifiers
-pub type RewardRelationshipId<T> = <T as recurringrewards::Trait>::RewardRelationshipId;
-
-/// Balance type of runtime
-pub type BalanceOf<T> =
-    <<T as stake::Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::Balance;
+/// Alias for the _Lead_ type
+pub type LeadOf<T> = Lead<
+    <T as membership::members::Trait>::MemberId,
+    <T as system::Trait>::AccountId,
+>;
 
 /// The bureaucracy main _Trait_
 pub trait Trait<I: Instance>:
-    system::Trait + recurringrewards::Trait + membership::members::Trait
+    system::Trait + membership::members::Trait
 {
+    /// Bureaucracy event type.
+    type Event: From<Event<Self, I>> + Into<<Self as system::Trait>::Event>;
 }
 
+decl_event!(
+    /// Proposals engine events
+    pub enum Event<T, I>
+    where
+        <T as membership::members::Trait>::MemberId,
+        <T as system::Trait>::AccountId
+    {
+        /// Emits on settings the leader.
+        /// Params:
+        /// - Member id of the leader.
+        /// - Role account id of the leader.
+        LeaderSet(MemberId, AccountId),
+
+    }
+);
+
 decl_storage! {
     trait Store for Module<T: Trait<I>, I: Instance> as Bureaucracy {
         /// The current lead.
-        pub CurrentLeadId get(current_lead_id) : Option<LeadId<T>>;
-
-        /// Maps identifier to corresponding lead.
-        pub LeadById get(lead_by_id): linked_map LeadId<T> => Lead<T::MemberId, T::AccountId, T::RewardRelationshipId, T::BlockNumber>;
-
-        /// Next identifier for new current lead.
-        pub NextLeadId get(next_lead_id): LeadId<T>;
+        pub CurrentLead get(current_lead) : Option<LeadOf<T>>;
     }
 }
 
 decl_module! {
     pub struct Module<T: Trait<I>, I: Instance> for enum Call where origin: T::Origin {
-    /// Introduce a lead when one is not currently set.
-    pub fn set_lead(origin, member: T::MemberId, role_account: T::AccountId) -> dispatch::Result {
-        ensure_root(origin)?;
-
-        // Ensure there is no current lead
-        ensure!(
-            <CurrentLeadId<T, I>>::get().is_none(),
-            MSG_CURRENT_LEAD_ALREADY_SET
-        );
-
-        let new_lead_id = <NextLeadId<T, I>>::get();
-
-        // Construct lead
-        let new_lead = Lead {
-            member_id: member,
-            role_account,
-            reward_relationship: None,
-            inducted: <system::Module<T>>::block_number(),
-            stage: LeadRoleState::Active,
-        };
+        /// Default deposit_event() handler
+        fn deposit_event() = default;
 
-        // mutation
+        /// Introduce a lead when one is not currently set.
+        pub fn set_lead(origin, member_id: T::MemberId, role_account_id: T::AccountId) -> dispatch::Result {
+            ensure_root(origin)?;
 
-        // Store lead
-        <LeadById<T, I>>::insert(new_lead_id, new_lead);
+            // Construct lead
+            let new_lead = Lead {
+                member_id,
+                role_account_id: role_account_id.clone(),
+            };
 
-        // Update current lead
-        <CurrentLeadId<T, I>>::put(new_lead_id);
+            // mutation
 
-        // Update next lead counter
-        <NextLeadId<T, I>>::mutate(|id| *id += <LeadId<T> as One>::one());
+            // Update current lead
+            <CurrentLead<T, I>>::put(new_lead);
 
-        // Trigger event: TODO: create bureaucracy events
-        //        Self::deposit_event(RawEvent::LeadSet(new_lead_id));
+            // Trigger an event
+            Self::deposit_event(RawEvent::LeaderSet(member_id, role_account_id));
 
-        Ok(())
-    }
+            Ok(())
+        }
     }
 }
 
 impl<T: Trait<I>, I: Instance> Module<T, I> {
     /// Checks that provided lead account id belongs to the current bureaucracy leader
     pub fn ensure_is_lead_account(lead_account_id: T::AccountId) -> Result<(), &'static str> {
-        // Ensure lead id is set
-        let lead_id = Self::ensure_lead_id_set()?;
+        let lead = <CurrentLead<T, I>>::get();
 
-        // If so, grab actual lead
-        let lead = <LeadById<T, I>>::get(lead_id);
-
-        if lead.role_account != lead_account_id {
-            return Err(MSG_IS_NOT_LEAD_ACCOUNT);
+        if let Some(lead) = lead {
+            if lead.role_account_id != lead_account_id {
+                return Err(MSG_IS_NOT_LEAD_ACCOUNT);
+            }
+        } else {
+            return Err(MSG_CURRENT_LEAD_NOT_SET);
         }
 
         Ok(())
     }
-
-    // checks that storage contains lead_id
-    fn ensure_lead_id_set() -> Result<LeadId<T>, &'static str> {
-        let opt_current_lead_id = <CurrentLeadId<T, I>>::get();
-
-        if let Some(lead_id) = opt_current_lead_id {
-            Ok(lead_id)
-        } else {
-            Err(MSG_CURRENT_LEAD_NOT_SET)
-        }
-    }
 }

+ 2 - 41
runtime-modules/bureaucracy/src/types.rs

@@ -2,52 +2,13 @@ use codec::{Decode, Encode};
 #[cfg(feature = "std")]
 use serde::{Deserialize, Serialize};
 
-/// The exit stage of a lead involvement in the working group.
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Debug, Clone, PartialEq)]
-pub struct ExitedLeadRole<BlockNumber> {
-    /// When exit was initiated.
-    pub initiated_at_block_number: BlockNumber,
-}
-
-/// The stage of the involvement of a lead in the working group.
-#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Debug, Clone, PartialEq)]
-pub enum LeadRoleState<BlockNumber> {
-    /// Currently active.
-    Active,
-
-    /// No longer active, for some reason
-    Exited(ExitedLeadRole<BlockNumber>),
-}
-
-/// Must be default constructible because it indirectly is a value in a storage map.
-/// ***SHOULD NEVER ACTUALLY GET CALLED, IS REQUIRED TO DUE BAD STORAGE MODEL IN SUBSTRATE***
-impl<BlockNumber> Default for LeadRoleState<BlockNumber> {
-    fn default() -> Self {
-        LeadRoleState::Active
-    }
-}
-
 /// Working group lead: curator lead
-/// For now this role is not staked or inducted through an structured process, like the hiring module,
-/// hence information about this is missing. Recurring rewards is included, somewhat arbitrarily!
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
 #[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
-pub struct Lead<MemberId, AccountId, RewardRelationshipId, BlockNumber> {
+pub struct Lead<MemberId, AccountId> {
     /// Member id of the leader
     pub member_id: MemberId,
 
     /// Account used to authenticate in this role,
-    pub role_account: AccountId,
-
-    /// Whether the role has recurring reward, and if so an identifier for this.
-    pub reward_relationship: Option<RewardRelationshipId>,
-
-    /// When was inducted
-    /// TODO: Add richer information about circumstances of induction, like referencing a council proposal?
-    pub inducted: BlockNumber,
-
-    /// The stage of the involvement of this lead in the working group.
-    pub stage: LeadRoleState<BlockNumber>,
+    pub role_account_id: AccountId,
 }

+ 3 - 1
runtime/src/lib.rs

@@ -791,7 +791,9 @@ impl migration::Trait for Runtime {
 }
 
 // Forum bureaucracy
-impl bureaucracy::Trait<bureaucracy::Instance1> for Runtime {}
+impl bureaucracy::Trait<bureaucracy::Instance1> for Runtime {
+    type Event = Event;
+}
 
 impl actors::Trait for Runtime {
     type Event = Event;