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

Commit 6abfae6

Browse files
committed
Add amalgamation traits for NFT CollectionId, ItemId, and DestroyWitness
1 parent 48e7cb1 commit 6abfae6

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

frame/support/src/traits/tokens.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub mod nonfungibles;
2828
pub mod nonfungibles_v2;
2929
pub use imbalance::Imbalance;
3030
pub use misc::{
31-
AssetId, AttributeNamespace, Balance, BalanceConversion, BalanceStatus, ConvertRank,
32-
DepositConsequence, ExistenceRequirement, GetSalary, Locker, WithdrawConsequence,
33-
WithdrawReasons,
31+
AssetId, AttributeNamespace, Balance, BalanceConversion, BalanceStatus,
32+
CollectionId, ConvertRank, DepositConsequence, DestroyWitness, ExistenceRequirement,
33+
GetSalary, ItemId, Locker, WithdrawConsequence, WithdrawReasons,
3434
};

frame/support/src/traits/tokens/misc.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,36 @@ pub trait BalanceConversion<InBalance, AssetId, OutBalance> {
210210
fn to_asset_balance(balance: InBalance, asset_id: AssetId) -> Result<OutBalance, Self::Error>;
211211
}
212212

213+
/// Simple amalgamation trait to collect together properties for a CollectionId under one roof.
214+
pub trait CollectionId:
215+
FullCodec + Copy + Eq + PartialEq + Debug + scale_info::TypeInfo + MaxEncodedLen
216+
{
217+
}
218+
impl<T: FullCodec + Copy + Eq + PartialEq + Debug + scale_info::TypeInfo + MaxEncodedLen> CollectionId
219+
for T
220+
{
221+
}
222+
223+
/// Simple amalgamation trait to collect together properties for an ItemId under one roof.
224+
pub trait ItemId:
225+
FullCodec + Copy + Eq + PartialEq + Debug + scale_info::TypeInfo + MaxEncodedLen
226+
{
227+
}
228+
impl<T: FullCodec + Copy + Eq + PartialEq + Debug + scale_info::TypeInfo + MaxEncodedLen> ItemId
229+
for T
230+
{
231+
}
232+
233+
/// Simple amalgamation trait to collect together properties for a DestroyWitness under one roof.
234+
pub trait DestroyWitness:
235+
FullCodec + Copy + Eq + PartialEq + Debug + scale_info::TypeInfo + MaxEncodedLen
236+
{
237+
}
238+
impl<T: FullCodec + Copy + Eq + PartialEq + Debug + scale_info::TypeInfo + MaxEncodedLen> DestroyWitness
239+
for T
240+
{
241+
}
242+
213243
/// Trait to handle asset locking mechanism to ensure interactions with the asset can be implemented
214244
/// downstream to extend logic of Uniques current functionality.
215245
pub trait Locker<CollectionId, ItemId> {

frame/support/src/traits/tokens/nonfungible_v2.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,18 @@
2525
//! use.
2626
2727
use super::nonfungibles_v2 as nonfungibles;
28-
use crate::{dispatch::DispatchResult, traits::Get};
28+
use crate::{
29+
dispatch::DispatchResult,
30+
traits::{tokens::ItemId, Get}
31+
};
2932
use codec::{Decode, Encode};
3033
use sp_runtime::TokenError;
3134
use sp_std::prelude::*;
3235

3336
/// Trait for providing an interface to a read-only NFT-like item.
3437
pub trait Inspect<AccountId> {
3538
/// Type for identifying an item.
36-
type ItemId;
39+
type ItemId: ItemId;
3740

3841
/// Returns the owner of `item`, or `None` if the item doesn't exist or has no
3942
/// owner.

frame/support/src/traits/tokens/nonfungibles_v2.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
//! Implementations of these traits may be converted to implementations of corresponding
2828
//! `nonfungible` traits by using the `nonfungible::ItemOf` type adapter.
2929
30+
use crate::traits::tokens::{CollectionId, ItemId, DestroyWitness};
3031
use crate::dispatch::{DispatchError, DispatchResult};
3132
use codec::{Decode, Encode};
3233
use sp_runtime::TokenError;
@@ -35,11 +36,11 @@ use sp_std::prelude::*;
3536
/// Trait for providing an interface to many read-only NFT-like sets of items.
3637
pub trait Inspect<AccountId> {
3738
/// Type for identifying an item.
38-
type ItemId;
39+
type ItemId: ItemId;
3940

4041
/// Type for identifying a collection (an identifier for an independent collection of
4142
/// items).
42-
type CollectionId;
43+
type CollectionId: CollectionId;
4344

4445
/// Returns the owner of `item` of `collection`, or `None` if the item doesn't exist
4546
/// (or somehow has no owner).
@@ -193,7 +194,7 @@ pub trait Create<AccountId, CollectionConfig>: Inspect<AccountId> {
193194
/// Trait for providing the ability to destroy collections of nonfungible items.
194195
pub trait Destroy<AccountId>: Inspect<AccountId> {
195196
/// The witness data needed to destroy an item.
196-
type DestroyWitness;
197+
type DestroyWitness: DestroyWitness;
197198

198199
/// Provide the appropriate witness data needed to destroy an item.
199200
fn get_destroy_witness(collection: &Self::CollectionId) -> Option<Self::DestroyWitness>;

0 commit comments

Comments
 (0)