From b2e3b88e90e2b19d3036311cf57c430b70a20d71 Mon Sep 17 00:00:00 2001 From: jasl Date: Thu, 9 Mar 2023 19:43:43 +0800 Subject: [PATCH 1/3] Add amalgamation traits for NFT CollectionId, ItemId, and DestroyWitness --- frame/support/src/traits/tokens.rs | 6 ++-- frame/support/src/traits/tokens/misc.rs | 30 +++++++++++++++++++ .../src/traits/tokens/nonfungible_v2.rs | 7 +++-- .../src/traits/tokens/nonfungibles_v2.rs | 11 ++++--- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/frame/support/src/traits/tokens.rs b/frame/support/src/traits/tokens.rs index f8dcf68159f1a..1d62d65022c83 100644 --- a/frame/support/src/traits/tokens.rs +++ b/frame/support/src/traits/tokens.rs @@ -28,7 +28,7 @@ pub mod nonfungibles; pub mod nonfungibles_v2; pub use imbalance::Imbalance; pub use misc::{ - AssetId, AttributeNamespace, Balance, BalanceConversion, BalanceStatus, ConvertRank, - DepositConsequence, ExistenceRequirement, GetSalary, Locker, WithdrawConsequence, - WithdrawReasons, + AssetId, AttributeNamespace, Balance, BalanceConversion, BalanceStatus, CollectionId, + ConvertRank, DepositConsequence, DestroyWitness, ExistenceRequirement, GetSalary, ItemId, + Locker, WithdrawConsequence, WithdrawReasons, }; diff --git a/frame/support/src/traits/tokens/misc.rs b/frame/support/src/traits/tokens/misc.rs index eff65f3620a32..221c02cd4b508 100644 --- a/frame/support/src/traits/tokens/misc.rs +++ b/frame/support/src/traits/tokens/misc.rs @@ -210,6 +210,36 @@ pub trait BalanceConversion { fn to_asset_balance(balance: InBalance, asset_id: AssetId) -> Result; } +/// 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 + 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 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 + 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 { diff --git a/frame/support/src/traits/tokens/nonfungible_v2.rs b/frame/support/src/traits/tokens/nonfungible_v2.rs index 175d94324aaa4..c430917577899 100644 --- a/frame/support/src/traits/tokens/nonfungible_v2.rs +++ b/frame/support/src/traits/tokens/nonfungible_v2.rs @@ -25,7 +25,10 @@ //! use. use super::nonfungibles_v2 as nonfungibles; -use crate::{dispatch::DispatchResult, traits::Get}; +use crate::{ + dispatch::DispatchResult, + traits::{tokens::ItemId, Get}, +}; use codec::{Decode, Encode}; use sp_runtime::TokenError; use sp_std::prelude::*; @@ -33,7 +36,7 @@ use sp_std::prelude::*; /// Trait for providing an interface to a read-only NFT-like item. pub trait Inspect { /// 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. diff --git a/frame/support/src/traits/tokens/nonfungibles_v2.rs b/frame/support/src/traits/tokens/nonfungibles_v2.rs index 5deb0c568f431..a72cecc939fa1 100644 --- a/frame/support/src/traits/tokens/nonfungibles_v2.rs +++ b/frame/support/src/traits/tokens/nonfungibles_v2.rs @@ -27,7 +27,10 @@ //! Implementations of these traits may be converted to implementations of corresponding //! `nonfungible` traits by using the `nonfungible::ItemOf` type adapter. -use crate::dispatch::{DispatchError, DispatchResult}; +use crate::{ + dispatch::{DispatchError, DispatchResult}, + traits::tokens::{CollectionId, DestroyWitness, ItemId}, +}; use codec::{Decode, Encode}; use sp_runtime::TokenError; use sp_std::prelude::*; @@ -35,11 +38,11 @@ use sp_std::prelude::*; /// Trait for providing an interface to many read-only NFT-like sets of items. pub trait Inspect { /// 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). @@ -193,7 +196,7 @@ pub trait Create: Inspect { /// Trait for providing the ability to destroy collections of nonfungible items. pub trait Destroy: Inspect { /// The witness data needed to destroy an item. - type DestroyWitness; + type DestroyWitness: DestroyWitness; /// Provide the appropriate witness data needed to destroy an item. fn get_destroy_witness(collection: &Self::CollectionId) -> Option; From cc29fe6a6237e646bfe9fbdf745da111986c36b2 Mon Sep 17 00:00:00 2001 From: jasl Date: Thu, 9 Mar 2023 23:41:26 +0800 Subject: [PATCH 2/3] Apply @bkchr suggests --- frame/support/src/traits/tokens.rs | 4 +-- frame/support/src/traits/tokens/misc.rs | 30 ------------------- .../src/traits/tokens/nonfungible_v2.rs | 6 ++-- .../src/traits/tokens/nonfungibles_v2.rs | 9 +++--- 4 files changed, 9 insertions(+), 40 deletions(-) diff --git a/frame/support/src/traits/tokens.rs b/frame/support/src/traits/tokens.rs index 1d62d65022c83..669a1be52a32c 100644 --- a/frame/support/src/traits/tokens.rs +++ b/frame/support/src/traits/tokens.rs @@ -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, }; diff --git a/frame/support/src/traits/tokens/misc.rs b/frame/support/src/traits/tokens/misc.rs index 221c02cd4b508..eff65f3620a32 100644 --- a/frame/support/src/traits/tokens/misc.rs +++ b/frame/support/src/traits/tokens/misc.rs @@ -210,36 +210,6 @@ pub trait BalanceConversion { fn to_asset_balance(balance: InBalance, asset_id: AssetId) -> Result; } -/// 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 - 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 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 - 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 { diff --git a/frame/support/src/traits/tokens/nonfungible_v2.rs b/frame/support/src/traits/tokens/nonfungible_v2.rs index c430917577899..c23bf3e4055b1 100644 --- a/frame/support/src/traits/tokens/nonfungible_v2.rs +++ b/frame/support/src/traits/tokens/nonfungible_v2.rs @@ -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; @@ -36,7 +36,7 @@ use sp_std::prelude::*; /// Trait for providing an interface to a read-only NFT-like item. pub trait Inspect { /// 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. diff --git a/frame/support/src/traits/tokens/nonfungibles_v2.rs b/frame/support/src/traits/tokens/nonfungibles_v2.rs index a72cecc939fa1..1bacf8881d665 100644 --- a/frame/support/src/traits/tokens/nonfungibles_v2.rs +++ b/frame/support/src/traits/tokens/nonfungibles_v2.rs @@ -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; @@ -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 { /// 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). @@ -196,7 +195,7 @@ pub trait Create: Inspect { /// Trait for providing the ability to destroy collections of nonfungible items. pub trait Destroy: Inspect { /// 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; From 6043b1f3371cea054cd13b769d58297e78c0c847 Mon Sep 17 00:00:00 2001 From: command-bot <> Date: Thu, 9 Mar 2023 15:51:17 +0000 Subject: [PATCH 3/3] ".git/.scripts/commands/fmt/fmt.sh" --- frame/support/src/traits/tokens.rs | 6 +++--- frame/support/src/traits/tokens/nonfungibles_v2.rs | 4 +--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/frame/support/src/traits/tokens.rs b/frame/support/src/traits/tokens.rs index 669a1be52a32c..f8dcf68159f1a 100644 --- a/frame/support/src/traits/tokens.rs +++ b/frame/support/src/traits/tokens.rs @@ -28,7 +28,7 @@ pub mod nonfungibles; pub mod nonfungibles_v2; pub use imbalance::Imbalance; pub use misc::{ - AssetId, AttributeNamespace, Balance, BalanceConversion, BalanceStatus, - ConvertRank, DepositConsequence, ExistenceRequirement, GetSalary, - Locker, WithdrawConsequence, WithdrawReasons, + AssetId, AttributeNamespace, Balance, BalanceConversion, BalanceStatus, ConvertRank, + DepositConsequence, ExistenceRequirement, GetSalary, Locker, WithdrawConsequence, + WithdrawReasons, }; diff --git a/frame/support/src/traits/tokens/nonfungibles_v2.rs b/frame/support/src/traits/tokens/nonfungibles_v2.rs index 1bacf8881d665..9d32f29becd4c 100644 --- a/frame/support/src/traits/tokens/nonfungibles_v2.rs +++ b/frame/support/src/traits/tokens/nonfungibles_v2.rs @@ -27,9 +27,7 @@ //! Implementations of these traits may be converted to implementations of corresponding //! `nonfungible` traits by using the `nonfungible::ItemOf` type adapter. -use crate::{ - dispatch::{DispatchError, DispatchResult, Parameter}, -}; +use crate::dispatch::{DispatchError, DispatchResult, Parameter}; use codec::{Decode, Encode}; use sp_runtime::TokenError; use sp_std::prelude::*;