Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
43376ab
adding membership module - storage
mnaamani Mar 13, 2019
216e694
use default implicit value for paid terms instead of initializing map
mnaamani Mar 13, 2019
a7d4aac
add migration
mnaamani Mar 14, 2019
6923186
renaming, adding handles map
mnaamani Mar 14, 2019
1237df8
membership: implement buy_membership
mnaamani Mar 14, 2019
918868e
make avatar_uri an Option instead of empty string to represent no uri
mnaamani Mar 14, 2019
cb1a3a7
add simple buy membership method
mnaamani Mar 14, 2019
6e202d9
burn fee when buying membership
mnaamani Mar 14, 2019
54738e7
keep extrinsic validation outside insert_new_paid_member
mnaamani Mar 14, 2019
e99cb53
update methods for profile
mnaamani Mar 14, 2019
6f46ad1
add method to change multiple profile user infos in one transaction
mnaamani Mar 14, 2019
ac0c928
check allowed new members before accepting new members
mnaamani Mar 14, 2019
f095b67
handle runtime uptime by using spec_version
mnaamani Mar 14, 2019
1d63f67
fix batch profile update
mnaamani Mar 14, 2019
7ae24d0
rename update profile method, and don't truncate avatar uri
mnaamani Mar 16, 2019
2d3329a
member sub accounts
mnaamani Mar 16, 2019
da0a072
add some notes on sub-accounts
mnaamani Mar 16, 2019
31fd1de
default min length of handle 5 chars
mnaamani Mar 16, 2019
95e4cd3
adjust avatar, handle and about text default max lengths
mnaamani Mar 16, 2019
478fbe0
reorg membership into a module directory
mnaamani Mar 19, 2019
a227fa3
add tests for membership
mnaamani Mar 19, 2019
27b7841
membership tests
mnaamani Mar 20, 2019
5ba5f86
membership: more tests
mnaamani Mar 20, 2019
74531d2
membership sub accounts, fix updating subaccounts
mnaamani Mar 20, 2019
3328650
membership tests
mnaamani Mar 20, 2019
bf2f5d5
introduce IsActiveMember trait
mnaamani Mar 20, 2019
c8b70cc
use IsActiveMember trait in election and runtime upgrade proposal mod…
mnaamani Mar 20, 2019
c7326e1
factor our migration to its own module
mnaamani Mar 20, 2019
53e54b6
additional comments on membership methods
mnaamani Mar 20, 2019
3fab73d
membership sub accounts - revert (move to staked roles)
mnaamani Mar 21, 2019
9f07751
add member through screener
mnaamani Mar 21, 2019
3e43d9e
refactor membership: renamed registry module to members
mnaamani Mar 25, 2019
75d835d
members: refactor insert members method
mnaamani Mar 25, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ rev = 'df5e65927780b323482e2e8b5031822f423a032d'

[dependencies.parity-codec]
default-features = false
version = '3.0'
version = '3.1'

[dependencies.parity-codec-derive]
default-features = false
version = '3.0'
version = '3.1'

[dependencies.primitives]
default_features = false
Expand Down
14 changes: 9 additions & 5 deletions src/governance/election.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@ use super::sealed_vote::SealedVote;
pub use super::{ GovernanceCurrency, BalanceOf };
use super::council;

use crate::traits::{IsActiveMember};

pub trait Trait: system::Trait + council::Trait + GovernanceCurrency {
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;

type CouncilElected: CouncilElected<Seats<Self::AccountId, BalanceOf<Self>>, Self::BlockNumber>;

type IsActiveMember: IsActiveMember<Self>;
}

#[derive(Clone, Copy, Encode, Decode)]
Expand Down Expand Up @@ -148,9 +152,9 @@ impl<T: Trait> Module<T> {
<system::Module<T>>::block_number() + length
}

