Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d09cfbc
refactor IsActiveMember trait to Members
mnaamani Mar 22, 2019
af58630
staked roles
mnaamani Mar 22, 2019
d46fc63
update Members and Roles traits
mnaamani Mar 22, 2019
14f7cf5
staked role accounts illiquid
mnaamani Mar 22, 2019
c1a0677
refactored staked roles
mnaamani Mar 22, 2019
e16cef9
admin methods for roles
mnaamani Mar 23, 2019
3896194
staked roles: clear entry requests every N blocks
mnaamani Mar 25, 2019
8e43956
staked roles: add expiery to entry requests
mnaamani Mar 25, 2019
1e35b21
staked roles: admin remove actor function
mnaamani Mar 25, 2019
79ef28c
staked roles: factor out deleting actor
mnaamani Mar 25, 2019
8264345
staked roles: clear unbonded accounts
mnaamani Mar 25, 2019
37d82a4
Merge branch 'membership' into staked-roles
mnaamani Mar 25, 2019
85d1f33
remove unecessary use statement
mnaamani Mar 25, 2019
24aa7fc
Merge branch 'development' into staked-roles
mnaamani Mar 25, 2019
a4b502e
staked role payouts
mnaamani Mar 25, 2019
4ef307e
MaybeDebug needed on trait
mnaamani Mar 26, 2019
cbab82b
staked roles: initialize runtime allowing Storage role
mnaamani Mar 26, 2019
d81f8aa
fix spelling on_finalise, on_initialise
mnaamani Mar 27, 2019
0114658
Merge branch 'development' into staked-roles
mnaamani Mar 27, 2019
f316733
error message when not enough balance to stake
mnaamani Mar 28, 2019
9c9a49a
burn role entry request fee
mnaamani Mar 28, 2019
baffb0b
rename role parameters field bonding_time -> bonding_period
mnaamani Mar 28, 2019
fd30145
renaming storage values
mnaamani Mar 30, 2019
9b11ce5
adding tests for staked roles
mnaamani Apr 1, 2019
18fae5e
pay reward to member account
mnaamani Apr 1, 2019
c7940af
tests: staked roles
mnaamani Apr 1, 2019
6c5deff
add EntryRequested and Unstaked events
mnaamani Apr 1, 2019
75bcdb5
rustfmt
mnaamani Apr 2, 2019
22fffb7
fix warnings in roles module
mnaamani Apr 2, 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
6 changes: 3 additions & 3 deletions src/governance/election.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ use super::sealed_vote::SealedVote;
pub use super::{ GovernanceCurrency, BalanceOf };
use super::council;

use crate::traits::{IsActiveMember};
use crate::traits::{Members};

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>;
type Members: Members<Self>;
}

#[derive(Clone, Copy, Encode, Decode)]
Expand Down Expand Up @@ -154,7 +154,7 @@ impl<T: Trait> Module<T> {


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

// PUBLIC IMMUTABLES
Expand Down
21 changes: 14 additions & 7 deletions src/governance/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use rstd::prelude::*;
pub use super::{election, council, proposals, GovernanceCurrency};
pub use system;
use crate::traits;
use crate::traits::{Members};

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

pub struct AnyAccountIsMember {}
impl<T: system::Trait> traits::IsActiveMember<T> for AnyAccountIsMember {
pub struct MockMembership {}
impl<T: system::Trait> Members<T> for MockMembership {
type Id = u32;
fn is_active_member(who: &T::AccountId) -> bool {
// all accounts are considered members.
// There is currently no test coverage for non-members.
// Should add some coverage, and update this method to reflect which accounts are or are not members
true
}
fn lookup_member_id(account_id: &T::AccountId) -> Result<Self::Id, &'static str> {
Err("not implemented!")
}
fn lookup_account_by_member_id(id: Self::Id) -> Result<T::AccountId, &'static str> {
Err("not implemented!")
}
}

// 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 @@ -65,7 +72,7 @@ impl election::Trait for Test {

type CouncilElected = (Council,);

type IsActiveMember = AnyAccountIsMember;
type Members = MockMembership;
}

impl balances::Trait for Test {
Expand Down
42 changes: 26 additions & 16 deletions src/governance/proposals.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use srml_support::{StorageValue, StorageMap, dispatch::Result, decl_module, decl_event, decl_storage, ensure};
use srml_support::{StorageValue, StorageMap, dispatch, decl_module, decl_event, decl_storage, ensure};
use srml_support::traits::{Currency};
use primitives::{storage::well_known_keys};
use runtime_primitives::traits::{As, Hash, Zero};
Expand All @@ -8,7 +8,7 @@ use rstd::prelude::*;

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

const DEFAULT_APPROVAL_QUORUM: u32 = 60;
const DEFAULT_MIN_STAKE: u64 = 100;
Expand Down Expand Up @@ -117,7 +117,7 @@ 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>;
type Members: Members<Self>;
}

