This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat(pallet-ranked-collective): added types #14577
Open
PraetorP
wants to merge
8
commits into
paritytech:master
Choose a base branch
from
UniqueNetwork:ranked-collective-config
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
74254e9
feat(pallet-ranked-collective): added types
PraetorP 837cbac
Merge remote-tracking branch 'origin/master' into ranked-collective-c…
PraetorP 4d4711b
doc(pallet-ranked-collective): update fn docs
PraetorP b2ac5d1
Update primitives/runtime/src/traits.rs
PraetorP 5d1b180
test(pallet-ranked-collective): switch to `Ignore`
PraetorP e1f8af4
Update primitives/runtime/src/traits.rs
PraetorP 2261fb0
Revert "Update primitives/runtime/src/traits.rs"
PraetorP 9137fb3
Update primitives/runtime/src/traits.rs
PraetorP File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -382,12 +382,19 @@ pub mod pallet { | |
type RuntimeEvent: From<Event<Self, I>> | ||
+ IsType<<Self as frame_system::Config>::RuntimeEvent>; | ||
|
||
/// The origin required to add or promote a mmember. The success value indicates the | ||
/// The origin required to add a member. | ||
type AddOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = ()>; | ||
|
||
/// The origin required to remove a member. The success value indicates the | ||
/// maximum rank *from which* the removal may be. | ||
type RemoveOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = Rank>; | ||
|
||
/// The origin required to promote a member. The success value indicates the | ||
/// maximum rank *to which* the promotion may be. | ||
type PromoteOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = Rank>; | ||
|
||
/// The origin required to demote or remove a member. The success value indicates the | ||
/// maximum rank *from which* the demotion/removal may be. | ||
/// The origin required to demote a member. The success value indicates the | ||
/// maximum rank *from which* the demotion may be. | ||
type DemoteOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = Rank>; | ||
|
||
/// The polling system used for our voting. | ||
|
@@ -482,22 +489,21 @@ pub mod pallet { | |
impl<T: Config<I>, I: 'static> Pallet<T, I> { | ||
/// Introduce a new member. | ||
/// | ||
/// - `origin`: Must be the `AdminOrigin`. | ||
/// - `origin`: Must be the `AddOrigin`. | ||
/// - `who`: Account of non-member which will become a member. | ||
/// - `rank`: The rank to give the new member. | ||
/// | ||
/// Weight: `O(1)` | ||
#[pallet::call_index(0)] | ||
#[pallet::weight(T::WeightInfo::add_member())] | ||
pub fn add_member(origin: OriginFor<T>, who: AccountIdLookupOf<T>) -> DispatchResult { | ||
let _ = T::PromoteOrigin::ensure_origin(origin)?; | ||
T::AddOrigin::ensure_origin(origin)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function docs needs to be updated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. + Refresh docs to some other functions |
||
let who = T::Lookup::lookup(who)?; | ||
Self::do_add_member(who) | ||
} | ||
|
||
/// Increment the rank of an existing member by one. | ||
/// | ||
/// - `origin`: Must be the `AdminOrigin`. | ||
/// - `origin`: Must be the `PromoteOrigin`. | ||
/// - `who`: Account of existing member. | ||
/// | ||
/// Weight: `O(1)` | ||
|
@@ -512,7 +518,7 @@ pub mod pallet { | |
/// Decrement the rank of an existing member by one. If the member is already at rank zero, | ||
/// then they are removed entirely. | ||
/// | ||
/// - `origin`: Must be the `AdminOrigin`. | ||
/// - `origin`: Must be the `DemoteOrigin`. | ||
/// - `who`: Account of existing member of rank greater than zero. | ||
/// | ||
/// Weight: `O(1)`, less if the member's index is highest in its rank. | ||
|
@@ -526,7 +532,7 @@ pub mod pallet { | |
|
||
/// Remove the member entirely. | ||
/// | ||
/// - `origin`: Must be the `AdminOrigin`. | ||
/// - `origin`: Must be the `RemoveOrigin`. | ||
/// - `who`: Account of existing member of rank greater than zero. | ||
/// - `min_rank`: The rank of the member or greater. | ||
/// | ||
|
@@ -538,7 +544,7 @@ pub mod pallet { | |
who: AccountIdLookupOf<T>, | ||
min_rank: Rank, | ||
) -> DispatchResultWithPostInfo { | ||
let max_rank = T::DemoteOrigin::ensure_origin(origin)?; | ||
let max_rank = T::RemoveOrigin::ensure_origin(origin)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function doc mentions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
let who = T::Lookup::lookup(who)?; | ||
let MemberRecord { rank, .. } = Self::ensure_member(&who)?; | ||
ensure!(min_rank >= rank, Error::<T, I>::InvalidWitness); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does it improve flexibility?
PromoteOrigin
returns theRank
, if it returns 0, it can onlyadd_member
.Same with
DemoteOrigin
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
AddOrigin
allows a chain to use a different (from thePromoteOrigin
) authority to add members. E.g., entering the ranked collective could be managed separately from promoting inside it. The same with theRemoveOrigin
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can do the same with only
PromoteOrigin
since it returnsRank
.for your add origin the promote origin type will return rank
0
hence it can only add.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In current impl where only
PromoteOrigin
exists, one could add a dedicated origin with a 0 rank to thePromoteOrigin
to add new members. However, anyone who can promote can also add a new member in this case, not only our dedicated origin. So we can't express the setting where one can promote an existing member but can't add a new one.