Skip to content

Commit ea3ca3f

Browse files
Move LockableCurrency trait to fungibles::Lockable and deprecate LockableCurrency (paritytech#12798)
* WIP move LockableCurrency to fungibles * rename Lockable and LockIdentifier to funginbles::* * fix imports further * change Lockable from fungible to fungibles * reintroduce LockableCurrency but marked as deprecated * fix imports * fix imports * cargo fmt * add allow deprecated warnings * remove unused benchmark import * fix some of the docs * fix failing doctest check * reexport LockIdentifier and LockableCurrency from support/traits * reexport LockIdentifier and LockableCurrency from support/traits * allow using deprecated re-export * replace LockableCurrency and LockIdentifier with a module alias * Update frame/support/src/traits/tokens/fungibles/lockable.rs * Update frame/staking/src/pallet/mod.rs Co-authored-by: Squirrel <gilescope@gmail.com> * Update frame/support/src/traits.rs Co-authored-by: Squirrel <gilescope@gmail.com> * REVERT removing fungibles::Lockable import Co-authored-by: parity-processbot <> Co-authored-by: Squirrel <gilescope@gmail.com>
1 parent 6e73c85 commit ea3ca3f

File tree

20 files changed

+135
-105
lines changed

20 files changed

+135
-105
lines changed

bin/node/runtime/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ use frame_support::{
3232
pallet_prelude::Get,
3333
parameter_types,
3434
traits::{
35-
fungible::ItemOf, AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU16, ConstU32,
36-
Currency, EitherOfDiverse, EqualPrivilegeOnly, Everything, Imbalance, InstanceFilter,
37-
KeyOwnerProofSystem, LockIdentifier, Nothing, OnUnbalanced, U128CurrencyToVote,
35+
fungible::ItemOf, fungibles, AsEnsureOriginWithArg, ConstBool, ConstU128, ConstU16,
36+
ConstU32, Currency, EitherOfDiverse, EqualPrivilegeOnly, Everything, Imbalance,
37+
InstanceFilter, KeyOwnerProofSystem, Nothing, OnUnbalanced, U128CurrencyToVote,
3838
WithdrawReasons,
3939
},
4040
weights::{
@@ -1003,7 +1003,7 @@ parameter_types! {
10031003
pub const DesiredRunnersUp: u32 = 7;
10041004
pub const MaxVoters: u32 = 10 * 1000;
10051005
pub const MaxCandidates: u32 = 1000;
1006-
pub const ElectionsPhragmenPalletId: LockIdentifier = *b"phrelect";
1006+
pub const ElectionsPhragmenPalletId: fungibles::LockIdentifier = *b"phrelect";
10071007
}
10081008

10091009
// Make sure that there are no more than `MaxMembers` members elected via elections-phragmen.

frame/balances/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ that you need, then you can avoid coupling with the Balances module.
5757
fungible assets system.
5858
- [`ReservableCurrency`](https://docs.rs/frame-support/latest/frame_support/traits/trait.ReservableCurrency.html):
5959
Functions for dealing with assets that can be reserved from an account.
60-
- [`LockableCurrency`](https://docs.rs/frame-support/latest/frame_support/traits/trait.LockableCurrency.html): Functions for
60+
- [`Lockable`](https://docs.rs/frame-support/latest/frame_support/traits/fungibles/trait.Lockable.html): Functions for
6161
dealing with accounts that allow liquidity restrictions.
6262
- [`Imbalance`](https://docs.rs/frame-support/latest/frame_support/traits/trait.Imbalance.html): Functions for handling
6363
imbalances between total issuance in the system and account balances. Must be used when a function
@@ -88,13 +88,13 @@ pub type NegativeImbalanceOf<T> = <<T as Config>::Currency as Currency<<T as fra
8888

8989
```
9090

91-
The Staking module uses the `LockableCurrency` trait to lock a stash account's funds:
91+
The Staking module uses the `fungibles::Lockable` trait to lock a stash account's funds:
9292

9393
```rust
94-
use frame_support::traits::{WithdrawReasons, LockableCurrency};
94+
use frame_support::traits::{WithdrawReasons, fungibles};
9595
use sp_runtime::traits::Bounded;
9696
pub trait Config: frame_system::Config {
97-
type Currency: LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>;
97+
type Currency: fungibles::Lockable<Self::AccountId, Moment=Self::BlockNumber>;
9898
}
9999

100100
fn update_ledger<T: Config>(

frame/balances/src/lib.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
//! - [`ReservableCurrency`](frame_support::traits::ReservableCurrency):
8080
//! - [`NamedReservableCurrency`](frame_support::traits::NamedReservableCurrency):
8181
//! Functions for dealing with assets that can be reserved from an account.
82-
//! - [`LockableCurrency`](frame_support::traits::LockableCurrency): Functions for
82+
//! - [`Lockable`](frame_support::traits::fungibles::Lockable): Functions for
8383
//! dealing with accounts that allow liquidity restrictions.
8484
//! - [`Imbalance`](frame_support::traits::Imbalance): Functions for handling
8585
//! imbalances between total issuance in the system and account balances. Must be used when a
@@ -113,13 +113,13 @@
113113
//! # fn main() {}
114114
//! ```
115115
//!
116-
//! The Staking pallet uses the `LockableCurrency` trait to lock a stash account's funds:
116+
//! The Staking pallet uses the `fungibles::Lockable` trait to lock a stash account's funds:
117117
//!
118118
//! ```
119-
//! use frame_support::traits::{WithdrawReasons, LockableCurrency};
119+
//! use frame_support::traits::{WithdrawReasons, fungibles, fungibles::Lockable};
120120
//! use sp_runtime::traits::Bounded;
121121
//! pub trait Config: frame_system::Config {
122-
//! type Currency: LockableCurrency<Self::AccountId, Moment=Self::BlockNumber>;
122+
//! type Currency: fungibles::Lockable<Self::AccountId, Moment=Self::BlockNumber>;
123123
//! }
124124
//! # struct StakingLedger<T: Config> {
125125
//! # stash: <T as frame_system::Config>::AccountId,
@@ -171,11 +171,13 @@ use frame_support::{
171171
ensure,
172172
pallet_prelude::DispatchResult,
173173
traits::{
174-
tokens::{fungible, BalanceStatus as Status, DepositConsequence, WithdrawConsequence},
174+
tokens::{
175+
fungible, fungibles, BalanceStatus as Status, DepositConsequence, WithdrawConsequence,
176+
},
175177
Currency, DefensiveSaturating, ExistenceRequirement,
176178
ExistenceRequirement::{AllowDeath, KeepAlive},
177-
Get, Imbalance, LockIdentifier, LockableCurrency, NamedReservableCurrency, OnUnbalanced,
178-
ReservableCurrency, SignedImbalance, StoredMap, TryDrop, WithdrawReasons,
179+
Get, Imbalance, NamedReservableCurrency, OnUnbalanced, ReservableCurrency, SignedImbalance,
180+
StoredMap, TryDrop, WithdrawReasons,
179181
},
180182
WeakBoundedVec,
181183
};
@@ -662,7 +664,7 @@ impl BitOr for Reasons {
662664
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug, MaxEncodedLen, TypeInfo)]
663665
pub struct BalanceLock<Balance> {
664666
/// An identifier for this lock. Only one lock may be in existence for each identifier.
665-
pub id: LockIdentifier,
667+
pub id: fungibles::LockIdentifier,
666668
/// The amount which the free balance may not drop below when this lock is in effect.
667669
pub amount: Balance,
668670
/// If true, then the lock remains in effect even for payment of transaction fees.
@@ -2131,7 +2133,7 @@ where
21312133
}
21322134
}
21332135

2134-
impl<T: Config<I>, I: 'static> LockableCurrency<T::AccountId> for Pallet<T, I>
2136+
impl<T: Config<I>, I: 'static> fungibles::Lockable<T::AccountId> for Pallet<T, I>
21352137
where
21362138
T::Balance: MaybeSerializeDeserialize + Debug,
21372139
{
@@ -2142,7 +2144,7 @@ where
21422144
// Set a lock on the balance of `who`.
21432145
// Is a no-op if lock amount is zero or `reasons` `is_none()`.
21442146
fn set_lock(
2145-
id: LockIdentifier,
2147+
id: fungibles::LockIdentifier,
21462148
who: &T::AccountId,
21472149
amount: T::Balance,
21482150
reasons: WithdrawReasons,
@@ -2164,7 +2166,7 @@ where
21642166
// Extend a lock on the balance of `who`.
21652167
// Is a no-op if lock amount is zero or `reasons` `is_none()`.
21662168
fn extend_lock(
2167-
id: LockIdentifier,
2169+
id: fungibles::LockIdentifier,
21682170
who: &T::AccountId,
21692171
amount: T::Balance,
21702172
reasons: WithdrawReasons,
@@ -2193,7 +2195,7 @@ where
21932195
Self::update_locks(who, &locks[..]);
21942196
}
21952197

2196-
fn remove_lock(id: LockIdentifier, who: &T::AccountId) {
2198+
fn remove_lock(id: fungibles::LockIdentifier, who: &T::AccountId) {
21972199
let mut locks = Self::locks(who);
21982200
locks.retain(|l| l.id != id);
21992201
Self::update_locks(who, &locks[..]);

frame/balances/src/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ macro_rules! decl_tests {
2828
use frame_support::{
2929
assert_noop, assert_storage_noop, assert_ok, assert_err,
3030
traits::{
31-
LockableCurrency, LockIdentifier, WithdrawReasons,
31+
fungibles, fungibles::Lockable, WithdrawReasons,
3232
Currency, ReservableCurrency, ExistenceRequirement::AllowDeath
3333
}
3434
};
3535
use pallet_transaction_payment::{ChargeTransactionPayment, Multiplier};
3636
use frame_system::RawOrigin;
3737

38-
const ID_1: LockIdentifier = *b"1 ";
39-
const ID_2: LockIdentifier = *b"2 ";
38+
const ID_1: fungibles::LockIdentifier = *b"1 ";
39+
const ID_2: fungibles::LockIdentifier = *b"2 ";
4040

4141
pub const CALL: &<$test as frame_system::Config>::RuntimeCall =
4242
&RuntimeCall::Balances(pallet_balances::Call::transfer { dest: 0, value: 0 });

frame/contracts/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use frame_support::{
3737
parameter_types,
3838
storage::child,
3939
traits::{
40-
BalanceStatus, ConstU32, ConstU64, Contains, Currency, Get, LockableCurrency, OnIdle,
40+
fungibles::Lockable, BalanceStatus, ConstU32, ConstU64, Contains, Currency, Get, OnIdle,
4141
OnInitialize, ReservableCurrency, WithdrawReasons,
4242
},
4343
weights::{constants::WEIGHT_PER_SECOND, Weight},

frame/conviction-voting/src/benchmarking.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use assert_matches::assert_matches;
2323
use frame_benchmarking::{account, benchmarks_instance_pallet, whitelist_account};
2424
use frame_support::{
2525
dispatch::RawOrigin,
26-
traits::{fungible, Currency, Get},
26+
traits::{Currency, Get},
2727
};
2828
use sp_runtime::traits::Bounded;
2929
use sp_std::collections::btree_map::BTreeMap;

frame/conviction-voting/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use frame_support::{
3131
dispatch::{DispatchError, DispatchResult},
3232
ensure,
3333
traits::{
34-
fungible, Currency, Get, LockIdentifier, LockableCurrency, PollStatus, Polling,
34+
fungible, fungibles, fungibles::Lockable, Currency, Get, PollStatus, Polling,
3535
ReservableCurrency, WithdrawReasons,
3636
},
3737
};
@@ -60,7 +60,7 @@ mod tests;
6060
#[cfg(feature = "runtime-benchmarks")]
6161
pub mod benchmarking;
6262

63-
const CONVICTION_VOTING_ID: LockIdentifier = *b"pyconvot";
63+
const CONVICTION_VOTING_ID: fungibles::LockIdentifier = *b"pyconvot";
6464

6565
type AccountIdLookupOf<T> = <<T as frame_system::Config>::Lookup as StaticLookup>::Source;
6666
type BalanceOf<T, I = ()> =
@@ -104,7 +104,7 @@ pub mod pallet {
104104
type WeightInfo: WeightInfo;
105105
/// Currency type with which voting happens.
106106
type Currency: ReservableCurrency<Self::AccountId>
107-
+ LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>
107+
+ fungibles::Lockable<Self::AccountId, Moment = Self::BlockNumber>
108108
+ fungible::Inspect<Self::AccountId>;
109109

110110
/// The implementation of the logic which conducts polls.

frame/democracy/src/lib.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,11 @@ use frame_support::{
157157
ensure,
158158
traits::{
159159
defensive_prelude::*,
160+
fungibles,
161+
fungibles::Lockable,
160162
schedule::{v3::Named as ScheduleNamed, DispatchTime},
161-
Bounded, Currency, Get, LockIdentifier, LockableCurrency, OnUnbalanced, QueryPreimage,
162-
ReservableCurrency, StorePreimage, WithdrawReasons,
163+
Bounded, Currency, Get, OnUnbalanced, QueryPreimage, ReservableCurrency, StorePreimage,
164+
WithdrawReasons,
163165
},
164166
weights::Weight,
165167
};
@@ -189,7 +191,7 @@ pub mod benchmarking;
189191

190192
pub mod migrations;
191193

192-
const DEMOCRACY_ID: LockIdentifier = *b"democrac";
194+
const DEMOCRACY_ID: fungibles::LockIdentifier = *b"democrac";
193195

194196
/// A proposal index.
195197
pub type PropIndex = u32;
@@ -234,7 +236,7 @@ pub mod pallet {
234236

235237
/// Currency type for this pallet.
236238
type Currency: ReservableCurrency<Self::AccountId>
237-
+ LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>;
239+
+ fungibles::Lockable<Self::AccountId, Moment = Self::BlockNumber>;
238240

239241
/// The period between a proposal being approved and enacted.
240242
///

frame/elections-phragmen/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@
101101
use codec::{Decode, Encode};
102102
use frame_support::{
103103
traits::{
104-
defensive_prelude::*, ChangeMembers, Contains, ContainsLengthBound, Currency,
105-
CurrencyToVote, Get, InitializeMembers, LockIdentifier, LockableCurrency, OnUnbalanced,
104+
defensive_prelude::*, fungibles, fungibles::Lockable, ChangeMembers, Contains,
105+
ContainsLengthBound, Currency, CurrencyToVote, Get, InitializeMembers, OnUnbalanced,
106106
ReservableCurrency, SortedMembers, WithdrawReasons,
107107
},
108108
weights::Weight,
@@ -199,10 +199,10 @@ pub mod pallet {
199199

200200
/// Identifier for the elections-phragmen pallet's lock
201201
#[pallet::constant]
202-
type PalletId: Get<LockIdentifier>;
202+
type PalletId: Get<fungibles::LockIdentifier>;
203203

204204
/// The currency that people are electing with.
205-
type Currency: LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>
205+
type Currency: fungibles::Lockable<Self::AccountId, Moment = Self::BlockNumber>
206206
+ ReservableCurrency<Self::AccountId>;
207207

208208
/// What to do when the members change.
@@ -1274,7 +1274,7 @@ mod tests {
12741274
}
12751275

12761276
parameter_types! {
1277-
pub const ElectionsPhragmenPalletId: LockIdentifier = *b"phrelect";
1277+
pub const ElectionsPhragmenPalletId: fungibles::LockIdentifier = *b"phrelect";
12781278
pub const PhragmenMaxVoters: u32 = 1000;
12791279
pub const PhragmenMaxCandidates: u32 = 100;
12801280
}

frame/executive/src/lib.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -620,10 +620,7 @@ mod tests {
620620

621621
use frame_support::{
622622
assert_err, parameter_types,
623-
traits::{
624-
ConstU32, ConstU64, ConstU8, Currency, LockIdentifier, LockableCurrency,
625-
WithdrawReasons,
626-
},
623+
traits::{fungibles, ConstU32, ConstU64, ConstU8, Currency, WithdrawReasons},
627624
weights::{ConstantMultiplier, IdentityFee, RuntimeDbWeight, Weight, WeightToFee},
628625
};
629626
use frame_system::{Call as SystemCall, ChainContext, LastRuntimeUpgradeInfo};
@@ -1185,11 +1182,11 @@ mod tests {
11851182

11861183
#[test]
11871184
fn can_pay_for_tx_fee_on_full_lock() {
1188-
let id: LockIdentifier = *b"0 ";
1185+
let id: fungibles::LockIdentifier = *b"0 ";
11891186
let execute_with_lock = |lock: WithdrawReasons| {
11901187
let mut t = new_test_ext(1);
11911188
t.execute_with(|| {
1192-
<pallet_balances::Pallet<Runtime> as LockableCurrency<Balance>>::set_lock(
1189+
<pallet_balances::Pallet<Runtime> as fungibles::Lockable<Balance>>::set_lock(
11931190
id, &1, 110, lock,
11941191
);
11951192
let xt = TestXt::new(

frame/referenda/src/lib.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// This file is part of Substrate.
2-
31
// Copyright (C) 2017-2022 Parity Technologies (UK) Ltd.
42
// SPDX-License-Identifier: Apache-2.0
53

@@ -68,11 +66,12 @@ use codec::{Codec, Encode};
6866
use frame_support::{
6967
ensure,
7068
traits::{
69+
fungibles,
7170
schedule::{
7271
v3::{Anon as ScheduleAnon, Named as ScheduleNamed},
7372
DispatchTime,
7473
},
75-
Currency, LockIdentifier, OnUnbalanced, OriginTrait, PollStatus, Polling, QueryPreimage,
74+
Currency, OnUnbalanced, OriginTrait, PollStatus, Polling, QueryPreimage,
7675
ReservableCurrency, StorePreimage, VoteTally,
7776
},
7877
BoundedVec,
@@ -133,7 +132,7 @@ macro_rules! impl_tracksinfo_get {
133132
};
134133
}
135134

136-
const ASSEMBLY_ID: LockIdentifier = *b"assembly";
135+
const ASSEMBLY_ID: fungibles::LockIdentifier = *b"assembly";
137136

138137
#[frame_support::pallet]
139138
pub mod pallet {

frame/staking/src/pallet/impls.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ use frame_support::{
2525
dispatch::WithPostDispatchInfo,
2626
pallet_prelude::*,
2727
traits::{
28-
Currency, CurrencyToVote, Defensive, DefensiveResult, EstimateNextNewSession, Get,
29-
Imbalance, LockableCurrency, OnUnbalanced, TryCollect, UnixTime, WithdrawReasons,
28+
fungibles::Lockable, Currency, CurrencyToVote, Defensive, DefensiveResult,
29+
EstimateNextNewSession, Get, Imbalance, OnUnbalanced, TryCollect, UnixTime,
30+
WithdrawReasons,
3031
},
3132
weights::Weight,
3233
};

frame/staking/src/pallet/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use frame_support::{
2424
dispatch::Codec,
2525
pallet_prelude::*,
2626
traits::{
27-
Currency, CurrencyToVote, Defensive, DefensiveResult, DefensiveSaturating, EnsureOrigin,
28-
EstimateNextNewSession, Get, LockIdentifier, LockableCurrency, OnUnbalanced, TryCollect,
27+
fungibles, fungibles::Lockable, Currency, CurrencyToVote, Defensive, DefensiveResult,
28+
DefensiveSaturating, EnsureOrigin, EstimateNextNewSession, Get, OnUnbalanced, TryCollect,
2929
UnixTime,
3030
},
3131
weights::Weight,
@@ -50,7 +50,7 @@ use crate::{
5050
ValidatorPrefs,
5151
};
5252

53-
const STAKING_ID: LockIdentifier = *b"staking ";
53+
const STAKING_ID: fungibles::LockIdentifier = *b"staking ";
5454

5555
#[frame_support::pallet]
5656
pub mod pallet {
@@ -78,7 +78,7 @@ pub mod pallet {
7878
#[pallet::config]
7979
pub trait Config: frame_system::Config {
8080
/// The staking balance.
81-
type Currency: LockableCurrency<
81+
type Currency: fungibles::Lockable<
8282
Self::AccountId,
8383
Moment = Self::BlockNumber,
8484
Balance = Self::CurrencyBalance,

frame/support/src/traits.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
//! NOTE: If you're looking for `parameter_types`, it has moved in to the top-level module.
2121
2222
pub mod tokens;
23+
#[allow(deprecated)]
2324
pub use tokens::{
2425
currency::{
2526
ActiveIssuanceOf, Currency, LockIdentifier, LockableCurrency, NamedReservableCurrency,

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ use sp_std::fmt::Debug;
3232
mod reservable;
3333
pub use reservable::{NamedReservableCurrency, ReservableCurrency};
3434
mod lockable;
35-
pub use lockable::{LockIdentifier, LockableCurrency, VestingSchedule};
35+
36+
#[deprecated(note = "Deprecated in favour of using fungibles::Lockable trait directly")]
37+
pub use super::fungibles::{LockIdentifier, Lockable as LockableCurrency};
38+
pub use lockable::VestingSchedule;
3639

3740
/// Abstraction over a fungible assets system.
3841
pub trait Currency<AccountId> {

0 commit comments

Comments
 (0)