mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 11:41:02 +00:00
Add nonfungibles::Create Trait & Implement for Uniques (#9438)
* Add nonfungibles::Create Trait & Implement for Uniques Closes #9419 * Formatting * Remove default implementation (`TokenError::Unsupported`) from `Create` trait Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Formatting * Do not wrap parameters in Options * Formatting Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -117,6 +117,12 @@ pub trait InspectEnumerable<AccountId>: Inspect<AccountId> {
|
||||
) -> Box<dyn Iterator<Item = Self::InstanceId>>;
|
||||
}
|
||||
|
||||
/// Trait for providing the ability to create classes of nonfungible assets.
|
||||
pub trait Create<AccountId>: Inspect<AccountId> {
|
||||
/// Create a `class` of nonfungible assets to be owned by `who` and managed by `admin`.
|
||||
fn create_class(class: &Self::ClassId, who: &AccountId, admin: &AccountId) -> DispatchResult;
|
||||
}
|
||||
|
||||
/// Trait for providing an interface for multiple classes of NFT-like assets which may be minted,
|
||||
/// burned and/or have attributes set on them.
|
||||
pub trait Mutate<AccountId>: Inspect<AccountId> {
|
||||
|
||||
@@ -48,6 +48,38 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn do_create_class(
|
||||
class: T::ClassId,
|
||||
owner: T::AccountId,
|
||||
admin: T::AccountId,
|
||||
deposit: DepositBalanceOf<T, I>,
|
||||
free_holding: bool,
|
||||
event: Event<T, I>,
|
||||
) -> DispatchResult {
|
||||
ensure!(!Class::<T, I>::contains_key(class), Error::<T, I>::InUse);
|
||||
|
||||
T::Currency::reserve(&owner, deposit)?;
|
||||
|
||||
Class::<T, I>::insert(
|
||||
class,
|
||||
ClassDetails {
|
||||
owner: owner.clone(),
|
||||
issuer: admin.clone(),
|
||||
admin: admin.clone(),
|
||||
freezer: admin.clone(),
|
||||
total_deposit: deposit,
|
||||
free_holding,
|
||||
instances: 0,
|
||||
instance_metadatas: 0,
|
||||
attributes: 0,
|
||||
is_frozen: false,
|
||||
},
|
||||
);
|
||||
|
||||
Self::deposit_event(event);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn do_mint(
|
||||
class: T::ClassId,
|
||||
instance: T::InstanceId,
|
||||
|
||||
@@ -19,7 +19,10 @@
|
||||
|
||||
use super::*;
|
||||
use frame_support::{
|
||||
traits::tokens::nonfungibles::{Inspect, InspectEnumerable, Mutate, Transfer},
|
||||
traits::{
|
||||
tokens::nonfungibles::{Create, Inspect, InspectEnumerable, Mutate, Transfer},
|
||||
Get,
|
||||
},
|
||||
BoundedSlice,
|
||||
};
|
||||
use sp_runtime::DispatchResult;
|
||||
@@ -85,6 +88,24 @@ impl<T: Config<I>, I: 'static> Inspect<<T as SystemConfig>::AccountId> for Palle
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: 'static> Create<<T as SystemConfig>::AccountId> for Pallet<T, I> {
|
||||
/// Create a `class` of nonfungible assets to be owned by `who` and managed by `admin`.
|
||||
fn create_class(
|
||||
class: &Self::ClassId,
|
||||
who: &T::AccountId,
|
||||
admin: &T::AccountId,
|
||||
) -> DispatchResult {
|
||||
Self::do_create_class(
|
||||
class.clone(),
|
||||
who.clone(),
|
||||
admin.clone(),
|
||||
T::ClassDeposit::get(),
|
||||
false,
|
||||
Event::Created(class.clone(), who.clone(), admin.clone()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Config<I>, I: 'static> Mutate<<T as SystemConfig>::AccountId> for Pallet<T, I> {
|
||||
fn mint_into(
|
||||
class: &Self::ClassId,
|
||||
|
||||
@@ -316,28 +316,14 @@ pub mod pallet {
|
||||
let owner = ensure_signed(origin)?;
|
||||
let admin = T::Lookup::lookup(admin)?;
|
||||
|
||||
ensure!(!Class::<T, I>::contains_key(class), Error::<T, I>::InUse);
|
||||
|
||||
let deposit = T::ClassDeposit::get();
|
||||
T::Currency::reserve(&owner, deposit)?;
|
||||
|
||||
Class::<T, I>::insert(
|
||||
Self::do_create_class(
|
||||
class,
|
||||
ClassDetails {
|
||||
owner: owner.clone(),
|
||||
issuer: admin.clone(),
|
||||
admin: admin.clone(),
|
||||
freezer: admin.clone(),
|
||||
total_deposit: deposit,
|
||||
free_holding: false,
|
||||
instances: 0,
|
||||
instance_metadatas: 0,
|
||||
attributes: 0,
|
||||
is_frozen: false,
|
||||
},
|
||||
);
|
||||
Self::deposit_event(Event::Created(class, owner, admin));
|
||||
Ok(())
|
||||
owner.clone(),
|
||||
admin.clone(),
|
||||
T::ClassDeposit::get(),
|
||||
false,
|
||||
Event::Created(class, owner, admin),
|
||||
)
|
||||
}
|
||||
|
||||
/// Issue a new class of non-fungible assets from a privileged origin.
|
||||
@@ -366,25 +352,14 @@ pub mod pallet {
|
||||
T::ForceOrigin::ensure_origin(origin)?;
|
||||
let owner = T::Lookup::lookup(owner)?;
|
||||
|
||||
ensure!(!Class::<T, I>::contains_key(class), Error::<T, I>::InUse);
|
||||
|
||||
Class::<T, I>::insert(
|
||||
Self::do_create_class(
|
||||
class,
|
||||
ClassDetails {
|
||||
owner: owner.clone(),
|
||||
issuer: owner.clone(),
|
||||
admin: owner.clone(),
|
||||
freezer: owner.clone(),
|
||||
total_deposit: Zero::zero(),
|
||||
free_holding,
|
||||
instances: 0,
|
||||
instance_metadatas: 0,
|
||||
attributes: 0,
|
||||
is_frozen: false,
|
||||
},
|
||||
);
|
||||
Self::deposit_event(Event::ForceCreated(class, owner));
|
||||
Ok(())
|
||||
owner.clone(),
|
||||
owner.clone(),
|
||||
Zero::zero(),
|
||||
free_holding,
|
||||
Event::ForceCreated(class, owner),
|
||||
)
|
||||
}
|
||||
|
||||
/// Destroy a class of fungible assets.
|
||||
|
||||
Reference in New Issue
Block a user