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

Commit 3beef83

Browse files
bkchrggwpez
authored andcommitted
HoldReason: Improve usage (#13869)
* HoldReason: Improve usage `HoldReason` was switched recently to use the `composite_enum` attribute that will merge the enums from all pallets in the runtime to `RuntimeHoldReason`. `pallet-nis` was still requiring that the variant was passed as constant to call `hold`. The proper implementation is to use the `HoldReason` from inside the pallet directly when calling `hold`. This is done by adding a `RuntimeHoldReason` as type to the `Config` trait and requiring that `Currency` is using the same reason. Besides that the pr changes the name `HoldIdentifier` in `pallet_balances::Config` to `RuntimeHoldReason`. * Update frame/nis/src/lib.rs Co-authored-by: Oliver Tale-Yazdi <[email protected]> * Review comment * Fixes --------- Co-authored-by: Oliver Tale-Yazdi <[email protected]>
1 parent d6a78e5 commit 3beef83

File tree

60 files changed

+97
-127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+97
-127
lines changed

bin/node-template/runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl pallet_balances::Config for Runtime {
245245
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
246246
type FreezeIdentifier = ();
247247
type MaxFreezes = ();
248-
type HoldIdentifier = ();
248+
type RuntimeHoldReason = ();
249249
type MaxHolds = ();
250250
}
251251

bin/node/runtime/src/lib.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ use pallet_nis::WithMaximumOf;
5959
use pallet_session::historical as pallet_session_historical;
6060
pub use pallet_transaction_payment::{CurrencyAdapter, Multiplier, TargetedFeeAdjustment};
6161
use pallet_transaction_payment::{FeeDetails, RuntimeDispatchInfo};
62-
use scale_info::TypeInfo;
6362
use sp_api::impl_runtime_apis;
6463
use sp_authority_discovery::AuthorityId as AuthorityDiscoveryId;
6564
use sp_consensus_grandpa::AuthorityId as GrandpaId;
@@ -439,17 +438,6 @@ parameter_types! {
439438
pub const MaxReserves: u32 = 50;
440439
}
441440

442-
/// A reason for placing a hold on funds.
443-
#[derive(
444-
Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Encode, Decode, MaxEncodedLen, Debug, TypeInfo,
445-
)]
446-
pub enum HoldReason {
447-
/// The NIS Pallet has reserved it for a non-fungible receipt.
448-
Nis,
449-
/// Used by the NFT Fractionalization Pallet.
450-
NftFractionalization,
451-
}
452-
453441
impl pallet_balances::Config for Runtime {
454442
type MaxLocks = MaxLocks;
455443
type MaxReserves = MaxReserves;
@@ -462,7 +450,7 @@ impl pallet_balances::Config for Runtime {
462450
type WeightInfo = pallet_balances::weights::SubstrateWeight<Runtime>;
463451
type FreezeIdentifier = ();
464452
type MaxFreezes = ();
465-
type HoldIdentifier = HoldReason;
453+
type RuntimeHoldReason = RuntimeHoldReason;
466454
type MaxHolds = ConstU32<2>;
467455
}
468456

@@ -1520,7 +1508,6 @@ parameter_types! {
15201508
pub const ThawThrottle: (Perquintill, BlockNumber) = (Perquintill::from_percent(25), 5);
15211509
pub Target: Perquintill = Perquintill::zero();
15221510
pub const NisPalletId: PalletId = PalletId(*b"py/nis ");
1523-
pub const NisHoldReason: HoldReason = HoldReason::Nis;
15241511
}
15251512

15261513
impl pallet_nis::Config for Runtime {
@@ -1544,7 +1531,7 @@ impl pallet_nis::Config for Runtime {
15441531
type IntakePeriod = IntakePeriod;
15451532
type MaxIntakeWeight = MaxIntakeWeight;
15461533
type ThawThrottle = ThawThrottle;
1547-
type HoldReason = NisHoldReason;
1534+
type RuntimeHoldReason = RuntimeHoldReason;
15481535
}
15491536

15501537
parameter_types! {
@@ -1618,7 +1605,6 @@ parameter_types! {
16181605
pub const NftFractionalizationPalletId: PalletId = PalletId(*b"fraction");
16191606
pub NewAssetSymbol: BoundedVec<u8, StringLimit> = (*b"FRAC").to_vec().try_into().unwrap();
16201607
pub NewAssetName: BoundedVec<u8, StringLimit> = (*b"Frac").to_vec().try_into().unwrap();
1621-
pub const NftFractionalizationHoldReason: HoldReason = HoldReason::NftFractionalization;
16221608
}
16231609

16241610
impl pallet_nft_fractionalization::Config for Runtime {
@@ -1636,7 +1622,7 @@ impl pallet_nft_fractionalization::Config for Runtime {
16361622
type Nfts = Nfts;
16371623
type PalletId = NftFractionalizationPalletId;
16381624
type WeightInfo = pallet_nft_fractionalization::weights::SubstrateWeight<Runtime>;
1639-
type HoldReason = NftFractionalizationHoldReason;
1625+
type RuntimeHoldReason = RuntimeHoldReason;
16401626
#[cfg(feature = "runtime-benchmarks")]
16411627
type BenchmarkHelper = ();
16421628
}

client/executor/benches/bench.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ use sc_executor_common::{
2525
};
2626
use sc_executor_wasmtime::InstantiationStrategy;
2727
use sc_runtime_test::wasm_binary_unwrap as test_runtime;
28-
use sp_wasm_interface::HostFunctions as _;
2928
use std::sync::{
3029
atomic::{AtomicBool, AtomicUsize, Ordering},
3130
Arc,

frame/alliance/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl pallet_balances::Config for Test {
8989
type ReserveIdentifier = [u8; 8];
9090
type FreezeIdentifier = ();
9191
type MaxFreezes = ();
92-
type HoldIdentifier = ();
92+
type RuntimeHoldReason = ();
9393
type MaxHolds = ();
9494
}
9595

frame/asset-rate/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl pallet_balances::Config for Test {
7777
type MaxLocks = ();
7878
type MaxReserves = ();
7979
type ReserveIdentifier = [u8; 8];
80-
type HoldIdentifier = ();
80+
type RuntimeHoldReason = RuntimeHoldReason;
8181
type FreezeIdentifier = ();
8282
type MaxHolds = ();
8383
type MaxFreezes = ();

frame/assets/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl pallet_balances::Config for Test {
8787
type MaxLocks = ();
8888
type MaxReserves = ();
8989
type ReserveIdentifier = [u8; 8];
90-
type HoldIdentifier = ();
90+
type RuntimeHoldReason = ();
9191
type FreezeIdentifier = ();
9292
type MaxHolds = ();
9393
type MaxFreezes = ();

frame/atomic-swap/src/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl pallet_balances::Config for Test {
6464
type WeightInfo = ();
6565
type FreezeIdentifier = ();
6666
type MaxFreezes = ();
67-
type HoldIdentifier = ();
67+
type RuntimeHoldReason = ();
6868
type MaxHolds = ();
6969
}
7070

frame/babe/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl pallet_balances::Config for Test {
145145
type WeightInfo = ();
146146
type FreezeIdentifier = ();
147147
type MaxFreezes = ();
148-
type HoldIdentifier = ();
148+
type RuntimeHoldReason = ();
149149
type MaxHolds = ();
150150
}
151151

frame/balances/src/impl_fungible.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<T: Config<I>, I: 'static> fungible::Mutate<T::AccountId> for Pallet<T, I> {
207207
impl<T: Config<I>, I: 'static> fungible::MutateHold<T::AccountId> for Pallet<T, I> {}
208208

209209
impl<T: Config<I>, I: 'static> fungible::InspectHold<T::AccountId> for Pallet<T, I> {
210-
type Reason = T::HoldIdentifier;
210+
type Reason = T::RuntimeHoldReason;
211211

212212
fn total_balance_on_hold(who: &T::AccountId) -> T::Balance {
213213
Self::account(who).reserved

frame/balances/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ pub mod pallet {
257257
/// Use of reserves is deprecated in favour of holds. See `https://github.com/paritytech/substrate/pull/12951/`
258258
type ReserveIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy;
259259

260-
/// The ID type for holds.
261-
type HoldIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy;
260+
/// The overarching hold reason.
261+
type RuntimeHoldReason: Parameter + Member + MaxEncodedLen + Ord + Copy;
262262

263263
/// The ID type for freezes.
264264
type FreezeIdentifier: Parameter + Member + MaxEncodedLen + Ord + Copy;
@@ -437,7 +437,7 @@ pub mod pallet {
437437
_,
438438
Blake2_128Concat,
439439
T::AccountId,
440-
BoundedVec<IdAmount<T::HoldIdentifier, T::Balance>, T::MaxHolds>,
440+
BoundedVec<IdAmount<T::RuntimeHoldReason, T::Balance>, T::MaxHolds>,
441441
ValueQuery,
442442
>;
443443

0 commit comments

Comments
 (0)