mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 00:31:07 +00:00
MEL: Origin, Referenda, ConvictionVoting (#11631)
* Referenda & CV pallets ready * Fix build * Add mel_bound for Voting and Casting types * Add mel_bound on Tally * Add mel_bound on another Tally * Add mel_bound for pallet_collective::RawOrigin Co-authored-by: Keith Yeung <kungfukeith11@gmail.com>
This commit is contained in:
@@ -87,12 +87,11 @@ type ClassOf<T, I = ()> = <<T as Config<I>>::Polls as Polling<TallyOf<T, I>>>::C
|
||||
#[frame_support::pallet]
|
||||
pub mod pallet {
|
||||
use super::*;
|
||||
use frame_support::pallet_prelude::*;
|
||||
use frame_support::{pallet_prelude::*, traits::ClassCountOf};
|
||||
use frame_system::pallet_prelude::*;
|
||||
|
||||
#[pallet::pallet]
|
||||
#[pallet::generate_store(pub(super) trait Store)]
|
||||
#[pallet::without_storage_info]
|
||||
pub struct Pallet<T, I = ()>(_);
|
||||
|
||||
#[pallet::config]
|
||||
@@ -154,7 +153,7 @@ pub mod pallet {
|
||||
_,
|
||||
Twox64Concat,
|
||||
T::AccountId,
|
||||
Vec<(ClassOf<T, I>, BalanceOf<T, I>)>,
|
||||
BoundedVec<(ClassOf<T, I>, BalanceOf<T, I>), ClassCountOf<T::Polls, TallyOf<T, I>>>,
|
||||
ValueQuery,
|
||||
>;
|
||||
|
||||
@@ -616,7 +615,15 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
ClassLocksFor::<T, I>::mutate(who, |locks| {
|
||||
match locks.iter().position(|x| &x.0 == class) {
|
||||
Some(i) => locks[i].1 = locks[i].1.max(amount),
|
||||
None => locks.push((class.clone(), amount)),
|
||||
None => {
|
||||
let ok = locks.try_push((class.clone(), amount)).is_ok();
|
||||
debug_assert!(
|
||||
ok,
|
||||
"Vec bounded by number of classes; \
|
||||
all items in Vec associated with a unique class; \
|
||||
qed"
|
||||
);
|
||||
},
|
||||
}
|
||||
});
|
||||
T::Currency::extend_lock(CONVICTION_VOTING_ID, who, amount, WithdrawReasons::TRANSFER);
|
||||
@@ -632,7 +639,13 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
let lock_needed = ClassLocksFor::<T, I>::mutate(who, |locks| {
|
||||
locks.retain(|x| &x.0 != class);
|
||||
if !class_lock_needed.is_zero() {
|
||||
locks.push((class.clone(), class_lock_needed));
|
||||
let ok = locks.try_push((class.clone(), class_lock_needed)).is_ok();
|
||||
debug_assert!(
|
||||
ok,
|
||||
"Vec bounded by number of classes; \
|
||||
all items in Vec associated with a unique class; \
|
||||
qed"
|
||||
);
|
||||
}
|
||||
locks.iter().map(|x| x.1).max().unwrap_or(Zero::zero())
|
||||
});
|
||||
|
||||
@@ -43,6 +43,7 @@ use crate::{AccountVote, Conviction, Vote};
|
||||
MaxEncodedLen,
|
||||
)]
|
||||
#[scale_info(skip_type_params(Total))]
|
||||
#[codec(mel_bound(Votes: MaxEncodedLen))]
|
||||
pub struct Tally<Votes: Clone + PartialEq + Eq + Debug + TypeInfo + Codec, Total> {
|
||||
/// The number of aye votes, expressed in terms of post-conviction lock-vote.
|
||||
pub ayes: Votes,
|
||||
|
||||
@@ -162,6 +162,7 @@ pub struct Delegating<Balance, AccountId, BlockNumber> {
|
||||
/// Information concerning the direct vote-casting of some voting power.
|
||||
#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
|
||||
#[scale_info(skip_type_params(MaxVotes))]
|
||||
#[codec(mel_bound(Balance: MaxEncodedLen, BlockNumber: MaxEncodedLen, PollIndex: MaxEncodedLen))]
|
||||
pub struct Casting<Balance, BlockNumber, PollIndex, MaxVotes>
|
||||
where
|
||||
MaxVotes: Get<u32>,
|
||||
@@ -177,6 +178,10 @@ where
|
||||
/// An indicator for what an account is doing; it can either be delegating or voting.
|
||||
#[derive(Encode, Decode, Clone, Eq, PartialEq, RuntimeDebug, TypeInfo, MaxEncodedLen)]
|
||||
#[scale_info(skip_type_params(MaxVotes))]
|
||||
#[codec(mel_bound(
|
||||
Balance: MaxEncodedLen, AccountId: MaxEncodedLen, BlockNumber: MaxEncodedLen,
|
||||
PollIndex: MaxEncodedLen,
|
||||
))]
|
||||
pub enum Voting<Balance, AccountId, BlockNumber, PollIndex, MaxVotes>
|
||||
where
|
||||
MaxVotes: Get<u32>,
|
||||
|
||||
Reference in New Issue
Block a user