Browse Source

Almost building, pushing for review

Bedeho Mender 5 years ago
parent
commit
9c8afcf016
3 changed files with 143 additions and 59 deletions
  1. 8 1
      Cargo.toml
  2. 51 29
      src/content_working_group/lib.rs
  3. 84 29
      src/content_working_group/mock.rs

+ 8 - 1
Cargo.toml

@@ -46,6 +46,7 @@ std = [
     'recurringrewards/std',
     'stake/std',
     'hiring/std',
+    'versioned_store/std',
     'versioned_store_permissions/std'
 ]
 
@@ -271,7 +272,7 @@ rev = '5570e3b56e9caffa7df1dbede6308b2e6ce18217'
 default_features = false
 git = 'https://github.com/Joystream/substrate-recurring-reward-module'
 package = 'substrate-recurring-reward-module'
-rev = 'dfdadb22c6acf317aed3558224c154f4b4b1dfb1'
+rev = '56add2132ab2957006988fb862cfdc3d734ed3d3'
 
 [dependencies.stake]
 default_features = false
@@ -285,6 +286,12 @@ git = 'https://github.com/bedeho/substrate-hiring-module'
 package = 'substrate-hiring-module'
 rev = '21efbf1b9535c5c18dc36e9e42e192f3c9c7515b'
 
+[dependencies.versioned_store]
+default_features = false
+package ='substrate-versioned-store'
+git = 'https://github.com/joystream/substrate-versioned-store-module'
+rev = 'd0c68722405355404840512edf3064d5ced3e1fe'
+
 [dependencies.versioned_store_permissions]
 default_features = false
 git = 'https://github.com/mnaamani/substrate-versioned-store-permissions-module'

+ 51 - 29
src/content_working_group/lib.rs

@@ -10,9 +10,9 @@ use rstd::collections::btree_set::BTreeSet;
 use rstd::prelude::*;
 use srml_support::traits::Currency;
 use srml_support::{
-    decl_module, decl_storage, decl_event, ensure, StorageMap, StorageValue, Parameter
+    decl_module, decl_storage, decl_event, Parameter // ensure, StorageMap, StorageValue,
 };
-use runtime_primitives::traits::{Member, One, SimpleArithmetic, MaybeSerialize};
+use runtime_primitives::traits::{Member, SimpleArithmetic, MaybeSerialize};
 use minting;
 use recurringrewards;
 use stake;
@@ -21,7 +21,7 @@ use versioned_store_permissions;
 use super::super::membership::members as membership;
 
 /// Module configuration trait for this Substrate module.