decl_event!(
Expand Down Expand Up @@ -349,7 +349,7 @@ impl<T: Trait> Module<T> {
}

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

fn is_councilor(sender: &T::AccountId) -> bool {
Expand All @@ -368,7 +368,7 @@ impl<T: Trait> Module<T> {
Self::current_block() >= proposed_at + Self::voting_period()
}

fn _process_vote(voter: T::AccountId, proposal_id: u32, vote: VoteKind) -> Result {
fn _process_vote(voter: T::AccountId, proposal_id: u32, vote: VoteKind) -> dispatch::Result {
let new_vote = (voter.clone(), vote.clone());
if <VotesByProposal<T>>::exists(proposal_id) {
// Append a new vote to other votes on this proposal:
Expand All @@ -382,7 +382,7 @@ impl<T: Trait> Module<T> {
Ok(())
}

fn end_block(now: T::BlockNumber) -> Result {
fn end_block(now: T::BlockNumber) -> dispatch::Result {

// TODO refactor this method

Expand All @@ -395,7 +395,7 @@ impl<T: Trait> Module<T> {
}

/// Get the voters for the current proposal.
pub fn tally(/* proposal_id: u32 */) -> Result {
pub fn tally(/* proposal_id: u32 */) -> dispatch::Result {

let councilors: u32 = Self::councilors_count();
let quorum: u32 = Self::approval_quorum_seats();
Expand Down Expand Up @@ -475,7 +475,7 @@ impl<T: Trait> Module<T> {
}

/// Updates proposal status and removes proposal from active ids.
fn _update_proposal_status(proposal_id: u32, new_status: ProposalStatus) -> Result {
fn _update_proposal_status(proposal_id: u32, new_status: ProposalStatus) -> dispatch::Result {
let all_active_ids = Self::active_proposal_ids();
let all_len = all_active_ids.len();
let other_active_ids: Vec<u32> = all_active_ids
Expand Down Expand Up @@ -503,7 +503,7 @@ impl<T: Trait> Module<T> {
}

/// Slash a proposal. The staked deposit will be slashed.
fn _slash_proposal(proposal_id: u32) -> Result {
fn _slash_proposal(proposal_id: u32) -> dispatch::Result {
let proposal = Self::proposals(proposal_id);

// Slash proposer's stake:
Expand All @@ -513,7 +513,7 @@ impl<T: Trait> Module<T> {
}

/// Reject a proposal. The staked deposit will be returned to a proposer.
fn _reject_proposal(proposal_id: u32) -> Result {
fn _reject_proposal(proposal_id: u32) -> dispatch::Result {
let proposal = Self::proposals(proposal_id);
let proposer = proposal.proposer;

Expand All @@ -529,7 +529,7 @@ impl<T: Trait> Module<T> {
}

/// Approve a proposal. The staked deposit will be returned.
fn _approve_proposal(proposal_id: u32) -> Result {
fn _approve_proposal(proposal_id: u32) -> dispatch::Result {
let proposal = Self::proposals(proposal_id);
let wasm_code = Self::wasm_code_by_hash(proposal.wasm_hash);

Expand Down Expand Up @@ -615,14 +615,24 @@ mod tests {

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

pub struct AnyAccountIsMember {}
impl<T: system::Trait> IsActiveMember<T> for AnyAccountIsMember {
pub struct MockMembership {}
impl<T: system::Trait> Members<T> for MockMembership {
type Id = u32;
fn is_active_member(who: &T::AccountId) -> bool {
// all accounts are considered members.
// There is currently no test coverage for non-members.
// Should add some coverage, and update this method to reflect which accounts are or are not members
true
}
fn lookup_member_id(account_id: &T::AccountId) -> Result<Self::Id, &'static str> {
Err("not implemented!")
}
fn lookup_account_by_member_id(id: Self::Id) -> Result<T::AccountId, &'static str> {
Err("not implemented!")
}
}

type System = system::Module<Test>;
Expand Down Expand Up @@ -716,7 +726,7 @@ mod tests {
b"Proposal Wasm Code".to_vec()
}

fn _create_default_proposal() -> Result {
fn _create_default_proposal() -> dispatch::Result {
_create_proposal(None, None, None, None, None)
}

Expand All @@ -726,7 +736,7 @@ mod tests {
name: Option<Vec<u8>>,
description: Option<Vec<u8>>,
wasm_code: Option<Vec<u8>>
) -> Result {
) -> dispatch::Result {
Proposals::create_proposal(
Origin::signed(origin.unwrap_or(PROPOSER1)),
stake.unwrap_or(min_stake()),
Expand Down
15 changes: 12 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ mod traits;
mod membership;
use membership::members;
mod migration;
mod roles;
use roles::actors;

use rstd::prelude::*;
#[cfg(feature = "std")]
Expand Down Expand Up @@ -186,7 +188,7 @@ impl balances::Trait for Runtime {
/// What to do if a new account is created.
type OnNewAccount = Indices;
/// Restrict whether an account can transfer funds. We don't place any further restrictions.
type EnsureAccountLiquid = Staking;
type EnsureAccountLiquid = (Staking, Actors);
/// The uniquitous event type.
type Event = Event;
}
Expand Down Expand Up @@ -214,13 +216,13 @@ impl governance::GovernanceCurrency for Runtime {

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

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

impl governance::council::Trait for Runtime {
Expand All @@ -242,12 +244,18 @@ impl members::Trait for Runtime {
type MemberId = u64;
type PaidTermId = u64;
type SubscriptionId = u64;
type Roles = Actors;
}

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

impl actors::Trait for Runtime {
type Event = Event;
type Members = Members;
}

construct_runtime!(
pub enum Runtime with Log(InternalLog: DigestItem<Hash, Ed25519AuthorityId>) where
Block = Block,
Expand All @@ -270,6 +278,7 @@ construct_runtime!(
Memo: memo::{Module, Call, Storage, Event<T>},
Members: members::{Module, Call, Storage, Event<T>, Config<T>},
Migration: migration::{Module, Call, Storage, Event<T>},
Actors: actors::{Module, Call, Storage, Event<T>},
DataObjectTypeRegistry: data_object_type_registry::{Module, Call, Storage, Event<T>, Config<T>},
}
);
Expand Down
28 changes: 25 additions & 3 deletions src/membership/members.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use runtime_primitives::traits::{Zero, SimpleArithmetic, As, Member, MaybeSerial
use system::{self, ensure_signed};
use crate::governance::{GovernanceCurrency, BalanceOf };
use {timestamp};
use crate::traits;
use crate::traits::{Members, Roles};

pub trait Trait: system::Trait + GovernanceCurrency + timestamp::Trait {
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
Expand All @@ -22,6 +22,8 @@ pub trait Trait: system::Trait + GovernanceCurrency + timestamp::Trait {

type SubscriptionId: Parameter + Member + SimpleArithmetic + Codec + Default + Copy
+ As<usize> + As<u64> + MaybeSerializeDebug + PartialEq;

type Roles: Roles<Self>;
}

const DEFAULT_FIRST_MEMBER_ID: u64 = 1;
Expand Down Expand Up @@ -173,7 +175,9 @@ impl<T: Trait> Module<T> {
}
}

impl<T: Trait> traits::IsActiveMember<T> for Module<T> {
impl<T: Trait> Members<T> for Module<T> {
type Id = T::MemberId;

fn is_active_member(who: &T::AccountId) -> bool {
match Self::ensure_is_member(who)
.and_then(|member_id| Self::ensure_profile(member_id))
Expand All @@ -182,6 +186,18 @@ impl<T: Trait> traits::IsActiveMember<T> for Module<T> {
Err(err) => false
}
}

fn lookup_member_id(who: &T::AccountId) -> Result<Self::Id, &'static str> {
Self::ensure_is_member(who)
}

fn lookup_account_by_member_id(id: Self::Id) -> Result<T::AccountId, &'static str> {
if <AccountIdByMemberId<T>>::exists(&id) {
Ok(Self::account_id_by_member_id(&id))
} else {
Err("member id doesn't exist")
}
}
}

decl_module! {
Expand All @@ -198,6 +214,9 @@ decl_module! {
// ensure key not associated with an existing membership
Self::ensure_not_member(&who)?;

// ensure account is not in a bonded role
ensure!(!T::Roles::is_role_account(&who), "role key cannot be used for membership");

// ensure paid_terms_id is active
let terms = Self::ensure_active_terms_id(paid_terms_id)?;

Expand Down Expand Up @@ -270,6 +289,9 @@ decl_module! {
// ensure key not associated with an existing membership
Self::ensure_not_member(&new_member)?;

// ensure account is not in a bonded role
ensure!(!T::Roles::is_role_account(&new_member), "role key cannot be used for membership");

let user_info = Self::check_user_registration_info(user_info)?;

// ensure handle is not already registered
Expand All @@ -292,7 +314,7 @@ impl<T: Trait> Module<T> {
Ok(())
}

fn ensure_is_member(who: &T::AccountId) -> Result<T::MemberId, &'static str> {
pub fn ensure_is_member(who: &T::AccountId) -> Result<T::MemberId, &'static str> {
let member_id = Self::member_id_by_account_id(who).ok_or("no member id found for accountid")?;
Ok(member_id)
}
Expand Down
1 change: 1 addition & 0 deletions src/membership/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ impl members::Trait for Test {
type MemberId = u32;
type PaidTermId = u32;
type SubscriptionId = u32;
type Roles = ();
}

pub struct ExtBuilder {
Expand Down
Loading