Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 254ead7

Browse files
committed
diff from meeting with Kian
1 parent b914803 commit 254ead7

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

frame/elections-phragmen/src/lib.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,15 @@ pub mod pallet {
203203
#[pallet::constant]
204204
type PalletId: Get<LockIdentifier>;
205205

206+
/// This will come from the outer runtime, and it will be the amalgamated lock ids.
207+
type RuntimeLockIds: From<crate::pallet::LockIds>;
208+
206209
/// The currency that people are electing with.
207-
type Currency: LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>
210+
type Currency: LockableCurrency<
211+
Self::AccountId,
212+
Moment = Self::BlockNumber,
213+
LockId = Self::RuntimeLockId
214+
>
208215
+ ReservableCurrency<Self::AccountId>;
209216

210217
/// What to do when the members change.
@@ -361,9 +368,20 @@ pub mod pallet {
361368
},
362369
};
363370

371+
// local lock id.
372+
#[pallet::composite]
373+
enum LockId {
374+
CouncilVoting,
375+
OtherReason,
376+
}
377+
378+
let id: T::RuntimeLockIds = LockId::CouncilVoting.into();
379+
364380
// Amount to be locked up.
365381
let locked_stake = value.min(T::Currency::free_balance(&who));
366-
T::Currency::set_lock(T::PalletId::get(), &who, locked_stake, WithdrawReasons::all());
382+
// TODO: the currency implementations, whatever it might be, will know if this lock/hold
383+
// operation is going to collide with collide with other existing locks or not.
384+
T::Currency::set_lock(id, &who, locked_stake, WithdrawReasons::all());
367385

368386
Voting::<T>::insert(&who, Voter { votes, deposit: new_deposit, stake: locked_stake });
369387
Ok(None::<Weight>.into())

frame/support/src/traits/tokens/currency/lockable.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ pub trait LockableCurrency<AccountId>: Currency<AccountId> {
2929
/// The quantity used to denote time; usually just a `BlockNumber`.
3030
type Moment;
3131

32+
/// Opaque Identifier for lock.
33+
// TODO: can already be ported to master with LockIdentifier used everywhere.
34+
type LockId;
35+
3236
/// The maximum number of locks a user should have on their account.
3337
type MaxLocks: Get<u32>;
3438

@@ -39,7 +43,7 @@ pub trait LockableCurrency<AccountId>: Currency<AccountId> {
3943
///
4044
/// If the lock `id` already exists, this will update it.
4145
fn set_lock(
42-
id: LockIdentifier,
46+
id: Self::LockId,
4347
who: &AccountId,
4448
amount: Self::Balance,
4549
reasons: WithdrawReasons,
@@ -54,7 +58,7 @@ pub trait LockableCurrency<AccountId>: Currency<AccountId> {
5458
/// - maximum `amount`
5559
/// - bitwise mask of all `reasons`
5660
fn extend_lock(
57-
id: LockIdentifier,
61+
id: Self::LockId,
5862
who: &AccountId,
5963
amount: Self::Balance,
6064
reasons: WithdrawReasons,

0 commit comments

Comments
 (0)