mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 14:01: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>>;
|
) -> 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,
|
/// Trait for providing an interface for multiple classes of NFT-like assets which may be minted,
|
||||||
/// burned and/or have attributes set on them.
|
/// burned and/or have attributes set on them.
|
||||||
pub trait Mutate<AccountId>: Inspect<AccountId> {
|
pub trait Mutate<AccountId>: Inspect<AccountId> {
|
||||||
|
|||||||
@@ -48,6 +48,38 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
|
|||||||
Ok(())
|
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(
|
pub(super) fn do_mint(
|
||||||
class: T::ClassId,
|
class: T::ClassId,
|
||||||
instance: T::InstanceId,
|
instance: T::InstanceId,
|
||||||
|
|||||||
@@ -19,7 +19,10 @@
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use frame_support::{
|
use frame_support::{
|
||||||
traits::tokens::nonfungibles::{Inspect, InspectEnumerable, Mutate, Transfer},
|
traits::{
|
||||||
|
tokens::nonfungibles::{Create, Inspect, InspectEnumerable, Mutate, Transfer},
|
||||||
|
Get,
|
||||||
|
},
|
||||||
BoundedSlice,
|
BoundedSlice,
|
||||||
};
|
};
|
||||||
use sp_runtime::DispatchResult;
|
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> {
|
impl<T: Config<I>, I: 'static> Mutate<<T as SystemConfig>::AccountId> for Pallet<T, I> {
|
||||||
fn mint_into(
|
fn mint_into(
|
||||||
class: &Self::ClassId,
|
class: &Self::ClassId,
|
||||||
|
|||||||
@@ -316,28 +316,14 @@ pub mod pallet {
|
|||||||
let owner = ensure_signed(origin)?;
|
let owner = ensure_signed(origin)?;
|
||||||
let admin = T::Lookup::lookup(admin)?;
|
let admin = T::Lookup::lookup(admin)?;
|
||||||
|
|
||||||
ensure!(!Class::<T, I>::contains_key(class), Error::<T, I>::InUse);
|
Self::do_create_class(
|
||||||
|
|
||||||
let deposit = T::ClassDeposit::get();
|
|
||||||
T::Currency::reserve(&owner, deposit)?;
|
|
||||||
|
|
||||||
Class::<T, I>::insert(
|
|
||||||
class,
|
class,
|
||||||
ClassDetails {
|
owner.clone(),
|
||||||
owner: owner.clone(),
|
admin.clone(),
|
||||||
issuer: admin.clone(),
|
T::ClassDeposit::get(),
|
||||||
admin: admin.clone(),
|
false,
|
||||||
freezer: admin.clone(),
|
Event::Created(class, owner, admin),
|
||||||
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(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Issue a new class of non-fungible assets from a privileged origin.
|
/// Issue a new class of non-fungible assets from a privileged origin.
|
||||||
@@ -366,25 +352,14 @@ pub mod pallet {
|
|||||||
T::ForceOrigin::ensure_origin(origin)?;
|
T::ForceOrigin::ensure_origin(origin)?;
|
||||||
let owner = T::Lookup::lookup(owner)?;
|
let owner = T::Lookup::lookup(owner)?;
|
||||||
|
|
||||||
ensure!(!Class::<T, I>::contains_key(class), Error::<T, I>::InUse);
|
Self::do_create_class(
|
||||||
|
|
||||||
Class::<T, I>::insert(
|
|
||||||
class,
|
class,
|
||||||
ClassDetails {
|
owner.clone(),
|
||||||
owner: owner.clone(),
|
owner.clone(),
|
||||||
issuer: owner.clone(),
|
Zero::zero(),
|
||||||
admin: owner.clone(),
|
free_holding,
|
||||||
freezer: owner.clone(),
|
Event::ForceCreated(class, owner),
|
||||||
total_deposit: Zero::zero(),
|
)
|
||||||
free_holding,
|
|
||||||
instances: 0,
|
|
||||||
instance_metadatas: 0,
|
|
||||||
attributes: 0,
|
|
||||||
is_frozen: false,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
Self::deposit_event(Event::ForceCreated(class, owner));
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destroy a class of fungible assets.
|
/// Destroy a class of fungible assets.
|
||||||
|
|||||||
Reference in New Issue
Block a user