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

Add amalgamation traits for NFT CollectionId and ItemId #13514

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Apply @bkchr suggests
  • Loading branch information
jasl committed Mar 9, 2023
commit cc29fe6a6237e646bfe9fbdf745da111986c36b2
4 changes: 2 additions & 2 deletions frame/support/src/traits/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub mod nonfungibles;
pub mod nonfungibles_v2;
pub use imbalance::Imbalance;
pub use misc::{
AssetId, AttributeNamespace, Balance, BalanceConversion, BalanceStatus, CollectionId,
ConvertRank, DepositConsequence, DestroyWitness, ExistenceRequirement, GetSalary, ItemId,
AssetId, AttributeNamespace, Balance, BalanceConversion, BalanceStatus,
ConvertRank, DepositConsequence, ExistenceRequirement, GetSalary,
Locker, WithdrawConsequence, WithdrawReasons,
};
30 changes: 0 additions & 30 deletions frame/support/src/traits/tokens/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,36 +210,6 @@ 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 a 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
{
}

/// Simple amalgamation trait to collect together properties for a DestroyWitness under one roof.
pub trait DestroyWitness:
FullCodec + Copy + Eq + PartialEq + Debug + scale_info::TypeInfo + MaxEncodedLen
{
}
impl<T: FullCodec + Copy + Eq + PartialEq + Debug + scale_info::TypeInfo + MaxEncodedLen>
DestroyWitness 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
6 changes: 3 additions & 3 deletions frame/support/src/traits/tokens/nonfungible_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

use super::nonfungibles_v2 as nonfungibles;
use crate::{
dispatch::DispatchResult,
traits::{tokens::ItemId, Get},
dispatch::{DispatchResult, Parameter},
traits::Get,
};
use codec::{Decode, Encode};
use sp_runtime::TokenError;
Expand All @@ -36,7 +36,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: ItemId;
type ItemId: Parameter;

/// Returns the owner of `item`, or `None` if the item doesn't exist or has no
/// owner.
Expand Down
9 changes: 4 additions & 5 deletions frame/support/src/traits/tokens/nonfungibles_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
//! `nonfungible` traits by using the `nonfungible::ItemOf` type adapter.

use crate::{
dispatch::{DispatchError, DispatchResult},
traits::tokens::{CollectionId, DestroyWitness, ItemId},
dispatch::{DispatchError, DispatchResult, Parameter},
};
use codec::{Decode, Encode};
use sp_runtime::TokenError;
Expand All @@ -38,11 +37,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: ItemId;
type ItemId: Parameter;

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

/// Returns the owner of `item` of `collection`, or `None` if the item doesn't exist
/// (or somehow has no owner).
Expand Down Expand Up @@ -196,7 +195,7 @@ pub trait Create<AccountId, CollectionConfig>: Inspect<AccountId> {
/// Trait for providing the ability to destroy collections of nonfungible items.
pub trait Destroy<AccountId>: Inspect<AccountId> {
/// The witness data needed to destroy an item.
type DestroyWitness: DestroyWitness;
type DestroyWitness: Parameter;

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