-pub trait Trait: system::Trait + minting::Trait + recurringrewards::Trait + stake::Trait + hiring::Trait + versioned_store_permissions::Trait + membership::Trait + Sized {
+pub trait Trait: system::Trait + minting::Trait + recurringrewards::Trait + stake::Trait + hiring::Trait + versioned_store_permissions::Trait + membership::Trait { // + Sized
 
     /// The event type.
     type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
@@ -59,18 +59,18 @@ pub trait Trait: system::Trait + minting::Trait + recurringrewards::Trait + stak
 }
 
 /// Type for identifier for dynamic version store credential.
-pub type DynamicCredentialId<T: Trait> = T::PrincipalId;
+pub type DynamicCredentialId<T: Trait> = <T as versioned_store_permissions::Trait>::PrincipalId;
 
 /// Balance type of runtime
 pub type BalanceOf<T> =
     <<T as stake::Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::Balance;
 
 /// Negative imbalance of runtime.
-pub type NegativeImbalance<T> =
-    <<T as stake::Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::NegativeImbalance;
+// pub type NegativeImbalance<T> =
+//    <<T as stake::Trait>::Currency as Currency<<T as system::Trait>::AccountId>>::NegativeImbalance;
 
 /// The exit stage of a lead involvement in the working group.
-#[derive(Encode, Decode, Debug, Eq, PartialEq, Clone, PartialOrd)]
+#[derive(Encode, Decode, Debug, Clone)]
 pub struct ExitedLeadRole<BlockNumber> {
 
     /// When exit was initiated.
@@ -78,7 +78,7 @@ pub struct ExitedLeadRole<BlockNumber> {
 }
 
 /// The stage of the involvement of a lead in the working group.
-#[derive(Encode, Decode, Debug, Eq, PartialEq, Clone, PartialOrd)]
+#[derive(Encode, Decode, Debug, Clone)]
 pub enum LeadRoleState<BlockNumber> {
 
     /// Currently active.
@@ -100,7 +100,7 @@ impl<BlockNumber> Default for LeadRoleState<BlockNumber> {
 /// 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!
-#[derive(Encode, Decode, Default, Debug, Eq, PartialEq, Clone, PartialOrd)]
+#[derive(Encode, Decode, Default, Debug, Clone)]
 pub struct Lead<AccountId, RewardRelationshipId, BlockNumber> {
 
     /// Account used to authenticate in this role,
@@ -118,7 +118,7 @@ pub struct Lead<AccountId, RewardRelationshipId, BlockNumber> {
 }
 
 /// Origin of exit initiation on behalf of a curator.'
-#[derive(Encode, Decode, Debug, Eq, PartialEq, Clone, PartialOrd)]
+#[derive(Encode, Decode, Debug, Clone)]
 pub enum CuratorExitInitiationOrigin {
 
     /// Lead is origin.
@@ -129,7 +129,7 @@ pub enum CuratorExitInitiationOrigin {
 }
 
 /// The exit stage of a curators involvement in the working group.
-#[derive(Encode, Decode, Debug, Eq, PartialEq, Clone, PartialOrd)]
+#[derive(Encode, Decode, Debug, Clone)]
 pub struct ExitedCuratorRoleStage<BlockNumber> {
 
     /// Origin for exit.
@@ -143,7 +143,7 @@ pub struct ExitedCuratorRoleStage<BlockNumber> {
 }
 
 /// The stage of the involvement of a curator in the working group.
-#[derive(Encode, Decode, Debug, Eq, PartialEq, Clone, PartialOrd)]
+#[derive(Encode, Decode, Debug, Clone)]
 pub enum CuratorRoleStage<BlockNumber> {
 
     /// Currently active.
@@ -163,7 +163,7 @@ impl<BlockNumber> Default for CuratorRoleStage<BlockNumber> {
 }
 
 /// The induction of a curator in the working group.
-#[derive(Encode, Decode, Default, Debug, Eq, PartialEq, Clone, PartialOrd)]
+#[derive(Encode, Decode, Default, Debug, Clone)]
 pub struct CuratorInduction<LeadId, ApplicationId, BlockNumber> {
 
     /// Lead responsible
@@ -178,7 +178,7 @@ pub struct CuratorInduction<LeadId, ApplicationId, BlockNumber> {
 
 /// Working group participant: curator
 /// This role can be staked, have reward and be inducted through the hiring module.
-#[derive(Encode, Decode, Default, Debug, Eq, PartialEq, Clone, PartialOrd)]
+#[derive(Encode, Decode, Default, Debug, Clone)]
 pub struct Curator<AccountId, RewardRelationshipId, StakeId, BlockNumber, LeadId, ApplicationId> {
 
     /// Account used to authenticate in this role,
@@ -200,8 +200,13 @@ pub struct Curator<AccountId, RewardRelationshipId, StakeId, BlockNumber, LeadId
     pub can_update_channel_curation_status: bool
 }
 
+/*
+ * BEGIN: =========================================================
+ * Channel stuff
+ */
+
 /// Type of channel content.
-#[derive(Encode, Decode, Debug, Eq, PartialEq, Clone, PartialOrd)]
+#[derive(Encode, Decode, Debug, Clone, PartialEq)]
 pub enum ChannelContentType {
     Video,
     Music,
@@ -220,7 +225,7 @@ impl Default for ChannelContentType {
 /// Status of channel, as set by the owner.
 /// Is only meant to affect visibility, mutation of channel and child content
 /// is unaffected on runtime.
-#[derive(Encode, Decode, Debug, Eq, PartialEq, Clone, PartialOrd)]
+#[derive(Encode, Decode, Debug, Clone, PartialEq)]
 pub enum ChannelPublishingStatus {
 
     /// Compliant UIs should render.
@@ -243,7 +248,7 @@ impl Default for ChannelPublishingStatus {
 /// Is only meant to affect visibility currently, but in the future
 /// it will also gate publication of new child content,
 /// editing properties, revenue flows, etc. 
-#[derive(Encode, Decode, Debug, Eq, PartialEq, Clone, PartialOrd)]
+#[derive(Encode, Decode, Debug, Clone, PartialEq)]
 pub enum ChannelCurationStatus {
     Normal,
     Censored
@@ -259,7 +264,7 @@ impl Default for ChannelCurationStatus {
 }
 
 /// A channel for publishing content.
-#[derive(Encode, Decode, Default, Debug, Eq, PartialEq, Clone, PartialOrd)]
+#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
 pub struct Channel<MemberId, AccountId, BlockNumber> {
 
     /// Unique human readble channel handle.
@@ -292,8 +297,13 @@ pub struct Channel<MemberId, AccountId, BlockNumber> {
 
 }
 
+/*
+ * END: =========================================================
+ * Channel stuff
+ */
+
 /// The types of built in credential holders.
-#[derive(Encode, Decode, Debug, Eq, PartialEq, Clone, PartialOrd)]
+#[derive(Encode, Decode, Debug, Clone)]
 pub enum BuiltInCredentialHolder {
 
     /// Cyrrent working group lead.
@@ -307,7 +317,7 @@ pub enum BuiltInCredentialHolder {
 }
 
 /// Holder of dynamic credential.
-#[derive(Encode, Decode, Debug, Eq, PartialEq, Clone, PartialOrd)]
+#[derive(Encode, Decode, Debug, Clone)]
 pub enum DynamicCredentialHolder<CuratorId: Ord, ChannelId> {
 
     /// Sets of curators.
@@ -328,7 +338,7 @@ impl<CuratorId: Ord, ChannelId> Default for DynamicCredentialHolder<CuratorId, C
 
 /// Represents credential for authenticating as "the current lead".
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Debug, Eq, PartialEq, Clone, PartialOrd, Default)]
+#[derive(Encode, Decode, Debug, Clone, Default)]
 pub struct LeadCredential {
 
     /// Whether it is currently possible to authenticate with this credential.
@@ -337,7 +347,7 @@ pub struct LeadCredential {
 
 /// Represents credential for authenticating as "any curator".
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Debug, Eq, PartialEq, Clone, PartialOrd, Default)]
+#[derive(Encode, Decode, Debug, Clone, Default)]
 pub struct AnyCuratorCredential {
 
     /// Whether it is currently possible to authenticate with this credential.
@@ -346,7 +356,7 @@ pub struct AnyCuratorCredential {
 
 /// Represents credential for authenticating as "any member".
 #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
-#[derive(Encode, Decode, Debug, Eq, PartialEq, Clone, PartialOrd, Default)]
+#[derive(Encode, Decode, Debug, Clone, Default)]
 pub struct AnyMemberCredential {
 
     /// Whether it is currently possible to authenticate with this credential.
@@ -355,7 +365,7 @@ pub struct AnyMemberCredential {
 
 /// Represents credential to be referenced from the version store.
 /// It is dynamic in the sense that these can be created on the fly.
-#[derive(Encode, Decode, Default, Debug, Eq, PartialEq, Clone, PartialOrd)]
+#[derive(Encode, Decode, Default, Debug, Clone)]
 pub struct DynamicCredential<CuratorId: Ord, ChannelId, BlockNumber> {
 
     /// Who holds this credential, meaning they can successfully authenticate with this credential.
@@ -374,8 +384,8 @@ pub struct DynamicCredential<CuratorId: Ord, ChannelId, BlockNumber> {
 /// Policy governing any curator opening which can be made by lead.
 /// Be aware that all limits are forward looking in constrainign future extrinsics or method calls.
 /// Updating them has no side-effects beyond changing the limit.
-#[derive(Encode, Decode, Debug, Eq, PartialEq, Clone, PartialOrd)]
-pub struct OpeningPolicy<BlockNumber, StakingPolicy> {
+#[derive(Encode, Decode, Debug, Clone, Default)]
+pub struct OpeningPolicy<BlockNumber: Default, Balance> {
 
     /// Limits the total number of curators which can be active, or possibly active through an active opening. 
     /// The contribution of an active opening is counted by looking at the rationing policy of the opening.
@@ -388,12 +398,24 @@ pub struct OpeningPolicy<BlockNumber, StakingPolicy> {
     pub max_review_period_length: BlockNumber,
 
     /// Staking policy for application
-    pub application_staking_policy: Option<StakingPolicy>,
+    pub application_staking_policy: Option<hiring::StakingPolicy<Balance, BlockNumber>>,
 
     /// Staking policy for role itself
-    pub role_staking_policy: Option<StakingPolicy>
+    pub role_staking_policy: Option<hiring::StakingPolicy<Balance, BlockNumber>>
 }
 
+/*
+impl<BlockNumber, StakingPolicy> Default for OpeningPolicy<BlockNumber, StakingPolicy> {
+
+    return OpeningPolicy {
+        curator_limit: Option<u16>,
+        max_review_period_length: BlockNumber,
+        application_staking_policy: Option<StakingPolicy>,
+        role_staking_policy: Option<StakingPolicy>
+    }
+}
+*/
+
 /// Represents 
 #[derive(Encode, Decode, Debug, Eq, PartialEq, Clone, PartialOrd)]
 pub enum WorkingGroupActor<T: Trait> {
@@ -452,7 +474,7 @@ decl_storage! {
 
         /// The constraints lead must respect when creating a new curator opening.
         /// Lack of policy is interpreted as blocking any new openings at all.
-        pub OptOpeningPolicy get(opening_policy) config(): Option<OpeningPolicy<T::BlockNumber, hiring::StakingPolicy<BalanceOf<T>, T::BlockNumber>>>;
+        pub OptOpeningPolicy get(opening_policy) config(): Option<OpeningPolicy<T::BlockNumber, BalanceOf<T>>>;
 
         /// Credentials for built in roles.
         pub CredentialOfLead get(credential_of_lead) config(): LeadCredential;

+ 84 - 29
src/content_working_group/mock.rs

@@ -14,21 +14,39 @@ pub use runtime_primitives::{
 
 use srml_support::{impl_outer_origin, parameter_types};
 
+use minting;
+use recurringrewards;
 use stake;
+use hiring;
+use versioned_store;
+use versioned_store_permissions;
 
-impl_outer_origin! {
-    pub enum Origin for Test {}
-}
+//use crate::membership;
+use super::super::membership::members as membership;
+
+pub use crate::currency::GovernanceCurrency;
 
-// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
-#[derive(Clone, PartialEq, Eq, Debug)]
-pub struct Test;
 parameter_types! {
     pub const BlockHashCount: u64 = 250;
     pub const MaximumBlockWeight: u32 = 1024;
     pub const MaximumBlockLength: u32 = 2 * 1024;
     pub const AvailableBlockRatio: Perbill = Perbill::one();
     pub const MinimumPeriod: u64 = 5;
+    pub const ExistentialDeposit: u32 = 0;
+    pub const TransferFee: u32 = 0;
+    pub const CreationFee: u32 = 0;
+    pub const TransactionBaseFee: u32 = 1;
+    pub const TransactionByteFee: u32 = 0;
+    pub const InitialMembersBalance: u64 = 2000;
+    pub const StakePoolId: [u8; 8] = *b"joystake";
+}
+
+// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted.
+#[derive(Clone, PartialEq, Eq, Debug)]
+pub struct Test;
+
+impl_outer_origin! {
+    pub enum Origin for Test {}
 }
 
 impl system::Trait for Test {
@@ -49,25 +67,12 @@ impl system::Trait for Test {
     type Version = ();
 }
 
-parameter_types! {
-    pub const ExistentialDeposit: u32 = 0;
-    pub const TransferFee: u32 = 0;
-    pub const CreationFee: u32 = 0;
-    pub const TransactionBaseFee: u32 = 1;
-    pub const TransactionByteFee: u32 = 0;
-    pub const InitialMembersBalance: u64 = 2000;
-    pub const StakePoolId: [u8; 8] = *b"joystake";
+impl timestamp::Trait for Test {
+    type Moment = u64;
+    type OnTimestampSet = ();
+    type MinimumPeriod = MinimumPeriod;
 }
 
-// system::Trait + 
-// minting::Trait +
-// recurringrewards::Trait +
-// stake::Trait +
-// hiring::Trait +
-// versioned_store_permissions::Trait +
-// membership::Trait +
-// Sized
-
 impl balances::Trait for Test {
     /// The type for recording an account's balance.
     type Balance = u64;
@@ -85,21 +90,71 @@ impl balances::Trait for Test {
     type CreationFee = CreationFee;
 }
 
-impl Trait for Test {
-    type Event = ();
-    type LeadId = u64;
-    type CuratorId = u64;
-    type ChannelId = u64;   
+/*
+pub trait PrincipalIdChecker<T: Trait> {
+    fn account_can_act_as_principal(account: &T::AccountId, group: T::PrincipalId) -> bool;
+}
+
+pub trait CreateClassPermissionsChecker<T: Trait> {
+    fn account_can_create_class_permissions(account: &T::AccountId) -> bool;
+}
+*/
+
+impl GovernanceCurrency for Test {
+    type Currency = balances::Module<Self>;
+}
+
+impl minting::Trait for Test {
+    type Currency = balances::Module<Self>; // Balances;
+    type MintId = u64;
+}
+
+impl recurringrewards::Trait for Test {
+    type PayoutStatusHandler = ();
+    type RecipientId = u64;
+    type RewardRelationshipId = u64;
 }
 
 impl stake::Trait for Test {
-    type Currency = Balances;
+    type Currency = balances::Module<Self>; // Balances;
     type StakePoolId = StakePoolId;
     type StakingEventsHandler = ();
     type StakeId = u64;
     type SlashId = u64;
 }
 
+impl hiring::Trait for Test {
+    type OpeningId = u64;
+    type ApplicationId = u64;
+    type ApplicationDeactivatedHandler = ();
+}
+
+impl versioned_store::Trait for Test {
+    type Event = ();
+}
+
+impl versioned_store_permissions::Trait for Test {
+    type PrincipalId = u64;
+    type PrincipalIdChecker = ();
+    type CreateClassPermissionsChecker =  ();
+}
+
+impl membership::Trait for Test {
+    type Event = ();
+    type MemberId = u64;
+    type PaidTermId = u64;
+    type SubscriptionId = u64;
+    type ActorId = u64;
+    type InitialMembersBalance = InitialMembersBalance;
+}
+
+impl Trait for Test {
+    type Event = ();
+    type LeadId = u64;
+    type CuratorId = u64;
+    type ChannelId = u64;   
+}
+
 pub fn build_test_externalities() -> runtime_io::TestExternalities {
     let t = system::GenesisConfig::default()
         .build_storage::<Test>()