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

Dependency Injection Trait Locker for Uniques Pallet #11025

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,7 @@ impl pallet_uniques::Config for Runtime {
#[cfg(feature = "runtime-benchmarks")]
type Helper = ();
type CreateOrigin = AsEnsureOriginWithArg<EnsureSigned<AccountId>>;
type Locker = ();
}

impl pallet_transaction_storage::Config for Runtime {
Expand Down
1 change: 1 addition & 0 deletions frame/uniques/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
) -> DispatchResult {
let class_details = Class::<T, I>::get(&class).ok_or(Error::<T, I>::UnknownClass)?;
ensure!(!class_details.is_frozen, Error::<T, I>::Frozen);
ensure!(!T::Locker::is_locked(class, instance), Error::<T, I>::Locked);

let mut details =
Asset::<T, I>::get(&class, &instance).ok_or(Error::<T, I>::UnknownClass)?;
Expand Down
33 changes: 33 additions & 0 deletions frame/uniques/src/impl_locker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// This file is part of Substrate.

// Copyright (C) 2017-2022 Parity Technologies (UK) Ltd.
HashWarlock marked this conversation as resolved.
Show resolved Hide resolved
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Implementation for `Locker` trait

/// Trait to handle asset locking mechanism to ensure interactions with the asset can be implemented
/// downstream to extend logic of Uniques current functionality
#[allow(clippy::upper_case_acronyms)]
HashWarlock marked this conversation as resolved.
Show resolved Hide resolved
pub trait Locker<ClassId, InstanceId> {
shawntabrizi marked this conversation as resolved.
Show resolved Hide resolved
/// Check if the asset should be locked and prevent interactions with the asset from executing.
/// Default will be false if not implemented downstream
fn is_locked(class: ClassId, instance: InstanceId) -> bool;
HashWarlock marked this conversation as resolved.
Show resolved Hide resolved
}

impl<ClassId, InstanceId> Locker<ClassId, InstanceId> for () {
fn is_locked(_class: ClassId, _instance: InstanceId) -> bool {
false
}
}
7 changes: 7 additions & 0 deletions frame/uniques/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub mod mock;
mod tests;

mod functions;
mod impl_locker;
mod impl_nonfungibles;
mod types;

Expand All @@ -52,6 +53,7 @@ use sp_runtime::{
};
use sp_std::prelude::*;

pub use impl_locker::Locker;
pub use pallet::*;
pub use types::*;
pub use weights::WeightInfo;
Expand Down Expand Up @@ -108,6 +110,9 @@ pub mod pallet {
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.
#[pallet::constant]
type ClassDeposit: Get<DepositBalanceOf<Self, I>>;
Expand Down Expand Up @@ -352,6 +357,8 @@ pub mod pallet {
Unapproved,
/// The named owner has not signed ownership of the class is acceptable.
Unaccepted,
/// The asset instance is locked.
Locked,
}

impl<T: Config<I>, I: 'static> Pallet<T, I> {
Expand Down
1 change: 1 addition & 0 deletions frame/uniques/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl Config for Test {
type Currency = Balances;
type CreateOrigin = AsEnsureOriginWithArg<frame_system::EnsureSigned<u64>>;
type ForceOrigin = frame_system::EnsureRoot<u64>;
type Locker = ();
type ClassDeposit = ConstU64<2>;
type InstanceDeposit = ConstU64<1>;
type MetadataDepositBase = ConstU64<1>;
Expand Down