Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pallet-membership should implement ContainsLengthBound #4865

Merged
merged 5 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 13 additions & 0 deletions prdoc/pr_4865.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Schema: Polkadot SDK PRDoc Schema (prdoc) v1.0.0
# See doc at https://raw.githubusercontent.com/paritytech/polkadot-sdk/master/prdoc/schema_user.json

title: Implement trait `ContainsLengthBound` for pallet-membership

doc:
- audience: Runtime Dev
description: |
Implement trait ContainsLengthBound for pallet membership otherwise we can't use it with pallet-tips without wrapper

crates:
- name: pallet-membership
Aideepakchaudhary marked this conversation as resolved.
Show resolved Hide resolved
bump: minor
13 changes: 12 additions & 1 deletion substrate/frame/membership/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

use frame_support::{
traits::{ChangeMembers, Contains, Get, InitializeMembers, SortedMembers},
traits::{ChangeMembers, Contains, ContainsLengthBound, Get, InitializeMembers, SortedMembers},
BoundedVec,
};
use sp_runtime::traits::{StaticLookup, UniqueSaturatedInto};
Expand Down Expand Up @@ -361,6 +361,17 @@ impl<T: Config<I>, I: 'static> Contains<T::AccountId> for Pallet<T, I> {
}
}

impl<T: Config> ContainsLengthBound for Pallet<T> {
fn min_len() -> usize {
0
}

/// Implementation uses a parameter type so calling is cost-free.
fn max_len() -> usize {
T::MaxMembers::get() as usize
}
}

impl<T: Config<I>, I: 'static> SortedMembers<T::AccountId> for Pallet<T, I> {
fn sorted_members() -> Vec<T::AccountId> {
Self::members().to_vec()
Expand Down
Loading