|
@@ -19,23 +19,15 @@ pub mod genesis;
|
|
#[cfg(feature = "std")]
|
|
#[cfg(feature = "std")]
|
|
use serde::{Deserialize, Serialize};
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
-use codec::{Decode, Encode}; // Codec
|
|
|
|
- //use rstd::collections::btree_map::BTreeMap;
|
|
|
|
-use membership::{members, role_types};
|
|
|
|
|
|
+use codec::{Decode, Encode};
|
|
use rstd::borrow::ToOwned;
|
|
use rstd::borrow::ToOwned;
|
|
use rstd::collections::btree_map::BTreeMap;
|
|
use rstd::collections::btree_map::BTreeMap;
|
|
use rstd::collections::btree_set::BTreeSet;
|
|
use rstd::collections::btree_set::BTreeSet;
|
|
use rstd::convert::From;
|
|
use rstd::convert::From;
|
|
use rstd::prelude::*;
|
|
use rstd::prelude::*;
|
|
-use sr_primitives::traits::{One, Zero}; // Member, SimpleArithmetic, MaybeSerialize
|
|
|
|
|
|
+use sr_primitives::traits::{One, Zero};
|
|
use srml_support::traits::{Currency, ExistenceRequirement, WithdrawReasons};
|
|
use srml_support::traits::{Currency, ExistenceRequirement, WithdrawReasons};
|
|
-use srml_support::{
|
|
|
|
- decl_event,
|
|
|
|
- decl_module,
|
|
|
|
- decl_storage,
|
|
|
|
- dispatch, // , StorageMap, , Parameter
|
|
|
|
- ensure,
|
|
|
|
-};
|
|
|
|
|
|
+use srml_support::{decl_event, decl_module, decl_storage, dispatch, ensure};
|
|
use system::{self, ensure_root, ensure_signed};
|
|
use system::{self, ensure_root, ensure_signed};
|
|
|
|
|
|
use common::constraints::InputValidationLengthConstraint;
|
|
use common::constraints::InputValidationLengthConstraint;
|
|
@@ -48,7 +40,7 @@ pub trait Trait:
|
|
+ stake::Trait
|
|
+ stake::Trait
|
|
+ hiring::Trait
|
|
+ hiring::Trait
|
|
+ versioned_store_permissions::Trait
|
|
+ versioned_store_permissions::Trait
|
|
- + members::Trait
|
|
|
|
|
|
+ + membership::Trait
|
|
{
|
|
{
|
|
// + Sized
|
|
// + Sized
|
|
|
|
|
|
@@ -56,19 +48,19 @@ pub trait Trait:
|
|
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
|
|
type Event: From<Event<Self>> + Into<<Self as system::Trait>::Event>;
|
|
}
|
|
}
|
|
|
|
|
|
-/// Type constraint for identifer used for actors in members module in this runtime.
|
|
|
|
-pub type ActorIdInMembersModule<T> = <T as members::Trait>::ActorId;
|
|
|
|
|
|
+/// Type constraint for identifer used for actors.
|
|
|
|
+pub type ActorId<T> = <T as membership::Trait>::ActorId;
|
|
|
|
|
|
/// Type for identifier for channels.
|
|
/// Type for identifier for channels.
|
|
/// The ChannelId must be capable of behaving like an actor id for membership module,
|
|
/// The ChannelId must be capable of behaving like an actor id for membership module,
|
|
/// since publishers are identified by their channel id.
|
|
/// since publishers are identified by their channel id.
|
|
-pub type ChannelId<T> = ActorIdInMembersModule<T>;
|
|
|
|
|
|
+pub type ChannelId<T> = ActorId<T>;
|
|
|
|
|
|
/// Type identifier for lead role, which must be same as membership actor identifeir
|
|
/// Type identifier for lead role, which must be same as membership actor identifeir
|
|
-pub type LeadId<T> = ActorIdInMembersModule<T>;
|
|
|
|
|
|
+pub type LeadId<T> = ActorId<T>;
|
|
|
|
|
|
/// Type identifier for curator role, which must be same as membership actor identifeir
|
|
/// Type identifier for curator role, which must be same as membership actor identifeir
|
|
-pub type CuratorId<T> = ActorIdInMembersModule<T>;
|
|
|
|
|
|
+pub type CuratorId<T> = ActorId<T>;
|
|
|
|
|
|
/// Type for the identifer for an opening for a curator.
|
|
/// Type for the identifer for an opening for a curator.
|
|
pub type CuratorOpeningId<T> = <T as hiring::Trait>::OpeningId;
|
|
pub type CuratorOpeningId<T> = <T as hiring::Trait>::OpeningId;
|
|
@@ -232,9 +224,8 @@ pub static MSG_ADD_CURATOR_OPENING_ZERO_MAX_APPLICANT_COUNT: &str =
|
|
|
|
|
|
// Errors for `apply_on_curator_opening`
|
|
// Errors for `apply_on_curator_opening`
|
|
pub static MSG_APPLY_ON_CURATOR_OPENING_UNSIGNED_ORIGIN: &str = "Unsigned origin";
|
|
pub static MSG_APPLY_ON_CURATOR_OPENING_UNSIGNED_ORIGIN: &str = "Unsigned origin";
|
|
-pub static MSG_APPLY_ON_CURATOR_OPENING_MEMBER_ID_INVALID: &str = "Member id is invalid";
|
|
|
|
-pub static MSG_APPLY_ON_CURATOR_OPENING_SIGNER_NOT_CONTROLLER_ACCOUNT: &str =
|
|
|
|
- "Signer does not match controller account";
|
|
|
|
|
|
+pub static MSG_MEMBER_ID_INVALID: &str = "Member id is invalid";
|
|
|
|
+pub static MSG_SIGNER_NOT_CONTROLLER_ACCOUNT: &str = "Signer does not match controller account";
|
|
pub static MSG_ORIGIN_IS_NIETHER_MEMBER_CONTROLLER_OR_ROOT: &str =
|
|
pub static MSG_ORIGIN_IS_NIETHER_MEMBER_CONTROLLER_OR_ROOT: &str =
|
|
"Origin must be controller or root account of member";
|
|
"Origin must be controller or root account of member";
|
|
pub static MSG_MEMBER_HAS_ACTIVE_APPLICATION_ON_OPENING: &str =
|
|
pub static MSG_MEMBER_HAS_ACTIVE_APPLICATION_ON_OPENING: &str =
|
|
@@ -276,7 +267,10 @@ impl<BlockNumber> Default for LeadRoleState<BlockNumber> {
|
|
/// hence information about this is missing. Recurring rewards is included, somewhat arbitrarily!
|
|
/// hence information about this is missing. Recurring rewards is included, somewhat arbitrarily!
|
|
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
|
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
|
|
#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
|
|
#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
|
|
-pub struct Lead<AccountId, RewardRelationshipId, BlockNumber> {
|
|
|
|
|
|
+pub struct Lead<AccountId, RewardRelationshipId, BlockNumber, MemberId> {
|
|
|
|
+ /// Leader member id,
|
|
|
|
+ pub member_id: MemberId,
|
|
|
|
+
|
|
/// Account used to authenticate in this role,
|
|
/// Account used to authenticate in this role,
|
|
pub role_account: AccountId,
|
|
pub role_account: AccountId,
|
|
|
|
|
|
@@ -438,9 +432,6 @@ pub struct Curator<
|
|
/// How the curator was inducted into the working group.
|
|
/// How the curator was inducted into the working group.
|
|
pub induction: CuratorInduction<LeadId, CuratorApplicationId, BlockNumber>,
|
|
pub induction: CuratorInduction<LeadId, CuratorApplicationId, BlockNumber>,
|
|
|
|
|
|
- /// Whether this curator can unilaterally alter the curation status of a channel.
|
|
|
|
- //pub can_update_channel_curation_status: bool,
|
|
|
|
-
|
|
|
|
/// Permissions module principal id
|
|
/// Permissions module principal id
|
|
pub principal_id: PrincipalId,
|
|
pub principal_id: PrincipalId,
|
|
}
|
|
}
|
|
@@ -774,27 +765,6 @@ impl<LeadId: Default, CuratorId> Default for WorkingGroupUnstaker<LeadId, Curato
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-/*
|
|
|
|
-/// ...
|
|
|
|
-#[derive(Encode, Decode, Debug, Eq, PartialEq, Clone, PartialOrd, Ord)]
|
|
|
|
-pub struct OpeningHire<CuratorApplicationId, CuratorId, PrincipalId> {
|
|
|
|
- curator_application_id: CuratorApplicationId,
|
|
|
|
- curator_id: CuratorId,
|
|
|
|
- principal_id: PrincipalId
|
|
|
|
-}
|
|
|
|
-*/
|
|
|
|
-
|
|
|
|
-/*
|
|
|
|
-pub enum ChannelActor<T: Trait> {
|
|
|
|
-
|
|
|
|
- ///
|
|
|
|
- WorkingGroupActor(WorkingGroupActor<T>),
|
|
|
|
-
|
|
|
|
- ///
|
|
|
|
- Owner
|
|
|
|
-}
|
|
|
|
-*/
|
|
|
|
-
|
|
|
|
// ======================================================================== //
|
|
// ======================================================================== //
|
|
// Move section below, this out in its own file later //
|
|
// Move section below, this out in its own file later //
|
|
// ======================================================================== //
|
|
// ======================================================================== //
|
|
@@ -936,13 +906,13 @@ impl rstd::convert::From<WrappedError<hiring::DeactivateApplicationError>> for &
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-impl rstd::convert::From<WrappedError<members::ControllerAccountForMemberCheckFailed>> for &str {
|
|
|
|
- fn from(wrapper: WrappedError<members::ControllerAccountForMemberCheckFailed>) -> Self {
|
|
|
|
|
|
+impl rstd::convert::From<WrappedError<membership::ControllerAccountForMemberCheckFailed>> for &str {
|
|
|
|
+ fn from(wrapper: WrappedError<membership::ControllerAccountForMemberCheckFailed>) -> Self {
|
|
match wrapper.error {
|
|
match wrapper.error {
|
|
- members::ControllerAccountForMemberCheckFailed::NotMember => {
|
|
|
|
|
|
+ membership::ControllerAccountForMemberCheckFailed::NotMember => {
|
|
MSG_CREATE_CHANNEL_IS_NOT_MEMBER
|
|
MSG_CREATE_CHANNEL_IS_NOT_MEMBER
|
|
}
|
|
}
|
|
- members::ControllerAccountForMemberCheckFailed::NotControllerAccount => {
|
|
|
|
|
|
+ membership::ControllerAccountForMemberCheckFailed::NotControllerAccount => {
|
|
MSG_CREATE_CHANNEL_NOT_CONTROLLER_ACCOUNT
|
|
MSG_CREATE_CHANNEL_NOT_CONTROLLER_ACCOUNT
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -974,17 +944,15 @@ impl rstd::convert::From<WrappedError<hiring::AddApplicationError>> for &str {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-impl rstd::convert::From<WrappedError<members::MemberControllerAccountDidNotSign>> for &str {
|
|
|
|
- fn from(wrapper: WrappedError<members::MemberControllerAccountDidNotSign>) -> Self {
|
|
|
|
|
|
+impl rstd::convert::From<WrappedError<membership::MemberControllerAccountDidNotSign>> for &str {
|
|
|
|
+ fn from(wrapper: WrappedError<membership::MemberControllerAccountDidNotSign>) -> Self {
|
|
match wrapper.error {
|
|
match wrapper.error {
|
|
- members::MemberControllerAccountDidNotSign::UnsignedOrigin => {
|
|
|
|
|
|
+ membership::MemberControllerAccountDidNotSign::UnsignedOrigin => {
|
|
MSG_APPLY_ON_CURATOR_OPENING_UNSIGNED_ORIGIN
|
|
MSG_APPLY_ON_CURATOR_OPENING_UNSIGNED_ORIGIN
|
|
}
|
|
}
|
|
- members::MemberControllerAccountDidNotSign::MemberIdInvalid => {
|
|
|
|
- MSG_APPLY_ON_CURATOR_OPENING_MEMBER_ID_INVALID
|
|
|
|
- }
|
|
|
|
- members::MemberControllerAccountDidNotSign::SignerControllerAccountMismatch => {
|
|
|
|
- MSG_APPLY_ON_CURATOR_OPENING_SIGNER_NOT_CONTROLLER_ACCOUNT
|
|
|
|
|
|
+ membership::MemberControllerAccountDidNotSign::MemberIdInvalid => MSG_MEMBER_ID_INVALID,
|
|
|
|
+ membership::MemberControllerAccountDidNotSign::SignerControllerAccountMismatch => {
|
|
|
|
+ MSG_SIGNER_NOT_CONTROLLER_ACCOUNT
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1012,7 +980,7 @@ decl_storage! {
|
|
pub CurrentLeadId get(current_lead_id) : Option<LeadId<T>>;
|
|
pub CurrentLeadId get(current_lead_id) : Option<LeadId<T>>;
|
|
|
|
|
|
/// Maps identifier to corresponding lead.
|
|
/// Maps identifier to corresponding lead.
|
|
- pub LeadById get(lead_by_id): 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, T::MemberId>;
|
|
|
|
|
|
/// Next identifier for new current lead.
|
|
/// Next identifier for new current lead.
|
|
pub NextLeadId get(next_lead_id): LeadId<T>;
|
|
pub NextLeadId get(next_lead_id): LeadId<T>;
|
|
@@ -1145,13 +1113,12 @@ decl_module! {
|
|
banner: OptionalText,
|
|
banner: OptionalText,
|
|
publication_status: ChannelPublicationStatus
|
|
publication_status: ChannelPublicationStatus
|
|
) {
|
|
) {
|
|
-
|
|
|
|
- // Ensure that it is signed
|
|
|
|
- let signer_account = ensure_signed(origin)?;
|
|
|
|
-
|
|
|
|
- // Ensure that owner member can authenticate with signer account
|
|
|
|
|
|
+ // Ensure that owner member is signed and can authenticate with signer account
|
|
ensure_on_wrapped_error!(
|
|
ensure_on_wrapped_error!(
|
|
- members::Module::<T>::ensure_is_controller_account_for_member(&owner, &signer_account)
|
|
|
|
|
|
+ membership::Module::<T>::ensure_member_controller_account_signed(
|
|
|
|
+ origin,
|
|
|
|
+ &owner
|
|
|
|
+ )
|
|
)?;
|
|
)?;
|
|
|
|
|
|
// Ensure it is currently possible to create channels (ChannelCreationEnabled).
|
|
// Ensure it is currently possible to create channels (ChannelCreationEnabled).
|
|
@@ -1160,9 +1127,6 @@ decl_module! {
|
|
MSG_CHANNEL_CREATION_DISABLED
|
|
MSG_CHANNEL_CREATION_DISABLED
|
|
);
|
|
);
|
|
|
|
|
|
- // Ensure prospective owner member is currently allowed to become channel owner
|
|
|
|
- let (member_in_role, next_channel_id) = Self::ensure_can_register_channel_owner_role_on_member(&owner, None)?;
|
|
|
|
-
|
|
|
|
// Ensure channel handle is acceptable length
|
|
// Ensure channel handle is acceptable length
|
|
Self::ensure_channel_handle_is_valid(&handle)?;
|
|
Self::ensure_channel_handle_is_valid(&handle)?;
|
|
|
|
|
|
@@ -1183,6 +1147,7 @@ decl_module! {
|
|
//
|
|
//
|
|
|
|
|
|
// Make and add new principal
|
|
// Make and add new principal
|
|
|
|
+ let next_channel_id = NextChannelId::<T>::get();
|
|
let principal_id = Self::add_new_principal(&Principal::ChannelOwner(next_channel_id));
|
|
let principal_id = Self::add_new_principal(&Principal::ChannelOwner(next_channel_id));
|
|
|
|
|
|
// Construct channel
|
|
// Construct channel
|
|
@@ -1213,14 +1178,8 @@ decl_module! {
|
|
|
|
|
|
// CREDENTIAL STUFF //
|
|
// CREDENTIAL STUFF //
|
|
|
|
|
|
- // Dial out to membership module and inform about new role as channe owner.
|
|
|
|
- let registered_role = <members::Module<T>>::register_role_on_member(owner, &member_in_role).is_ok();
|
|
|
|
-
|
|
|
|
- assert!(registered_role);
|
|
|
|
-
|
|
|
|
// Trigger event
|
|
// Trigger event
|
|
Self::deposit_event(RawEvent::ChannelCreated(next_channel_id));
|
|
Self::deposit_event(RawEvent::ChannelCreated(next_channel_id));
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/// An owner transfers channel ownership to a new owner.
|
|
/// An owner transfers channel ownership to a new owner.
|
|
@@ -1233,13 +1192,6 @@ decl_module! {
|
|
// Ensure channel owner has signed
|
|
// Ensure channel owner has signed
|
|
let channel = Self::ensure_channel_owner_signed(origin, &channel_id)?;
|
|
let channel = Self::ensure_channel_owner_signed(origin, &channel_id)?;
|
|
|
|
|
|
- // Ensure prospective new owner can actually become a channel owner (with a new channel id)
|
|
|
|
- // We do not pass the existing channel id because it is already owned and the call would
|
|
|
|
- // return with Err, since the membership system doesn't allow the same ActorInRole to be assigned
|
|
|
|
- // to more than one member, and we don't use the returned actor_in_role because its not
|
|
|
|
- // for the channel being transferred.
|
|
|
|
- Self::ensure_can_register_channel_owner_role_on_member(&new_owner, None)?;
|
|
|
|
-
|
|
|
|
//
|
|
//
|
|
// == MUTATION SAFE ==
|
|
// == MUTATION SAFE ==
|
|
//
|
|
//
|
|
@@ -1254,26 +1206,6 @@ decl_module! {
|
|
// Overwrite entry in ChannelById
|
|
// Overwrite entry in ChannelById
|
|
ChannelById::<T>::insert(channel_id, new_channel);
|
|
ChannelById::<T>::insert(channel_id, new_channel);
|
|
|
|
|
|
- let role = role_types::ActorInRole::new(
|
|
|
|
- role_types::Role::ChannelOwner,
|
|
|
|
- channel_id
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- // Remove
|
|
|
|
- let unregistered_role = <members::Module<T>>::unregister_role(
|
|
|
|
- role
|
|
|
|
- ).is_ok();
|
|
|
|
-
|
|
|
|
- assert!(unregistered_role);
|
|
|
|
-
|
|
|
|
- // Dial out to membership module and inform about new role as channel owner.
|
|
|
|
- let registered_role = <members::Module<T>>::register_role_on_member(
|
|
|
|
- new_owner,
|
|
|
|
- &role
|
|
|
|
- ).is_ok();
|
|
|
|
-
|
|
|
|
- assert!(registered_role);
|
|
|
|
-
|
|
|
|
// Trigger event
|
|
// Trigger event
|
|
Self::deposit_event(RawEvent::ChannelOwnershipTransferred(channel_id));
|
|
Self::deposit_event(RawEvent::ChannelOwnershipTransferred(channel_id));
|
|
}
|
|
}
|
|
@@ -1520,18 +1452,6 @@ decl_module! {
|
|
.map(|(successful_curator_application, _, _)| successful_curator_application.application_id)
|
|
.map(|(successful_curator_application, _, _)| successful_curator_application.application_id)
|
|
.collect::<BTreeSet<_>>();
|
|
.collect::<BTreeSet<_>>();
|
|
|
|
|
|
- // Ensure all applications are from members that _still_ can step into the given role
|
|
|
|
- let num_successful_applications_that_can_register_as_curator = successful_iter
|
|
|
|
- .clone()
|
|
|
|
- .map(|(successful_curator_application, _, _)| successful_curator_application.member_id)
|
|
|
|
- .filter_map(|successful_member_id| Self::ensure_can_register_curator_role_on_member(&successful_member_id).ok() )
|
|
|
|
- .count();
|
|
|
|
-
|
|
|
|
- ensure!(
|
|
|
|
- num_successful_applications_that_can_register_as_curator == num_provided_successful_curator_application_ids,
|
|
|
|
- MSG_MEMBER_NO_LONGER_REGISTRABLE_AS_CURATOR
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
// NB: Combined ensure check and mutation in hiring module
|
|
// NB: Combined ensure check and mutation in hiring module
|
|
ensure_on_wrapped_error!(
|
|
ensure_on_wrapped_error!(
|
|
hiring::Module::<T>::fill_opening(
|
|
hiring::Module::<T>::fill_opening(
|
|
@@ -1566,10 +1486,10 @@ decl_module! {
|
|
let recipient = <recurringrewards::Module<T>>::add_recipient();
|
|
let recipient = <recurringrewards::Module<T>>::add_recipient();
|
|
|
|
|
|
// member must exist, since it was checked that it can enter the role
|
|
// member must exist, since it was checked that it can enter the role
|
|
- let member_profile = <members::Module<T>>::member_profile(successful_curator_application.member_id).unwrap();
|
|
|
|
|
|
+ let membership = <membership::Module<T>>::membership(successful_curator_application.member_id);
|
|
|
|
|
|
// rewards are deposited in the member's root account
|
|
// rewards are deposited in the member's root account
|
|
- let reward_destination_account = member_profile.root_account;
|
|
|
|
|
|
+ let reward_destination_account = membership.root_account;
|
|
|
|
|
|
// values have been checked so this should not fail!
|
|
// values have been checked so this should not fail!
|
|
let relationship_id = <recurringrewards::Module<T>>::add_reward_relationship(
|
|
let relationship_id = <recurringrewards::Module<T>>::add_reward_relationship(
|
|
@@ -1624,14 +1544,6 @@ decl_module! {
|
|
// Store curator
|
|
// Store curator
|
|
CuratorById::<T>::insert(new_curator_id, curator);
|
|
CuratorById::<T>::insert(new_curator_id, curator);
|
|
|
|
|
|
- // Register role on member
|
|
|
|
- let registered_role = members::Module::<T>::register_role_on_member(
|
|
|
|
- successful_curator_application.member_id,
|
|
|
|
- &role_types::ActorInRole::new(role_types::Role::Curator, new_curator_id)
|
|
|
|
- ).is_ok();
|
|
|
|
-
|
|
|
|
- assert!(registered_role);
|
|
|
|
-
|
|
|
|
// Update next curator id
|
|
// Update next curator id
|
|
NextCuratorId::<T>::mutate(|id| *id += <CuratorId<T> as One>::one());
|
|
NextCuratorId::<T>::mutate(|id| *id += <CuratorId<T> as One>::one());
|
|
|
|
|
|
@@ -1643,20 +1555,6 @@ decl_module! {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- /*
|
|
|
|
- /// ...
|
|
|
|
- pub fn update_curator_reward(_origin) {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
- /*
|
|
|
|
- /// ...
|
|
|
|
- pub fn slash_curator(_origin) {
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
pub fn withdraw_curator_application(
|
|
pub fn withdraw_curator_application(
|
|
origin,
|
|
origin,
|
|
curator_application_id: CuratorApplicationId<T>
|
|
curator_application_id: CuratorApplicationId<T>
|
|
@@ -1740,17 +1638,14 @@ decl_module! {
|
|
// and cannot specify another arbitrary account as the source account.
|
|
// and cannot specify another arbitrary account as the source account.
|
|
// Ensure the source_account is either the controller or root account of member with given id
|
|
// Ensure the source_account is either the controller or root account of member with given id
|
|
ensure!(
|
|
ensure!(
|
|
- members::Module::<T>::ensure_member_controller_account(&source_account, &member_id).is_ok() ||
|
|
|
|
- members::Module::<T>::ensure_member_root_account(&source_account, &member_id).is_ok(),
|
|
|
|
|
|
+ membership::Module::<T>::ensure_member_controller_account(&source_account, &member_id).is_ok() ||
|
|
|
|
+ membership::Module::<T>::ensure_member_root_account(&source_account, &member_id).is_ok(),
|
|
MSG_ORIGIN_IS_NIETHER_MEMBER_CONTROLLER_OR_ROOT
|
|
MSG_ORIGIN_IS_NIETHER_MEMBER_CONTROLLER_OR_ROOT
|
|
);
|
|
);
|
|
|
|
|
|
// Ensure curator opening exists
|
|
// Ensure curator opening exists
|
|
let (curator_opening, _opening) = Self::ensure_curator_opening_exists(&curator_opening_id)?;
|
|
let (curator_opening, _opening) = Self::ensure_curator_opening_exists(&curator_opening_id)?;
|
|
|
|
|
|
- // Ensure new owner can actually become a curator
|
|
|
|
- let (_member_as_curator, _new_curator_id) = Self::ensure_can_register_curator_role_on_member(&member_id)?;
|
|
|
|
-
|
|
|
|
// Ensure that there is sufficient balance to cover stake proposed
|
|
// Ensure that there is sufficient balance to cover stake proposed
|
|
Self::ensure_can_make_stake_imbalance(
|
|
Self::ensure_can_make_stake_imbalance(
|
|
vec![&opt_role_stake_balance, &opt_application_stake_balance],
|
|
vec![&opt_role_stake_balance, &opt_application_stake_balance],
|
|
@@ -1822,16 +1717,9 @@ decl_module! {
|
|
) {
|
|
) {
|
|
// Ensure that origin is signed by member with given id.
|
|
// Ensure that origin is signed by member with given id.
|
|
ensure_on_wrapped_error!(
|
|
ensure_on_wrapped_error!(
|
|
- members::Module::<T>::ensure_member_controller_account_signed(origin, &member_id)
|
|
|
|
|
|
+ membership::Module::<T>::ensure_member_controller_account_signed(origin, &member_id)
|
|
)?;
|
|
)?;
|
|
|
|
|
|
- // Ensure that member is this curator
|
|
|
|
- let actor_in_role = role_types::ActorInRole::new(role_types::Role::Curator, curator_id);
|
|
|
|
-
|
|
|
|
- ensure!(
|
|
|
|
- members::MembershipIdByActorInRole::<T>::get(actor_in_role) == member_id,
|
|
|
|
- MSG_CURATOR_NOT_CONTROLLED_BY_MEMBER
|
|
|
|
- );
|
|
|
|
|
|
|
|
//
|
|
//
|
|
// == MUTATION SAFE ==
|
|
// == MUTATION SAFE ==
|
|
@@ -2071,18 +1959,13 @@ impl<T: Trait> Module<T> {
|
|
|
|
|
|
let new_lead_id = <NextLeadId<T>>::get();
|
|
let new_lead_id = <NextLeadId<T>>::get();
|
|
|
|
|
|
- let new_lead_role =
|
|
|
|
- role_types::ActorInRole::new(role_types::Role::CuratorLead, new_lead_id);
|
|
|
|
-
|
|
|
|
//
|
|
//
|
|
// == MUTATION SAFE ==
|
|
// == MUTATION SAFE ==
|
|
//
|
|
//
|
|
|
|
|
|
- // Register in role - will fail if member cannot become lead
|
|
|
|
- members::Module::<T>::register_role_on_member(member, &new_lead_role)?;
|
|
|
|
-
|
|
|
|
// Construct lead
|
|
// Construct lead
|
|
let new_lead = Lead {
|
|
let new_lead = Lead {
|
|
|
|
+ member_id: member,
|
|
role_account,
|
|
role_account,
|
|
reward_relationship: None,
|
|
reward_relationship: None,
|
|
inducted: <system::Module<T>>::block_number(),
|
|
inducted: <system::Module<T>>::block_number(),
|
|
@@ -2093,7 +1976,7 @@ impl<T: Trait> Module<T> {
|
|
<LeadById<T>>::insert(new_lead_id, new_lead);
|
|
<LeadById<T>>::insert(new_lead_id, new_lead);
|
|
|
|
|
|
// Update current lead
|
|
// Update current lead
|
|
- <CurrentLeadId<T>>::put(new_lead_id); // Some(new_lead_id)
|
|
|
|
|
|
+ <CurrentLeadId<T>>::put(new_lead_id);
|
|
|
|
|
|
// Update next lead counter
|
|
// Update next lead counter
|
|
<NextLeadId<T>>::mutate(|id| *id += <LeadId<T> as One>::one());
|
|
<NextLeadId<T>>::mutate(|id| *id += <LeadId<T> as One>::one());
|
|
@@ -2113,14 +1996,6 @@ impl<T: Trait> Module<T> {
|
|
// == MUTATION SAFE ==
|
|
// == MUTATION SAFE ==
|
|
//
|
|
//
|
|
|
|
|
|
- // Unregister from role in membership model
|
|
|
|
- let current_lead_role = role_types::ActorInRole {
|
|
|
|
- role: role_types::Role::CuratorLead,
|
|
|
|
- actor_id: lead_id,
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- <members::Module<T>>::unregister_role(current_lead_role)?;
|
|
|
|
-
|
|
|
|
// Update lead stage as exited
|
|
// Update lead stage as exited
|
|
let current_block = <system::Module<T>>::block_number();
|
|
let current_block = <system::Module<T>>::block_number();
|
|
|
|
|
|
@@ -2134,7 +2009,7 @@ impl<T: Trait> Module<T> {
|
|
<LeadById<T>>::insert(lead_id, new_lead);
|
|
<LeadById<T>>::insert(lead_id, new_lead);
|
|
|
|
|
|
// Update current lead
|
|
// Update current lead
|
|
- <CurrentLeadId<T>>::take(); // None
|
|
|
|
|
|
+ <CurrentLeadId<T>>::take();
|
|
|
|
|
|
// Trigger event
|
|
// Trigger event
|
|
Self::deposit_event(RawEvent::LeadUnset(lead_id));
|
|
Self::deposit_event(RawEvent::LeadUnset(lead_id));
|
|
@@ -2163,54 +2038,7 @@ impl<T: Trait> Module<T> {
|
|
Ok(())
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
|
|
- fn ensure_can_register_role_on_member(
|
|
|
|
- member_id: &T::MemberId,
|
|
|
|
- role: role_types::Role,
|
|
|
|
- actor_id: &ActorIdInMembersModule<T>,
|
|
|
|
- ) -> Result<members::ActorInRole<ActorIdInMembersModule<T>>, &'static str> {
|
|
|
|
- let new_actor_in_role = role_types::ActorInRole::new(role, *actor_id);
|
|
|
|
-
|
|
|
|
- <members::Module<T>>::can_register_role_on_member(member_id, &new_actor_in_role)
|
|
|
|
- .map(|_| new_actor_in_role)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- fn ensure_can_register_curator_role_on_member(
|
|
|
|
- member_id: &T::MemberId,
|
|
|
|
- ) -> Result<
|
|
|
|
- (
|
|
|
|
- members::ActorInRole<ActorIdInMembersModule<T>>,
|
|
|
|
- CuratorId<T>,
|
|
|
|
- ),
|
|
|
|
- &'static str,
|
|
|
|
- > {
|
|
|
|
- let next_id = <NextCuratorId<T>>::get();
|
|
|
|
-
|
|
|
|
- Self::ensure_can_register_role_on_member(member_id, role_types::Role::Curator, &next_id)
|
|
|
|
- .map(|curator_in_role| (curator_in_role, next_id))
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- fn ensure_can_register_channel_owner_role_on_member(
|
|
|
|
- member_id: &T::MemberId,
|
|
|
|
- opt_channel_id: Option<ChannelId<T>>,
|
|
|
|
- ) -> Result<
|
|
|
|
- (
|
|
|
|
- members::ActorInRole<ActorIdInMembersModule<T>>,
|
|
|
|
- ChannelId<T>,
|
|
|
|
- ),
|
|
|
|
- &'static str,
|
|
|
|
- > {
|
|
|
|
- let next_channel_id = opt_channel_id.unwrap_or_else(NextChannelId::<T>::get);
|
|
|
|
-
|
|
|
|
- Self::ensure_can_register_role_on_member(
|
|
|
|
- member_id,
|
|
|
|
- role_types::Role::ChannelOwner,
|
|
|
|
- &next_channel_id,
|
|
|
|
- )
|
|
|
|
- .map(|member_in_role| (member_in_role, next_channel_id))
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// TODO: convert InputConstraint ensurer routines into macroes
|
|
// TODO: convert InputConstraint ensurer routines into macroes
|
|
-
|
|
|
|
fn ensure_channel_handle_is_valid(handle: &[u8]) -> dispatch::Result {
|
|
fn ensure_channel_handle_is_valid(handle: &[u8]) -> dispatch::Result {
|
|
ChannelHandleConstraint::get().ensure_valid(
|
|
ChannelHandleConstraint::get().ensure_valid(
|
|
handle.len(),
|
|
handle.len(),
|
|
@@ -2315,7 +2143,7 @@ impl<T: Trait> Module<T> {
|
|
pub fn ensure_lead_is_set() -> Result<
|
|
pub fn ensure_lead_is_set() -> Result<
|
|
(
|
|
(
|
|
LeadId<T>,
|
|
LeadId<T>,
|
|
- Lead<T::AccountId, T::RewardRelationshipId, T::BlockNumber>,
|
|
|
|
|
|
+ Lead<T::AccountId, T::RewardRelationshipId, T::BlockNumber, T::MemberId>,
|
|
),
|
|
),
|
|
&'static str,
|
|
&'static str,
|
|
> {
|
|
> {
|
|
@@ -2344,7 +2172,7 @@ impl<T: Trait> Module<T> {
|
|
) -> Result<
|
|
) -> Result<
|
|
(
|
|
(
|
|
LeadId<T>,
|
|
LeadId<T>,
|
|
- Lead<T::AccountId, T::RewardRelationshipId, T::BlockNumber>,
|
|
|
|
|
|
+ Lead<T::AccountId, T::RewardRelationshipId, T::BlockNumber, T::MemberId>,
|
|
),
|
|
),
|
|
&'static str,
|
|
&'static str,
|
|
> {
|
|
> {
|
|
@@ -2359,25 +2187,7 @@ impl<T: Trait> Module<T> {
|
|
|
|
|
|
Ok((lead_id, lead))
|
|
Ok((lead_id, lead))
|
|
}
|
|
}
|
|
- /*
|
|
|
|
- fn ensure_activate_opening_at_valid(activate_at: &hiring::ActivateOpeningAt<T::BlockNumber>) -> Result<T::BlockNumber, &'static str>{
|
|
|
|
|
|
|
|
- let current_block = <system::Module<T>>::block_number();
|
|
|
|
-
|
|
|
|
- let starting_block =
|
|
|
|
- match activate_at {
|
|
|
|
- hiring::ActivateOpeningAt::CurrentBlock => current_block,
|
|
|
|
- hiring::ActivateOpeningAt::ExactBlock(block_number) => block_number.clone()
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- ensure!(
|
|
|
|
- starting_block >= current_block,
|
|
|
|
- MSG_OPENING_CANNOT_ACTIVATE_IN_THE_PAST
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- Ok(starting_block)
|
|
|
|
- }
|
|
|
|
- */
|
|
|
|
fn ensure_curator_opening_exists(
|
|
fn ensure_curator_opening_exists(
|
|
curator_opening_id: &CuratorOpeningId<T>,
|
|
curator_opening_id: &CuratorOpeningId<T>,
|
|
) -> Result<
|
|
) -> Result<
|
|
@@ -2542,8 +2352,6 @@ impl<T: Trait> Module<T> {
|
|
),
|
|
),
|
|
&'static str,
|
|
&'static str,
|
|
> {
|
|
> {
|
|
- //Result<(hiring::Application<<T as hiring::Trait>::OpeningId, T::BlockNumber, <T as stake::Trait>::StakeId>, CuratorOpening<T::OpeningId, T::BlockNumber, BalanceOf<T>, CuratorApplicationId<T>> ,hiring::Opening<BalanceOf<T>, T::BlockNumber, <T as hiring::Trait>::ApplicationId>), &'static str> {
|
|
|
|
-
|
|
|
|
ensure!(
|
|
ensure!(
|
|
CuratorApplicationById::<T>::exists(curator_application_id),
|
|
CuratorApplicationById::<T>::exists(curator_application_id),
|
|
MSG_CURATOR_APPLICATION_DOES_NOT_EXIST
|
|
MSG_CURATOR_APPLICATION_DOES_NOT_EXIST
|
|
@@ -2551,12 +2359,8 @@ impl<T: Trait> Module<T> {
|
|
|
|
|
|
let curator_application = CuratorApplicationById::<T>::get(curator_application_id);
|
|
let curator_application = CuratorApplicationById::<T>::get(curator_application_id);
|
|
|
|
|
|
- //let application = hiring::ApplicationById::<T>::get(curator_application.application_id);
|
|
|
|
-
|
|
|
|
let curator_opening = CuratorOpeningById::<T>::get(curator_application.curator_opening_id);
|
|
let curator_opening = CuratorOpeningById::<T>::get(curator_application.curator_opening_id);
|
|
|
|
|
|
- //let opening = hiring::OpeningById::<T>::get(curator_opening.opening_id);
|
|
|
|
-
|
|
|
|
Ok((
|
|
Ok((
|
|
curator_application,
|
|
curator_application,
|
|
*curator_application_id,
|
|
*curator_application_id,
|