// TODO This method should be moved to Membership module once it's created.
fn is_member(sender: T::AccountId) -> bool {
!T::Currency::free_balance(&sender).is_zero()

fn can_participate(sender: &T::AccountId) -> bool {
!T::Currency::free_balance(sender).is_zero() && T::IsActiveMember::is_active_member(sender)
}

// PUBLIC IMMUTABLES
Expand Down Expand Up @@ -651,7 +655,7 @@ decl_module! {
// Member can make subsequent calls during announcing stage to increase their stake.
fn apply(origin, stake: BalanceOf<T>) {
let sender = ensure_signed(origin)?;
ensure!(Self::is_member(sender.clone()), "Only members can apply to be on council");
ensure!(Self::can_participate(&sender), "Only members can apply to be on council");

let stage = Self::stage();
ensure!(Self::stage().is_some(), "election not running");
Expand All @@ -674,7 +678,7 @@ decl_module! {

fn vote(origin, commitment: T::Hash, stake: BalanceOf<T>) {
let sender = ensure_signed(origin)?;
ensure!(Self::is_member(sender.clone()), "Only members can vote for an applicant");
ensure!(Self::can_participate(&sender), "Only members can vote for an applicant");

let stage = Self::stage();
ensure!(Self::stage().is_some(), "election not running");
Expand Down
18 changes: 14 additions & 4 deletions src/governance/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use rstd::prelude::*;
pub use super::{election, council, proposals, GovernanceCurrency};
pub use system;
use crate::traits;

pub use primitives::{H256, Blake2Hasher};
pub use runtime_primitives::{
Expand All @@ -17,6 +18,16 @@ impl_outer_origin! {
pub enum Origin for Test {}
}

pub struct AnyAccountIsMember {}
impl<T: system::Trait> traits::IsActiveMember<T> for AnyAccountIsMember {
fn is_active_member(who: &T::AccountId) -> bool {
true
}
}

// default trait implementation - any account is not a member
// impl<T: system::Trait> traits::IsActiveMember<T> for () {}

// For testing the module, we construct most of a mock runtime. This means
// first constructing a configuration type (`Test`) which `impl`s each of the
// configuration traits of modules we want to use.
Expand Down Expand Up @@ -53,10 +64,10 @@ impl election::Trait for Test {
type Event = ();

type CouncilElected = (Council,);

type IsActiveMember = AnyAccountIsMember;
}
impl proposals::Trait for Test {
type Event = ();
}

impl balances::Trait for Test {
type Event = ();

Expand Down Expand Up @@ -92,6 +103,5 @@ pub fn initial_test_ext() -> runtime_io::TestExternalities<Blake2Hasher> {

pub type Election = election::Module<Test>;
pub type Council = council::Module<Test>;
pub type Proposals = proposals::Module<Test>;
pub type System = system::Module<Test>;
pub type Balances = balances::Module<Test>;
18 changes: 14 additions & 4 deletions src/governance/proposals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rstd::prelude::*;

use super::council;
pub use super::{ GovernanceCurrency, BalanceOf };
use crate::traits::{IsActiveMember};

const DEFAULT_APPROVAL_QUORUM: u32 = 60;
const DEFAULT_MIN_STAKE: u64 = 100;
Expand Down Expand Up @@ -115,6 +116,8 @@ pub struct TallyResult<BlockNumber> {
pub trait Trait: timestamp::Trait + council::Trait + GovernanceCurrency {
/// The overarching event type.
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;

type IsActiveMember: IsActiveMember<Self>;
}

decl_event!(
Expand Down Expand Up @@ -221,7 +224,7 @@ decl_module! {
) {

let proposer = ensure_signed(origin)?;
ensure!(Self::is_member(proposer.clone()), MSG_ONLY_MEMBERS_CAN_PROPOSE);
ensure!(Self::can_participate(proposer.clone()), MSG_ONLY_MEMBERS_CAN_PROPOSE);
ensure!(stake >= Self::min_stake(), MSG_STAKE_IS_TOO_LOW);

ensure!(!name.is_empty(), MSG_EMPTY_NAME_PROVIDED);
Expand Down Expand Up @@ -345,9 +348,8 @@ impl<T: Trait> Module<T> {
<system::Module<T>>::block_number()
}

// TODO This method should be moved to Membership module once it's created.
fn is_member(sender: T::AccountId) -> bool {
!T::Currency::free_balance(&sender).is_zero()
fn can_participate(sender: T::AccountId) -> bool {
!T::Currency::free_balance(&sender).is_zero() && T::IsActiveMember::is_active_member(&sender)
}

fn is_councilor(sender: &T::AccountId) -> bool {
Expand Down Expand Up @@ -613,6 +615,14 @@ mod tests {

impl Trait for Test {
type Event = ();
type IsActiveMember = AnyAccountIsMember;
}

pub struct AnyAccountIsMember {}
impl<T: system::Trait> IsActiveMember<T> for AnyAccountIsMember {
fn is_active_member(who: &T::AccountId) -> bool {
true
}
}

type System = system::Module<Test>;
Expand Down
25 changes: 22 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ extern crate parity_codec_derive;
pub mod governance;
use governance::{election, council, proposals};
mod memo;
mod membership;
use membership::members;
mod traits;
mod migration;

use rstd::prelude::*;
#[cfg(feature = "std")]
use primitives::bytes;
use primitives::{Ed25519AuthorityId, OpaqueMetadata};
use runtime_primitives::{
ApplyResult, transaction_validity::TransactionValidity, Ed25519Signature, generic,
traits::{self, Convert, BlakeTwo256, Block as BlockT, StaticLookup}, create_runtime_str
traits::{self as runtime_traits, Convert, BlakeTwo256, Block as BlockT, StaticLookup}, create_runtime_str
};
use client::{
block_builder::api::{CheckInherentsResult, InherentData, self as block_builder_api},
Expand Down Expand Up @@ -67,7 +71,7 @@ pub mod opaque {
#[derive(PartialEq, Eq, Clone, Default, Encode, Decode)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug))]
pub struct UncheckedExtrinsic(#[cfg_attr(feature = "std", serde(with="bytes"))] pub Vec<u8>);
impl traits::Extrinsic for UncheckedExtrinsic {
impl runtime_traits::Extrinsic for UncheckedExtrinsic {
fn is_signed(&self) -> Option<bool> {
None
}
Expand All @@ -87,7 +91,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("joystream-node"),
impl_name: create_runtime_str!("joystream-node"),
authoring_version: 3,
spec_version: 4,
spec_version: 5,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
};
Expand Down Expand Up @@ -208,11 +212,13 @@ impl governance::GovernanceCurrency for Runtime {

impl governance::proposals::Trait for Runtime {
type Event = Event;
type IsActiveMember = Members;
}

impl governance::election::Trait for Runtime {
type Event = Event;
type CouncilElected = (Council,);
type IsActiveMember = Members;
}

impl governance::council::Trait for Runtime {
Expand All @@ -224,6 +230,17 @@ impl memo::Trait for Runtime {
type Event = Event;
}

impl members::Trait for Runtime {
type Event = Event;
type MemberId = u64;
type PaidTermId = u64;
type SubscriptionId = u64;
}

impl migration::Trait for Runtime {
type Event = Event;
}

construct_runtime!(
pub enum Runtime with Log(InternalLog: DigestItem<Hash, Ed25519AuthorityId>) where
Block = Block,
Expand All @@ -244,6 +261,8 @@ construct_runtime!(
CouncilElection: election::{Module, Call, Storage, Event<T>, Config<T>},
Council: council::{Module, Call, Storage, Event<T>, Config<T>},
Memo: memo::{Module, Call, Storage, Event<T>},
Members: members::{Module, Call, Storage, Event<T>, Config<T>},
Migration: migration::{Module, Call, Storage, Event<T>},
}
);

Expand Down
Loading