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

Commit

Permalink
Add amalgamation traits for NFT CollectionId and ItemId
Browse files Browse the repository at this point in the history
  • Loading branch information
jasl committed Mar 2, 2023
1 parent d1d67cd commit 04fe4b8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
20 changes: 20 additions & 0 deletions frame/support/src/traits/tokens/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,26 @@ pub trait BalanceConversion<InBalance, AssetId, OutBalance> {
fn to_asset_balance(balance: InBalance, asset_id: AssetId) -> Result<OutBalance, Self::Error>;
}

/// Simple amalgamation trait to collect together properties for an CollectionId under one roof.
pub trait CollectionId:
FullCodec + Copy + Eq + PartialEq + Debug + scale_info::TypeInfo + MaxEncodedLen
{
}
impl<T: FullCodec + Copy + Eq + PartialEq + Debug + scale_info::TypeInfo + MaxEncodedLen> CollectionId
for T
{
}

/// Simple amalgamation trait to collect together properties for an ItemId under one roof.
pub trait ItemId:
FullCodec + Copy + Eq + PartialEq + Debug + scale_info::TypeInfo + MaxEncodedLen
{
}
impl<T: FullCodec + Copy + Eq + PartialEq + Debug + scale_info::TypeInfo + MaxEncodedLen> ItemId
for T
{
}

/// 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<CollectionId, ItemId> {
Expand Down
3 changes: 2 additions & 1 deletion frame/support/src/traits/tokens/nonfungible_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//! For an NFT API that has dual-level namespacing, the traits in `nonfungibles` are better to
//! use.

use super::misc::ItemId;
use super::nonfungibles_v2 as nonfungibles;
use crate::{dispatch::DispatchResult, traits::Get};
use codec::{Decode, Encode};
Expand All @@ -33,7 +34,7 @@ use sp_std::prelude::*;
/// Trait for providing an interface to a read-only NFT-like item.
pub trait Inspect<AccountId> {
/// Type for identifying an item.
type ItemId;
type ItemId: ItemId;

/// Returns the owner of `item`, or `None` if the item doesn't exist or has no
/// owner.
Expand Down
5 changes: 3 additions & 2 deletions frame/support/src/traits/tokens/nonfungibles_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
//! Implementations of these traits may be converted to implementations of corresponding
//! `nonfungible` traits by using the `nonfungible::ItemOf` type adapter.

use super::misc::{CollectionId, ItemId};
use crate::dispatch::{DispatchError, DispatchResult};
use codec::{Decode, Encode};
use sp_runtime::TokenError;
Expand All @@ -35,11 +36,11 @@ use sp_std::prelude::*;
/// Trait for providing an interface to many read-only NFT-like sets of items.
pub trait Inspect<AccountId> {
/// Type for identifying an item.
type ItemId;
type ItemId: ItemId;

/// Type for identifying a collection (an identifier for an independent collection of
/// items).
type CollectionId;
type CollectionId: CollectionId;

/// Returns the owner of `item` of `collection`, or `None` if the item doesn't exist
/// (or somehow has no owner).
Expand Down

0 comments on commit 04fe4b8

Please sign in to comment.