mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-23 20:05:49 +00:00
Dependency Injection Trait Locker for Uniques Pallet (#11025)
* Create a dependency injection trait named Locker that can be implemented downstream to enable locking of an asset. Use case defined in RMRK substrate pallet PR76 * Formatting * Change impl Locker function name to is_locked * Remove unused import * Add docstring header * Remove impl_locker file and add Locker trait to frame_support::traits * Expose Locker from frame_support::traits::misc * Formatting * Move to tokens folder * Move to tokens folder * Format and remove Locker from misc traits * Punctuation * Update frame/support/src/traits/tokens/misc.rs Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Giles Cope <gilescope@gmail.com>
This commit is contained in:
@@ -1407,6 +1407,7 @@ impl pallet_uniques::Config for Runtime {
|
|||||||
#[cfg(feature = "runtime-benchmarks")]
|
#[cfg(feature = "runtime-benchmarks")]
|
||||||
type Helper = ();
|
type Helper = ();
|
||||||
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
|
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
|
||||||
|
type Locker = ();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl pallet_transaction_storage::Config for Runtime {
|
impl pallet_transaction_storage::Config for Runtime {
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ pub use tokens::{
|
|||||||
},
|
},
|
||||||
fungible, fungibles,
|
fungible, fungibles,
|
||||||
imbalance::{Imbalance, OnUnbalanced, SignedImbalance},
|
imbalance::{Imbalance, OnUnbalanced, SignedImbalance},
|
||||||
BalanceStatus, ExistenceRequirement, WithdrawReasons,
|
BalanceStatus, ExistenceRequirement, Locker, WithdrawReasons,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod members;
|
mod members;
|
||||||
|
|||||||
@@ -27,5 +27,5 @@ pub mod nonfungibles;
|
|||||||
pub use imbalance::Imbalance;
|
pub use imbalance::Imbalance;
|
||||||
pub use misc::{
|
pub use misc::{
|
||||||
AssetId, Balance, BalanceConversion, BalanceStatus, DepositConsequence, ExistenceRequirement,
|
AssetId, Balance, BalanceConversion, BalanceStatus, DepositConsequence, ExistenceRequirement,
|
||||||
WithdrawConsequence, WithdrawReasons,
|
Locker, WithdrawConsequence, WithdrawReasons,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -179,3 +179,19 @@ pub trait BalanceConversion<InBalance, AssetId, OutBalance> {
|
|||||||
type Error;
|
type Error;
|
||||||
fn to_asset_balance(balance: InBalance, asset_id: AssetId) -> Result<OutBalance, Self::Error>;
|
fn to_asset_balance(balance: InBalance, asset_id: AssetId) -> Result<OutBalance, Self::Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Trait to handle asset locking mechanism to ensure interactions with the asset can be implemented
|
||||||
|
/// downstream to extend logic of Uniques current functionality.
|
||||||
|
pub trait Locker<ClassId, InstanceId> {
|
||||||
|
/// Check if the asset should be locked and prevent interactions with the asset from executing.
|
||||||
|
fn is_locked(class: ClassId, instance: InstanceId) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<ClassId, InstanceId> Locker<ClassId, InstanceId> for () {
|
||||||
|
// Default will be false if not implemented downstream.
|
||||||
|
// Note: The logic check in this function must be constant time and consistent for benchmarks
|
||||||
|
// to work.
|
||||||
|
fn is_locked(_class: ClassId, _instance: InstanceId) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
|||||||
) -> DispatchResult {
|
) -> DispatchResult {
|
||||||
let class_details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::UnknownClass)?;
|
let class_details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::UnknownClass)?;
|
||||||
ensure!(!class_details.is_frozen, Error::<T, I>::Frozen);
|
ensure!(!class_details.is_frozen, Error::<T, I>::Frozen);
|
||||||
|
ensure!(!T::Locker::is_locked(class, instance), Error::<T, I>::Locked);
|
||||||
|
|
||||||
let mut details =
|
let mut details =
|
||||||
Asset::<T, I>::get(&class, &instance).ok_or(Error::<T, I>::UnknownClass)?;
|
Asset::<T, I>::get(&class, &instance).ok_or(Error::<T, I>::UnknownClass)?;
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ pub mod weights;
|
|||||||
|
|
||||||
use codec::{Decode, Encode};
|
use codec::{Decode, Encode};
|
||||||
use frame_support::traits::{
|
use frame_support::traits::{
|
||||||
BalanceStatus::Reserved, Currency, EnsureOriginWithArg, ReservableCurrency,
|
tokens::Locker, BalanceStatus::Reserved, Currency, EnsureOriginWithArg, ReservableCurrency,
|
||||||
};
|
};
|
||||||
use frame_system::Config as SystemConfig;
|
use frame_system::Config as SystemConfig;
|
||||||
use sp_runtime::{
|
use sp_runtime::{
|
||||||
@@ -108,6 +108,9 @@ pub mod pallet {
|
|||||||
Self::ClassId,
|
Self::ClassId,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
/// Locker trait to enable Locking mechanism downstream.
|
||||||
|
type Locker: Locker<Self::ClassId, Self::InstanceId>;
|
||||||
|
|
||||||
/// The basic amount of funds that must be reserved for an asset class.
|
/// The basic amount of funds that must be reserved for an asset class.
|
||||||
#[pallet::constant]
|
#[pallet::constant]
|
||||||
type ClassDeposit: Get<DepositBalanceOf<Self, I>>;
|
type ClassDeposit: Get<DepositBalanceOf<Self, I>>;
|
||||||
@@ -352,6 +355,8 @@ pub mod pallet {
|
|||||||
Unapproved,
|
Unapproved,
|
||||||
/// The named owner has not signed ownership of the class is acceptable.
|
/// The named owner has not signed ownership of the class is acceptable.
|
||||||
Unaccepted,
|
Unaccepted,
|
||||||
|
/// The asset instance is locked.
|
||||||
|
Locked,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ impl Config for Test {
|
|||||||
type Currency = Balances;
|
type Currency = Balances;
|
||||||
type CreateOrigin = AsEnsureOriginWithArg<frame_system::EnsureSigned<u64>>;
|
type CreateOrigin = AsEnsureOriginWithArg<frame_system::EnsureSigned<u64>>;
|
||||||
type ForceOrigin = frame_system::EnsureRoot<u64>;
|
type ForceOrigin = frame_system::EnsureRoot<u64>;
|
||||||
|
type Locker = ();
|
||||||
type ClassDeposit = ConstU64<2>;
|
type ClassDeposit = ConstU64<2>;
|
||||||
type InstanceDeposit = ConstU64<1>;
|
type InstanceDeposit = ConstU64<1>;
|
||||||
type MetadataDepositBase = ConstU64<1>;
|
type MetadataDepositBase = ConstU64<1>;
|
||||||
|
|||||||
Reference in New Issue
Block a user