diff --git a/pallets/nfts/src/benchmarking.rs b/pallets/nfts/src/benchmarking.rs index bc81096b..8fa87557 100644 --- a/pallets/nfts/src/benchmarking.rs +++ b/pallets/nfts/src/benchmarking.rs @@ -19,7 +19,6 @@ #![cfg(feature = "runtime-benchmarks")] -use super::*; use enumflags2::{BitFlag, BitFlags}; use frame_benchmarking::v1::{ account, benchmarks_instance_pallet, whitelist_account, whitelisted_caller, BenchmarkError, @@ -32,6 +31,7 @@ use frame_support::{ use frame_system::{pallet_prelude::BlockNumberFor, RawOrigin as SystemOrigin}; use sp_runtime::traits::{Bounded, One}; +use super::*; use crate::Pallet as Nfts; const SEED: u32 = 0; diff --git a/pallets/nfts/src/common_functions.rs b/pallets/nfts/src/common_functions.rs index 2c4778c1..f51de192 100644 --- a/pallets/nfts/src/common_functions.rs +++ b/pallets/nfts/src/common_functions.rs @@ -17,10 +17,12 @@ //! Various pieces of common functionality. -use crate::*; use alloc::vec::Vec; + use frame_support::pallet_prelude::*; +use crate::*; + impl, I: 'static> Pallet { /// Get the owner of the item, if the item exists. pub fn owner(collection: T::CollectionId, item: T::ItemId) -> Option { diff --git a/pallets/nfts/src/features/approvals.rs b/pallets/nfts/src/features/approvals.rs index 053fa671..ad5d93c2 100644 --- a/pallets/nfts/src/features/approvals.rs +++ b/pallets/nfts/src/features/approvals.rs @@ -19,9 +19,10 @@ //! The bitflag [`PalletFeature::Approvals`] needs to be set in [`Config::Features`] for NFTs //! to have the functionality defined in this module. -use crate::*; use frame_support::pallet_prelude::*; +use crate::*; + impl, I: 'static> Pallet { /// Approves the transfer of an item to a delegate. /// diff --git a/pallets/nfts/src/features/atomic_swap.rs b/pallets/nfts/src/features/atomic_swap.rs index 830283b7..31c93fba 100644 --- a/pallets/nfts/src/features/atomic_swap.rs +++ b/pallets/nfts/src/features/atomic_swap.rs @@ -20,12 +20,13 @@ //! The bitflag [`PalletFeature::Swaps`] needs to be set in [`Config::Features`] for NFTs //! to have the functionality defined in this module. -use crate::*; use frame_support::{ pallet_prelude::*, traits::{Currency, ExistenceRequirement::KeepAlive}, }; +use crate::*; + impl, I: 'static> Pallet { /// Creates a new swap offer for the specified item. /// @@ -101,6 +102,7 @@ impl, I: 'static> Pallet { Ok(()) } + /// Cancels the specified swap offer. /// /// This function is used to cancel the specified swap offer created by the `caller` account. If diff --git a/pallets/nfts/src/features/attributes.rs b/pallets/nfts/src/features/attributes.rs index 28f7bd2c..ab0cdc68 100644 --- a/pallets/nfts/src/features/attributes.rs +++ b/pallets/nfts/src/features/attributes.rs @@ -20,9 +20,10 @@ //! The bitflag [`PalletFeature::Attributes`] needs to be set in [`Config::Features`] for NFTs //! to have the functionality defined in this module. -use crate::*; use frame_support::pallet_prelude::*; +use crate::*; + impl, I: 'static> Pallet { /// Sets the attribute of an item or a collection. /// diff --git a/pallets/nfts/src/features/buy_sell.rs b/pallets/nfts/src/features/buy_sell.rs index d6ec6f50..8cf86f79 100644 --- a/pallets/nfts/src/features/buy_sell.rs +++ b/pallets/nfts/src/features/buy_sell.rs @@ -20,12 +20,13 @@ //! The bitflag [`PalletFeature::Trading`] needs to be set in the [`Config::Features`] for NFTs //! to have the functionality defined in this module. -use crate::*; use frame_support::{ pallet_prelude::*, traits::{Currency, ExistenceRequirement, ExistenceRequirement::KeepAlive}, }; +use crate::*; + impl, I: 'static> Pallet { /// Pays the specified tips to the corresponding receivers. /// diff --git a/pallets/nfts/src/features/create_delete_collection.rs b/pallets/nfts/src/features/create_delete_collection.rs index f03df7fd..348ec6b9 100644 --- a/pallets/nfts/src/features/create_delete_collection.rs +++ b/pallets/nfts/src/features/create_delete_collection.rs @@ -18,9 +18,10 @@ //! This module contains helper methods to perform functionality associated with creating and //! destroying collections for the NFTs pallet. -use crate::*; use frame_support::pallet_prelude::*; +use crate::*; + impl, I: 'static> Pallet { /// Create a new collection with the given `collection`, `owner`, `admin`, `config`, `deposit`, /// and `event`. diff --git a/pallets/nfts/src/features/create_delete_item.rs b/pallets/nfts/src/features/create_delete_item.rs index 37f64ae1..e9843b2e 100644 --- a/pallets/nfts/src/features/create_delete_item.rs +++ b/pallets/nfts/src/features/create_delete_item.rs @@ -18,9 +18,10 @@ //! This module contains helper methods to perform functionality associated with minting and burning //! items for the NFTs pallet. -use crate::*; use frame_support::{pallet_prelude::*, traits::ExistenceRequirement}; +use crate::*; + impl, I: 'static> Pallet { /// Mint a new unique item with the given `collection`, `item`, and other minting configuration /// details. diff --git a/pallets/nfts/src/features/lock.rs b/pallets/nfts/src/features/lock.rs index 1c3c9c86..4649f4a0 100644 --- a/pallets/nfts/src/features/lock.rs +++ b/pallets/nfts/src/features/lock.rs @@ -18,9 +18,10 @@ //! This module contains helper methods to configure locks on collections and items for the NFTs //! pallet. -use crate::*; use frame_support::pallet_prelude::*; +use crate::*; + impl, I: 'static> Pallet { /// Locks a collection with specified settings. /// @@ -29,7 +30,6 @@ impl, I: 'static> Pallet { /// /// Note: it's possible only to lock the setting, but not to unlock it after. - /// /// - `origin`: The origin of the transaction, representing the account attempting to lock the /// collection. /// - `collection`: The identifier of the collection to be locked. diff --git a/pallets/nfts/src/features/metadata.rs b/pallets/nfts/src/features/metadata.rs index 26006160..b3d16b12 100644 --- a/pallets/nfts/src/features/metadata.rs +++ b/pallets/nfts/src/features/metadata.rs @@ -17,10 +17,12 @@ //! This module contains helper methods to configure the metadata of collections and items. -use crate::*; use alloc::vec::Vec; + use frame_support::pallet_prelude::*; +use crate::*; + impl, I: 'static> Pallet { /// Sets the metadata for a specific item within a collection. /// diff --git a/pallets/nfts/src/features/roles.rs b/pallets/nfts/src/features/roles.rs index aa6394f7..053eaf0b 100644 --- a/pallets/nfts/src/features/roles.rs +++ b/pallets/nfts/src/features/roles.rs @@ -17,10 +17,12 @@ //! This module contains helper methods to configure account roles for existing collections. -use crate::*; use alloc::{collections::btree_map::BTreeMap, vec::Vec}; + use frame_support::pallet_prelude::*; +use crate::*; + impl, I: 'static> Pallet { /// Set the team roles for a specific collection. /// diff --git a/pallets/nfts/src/features/settings.rs b/pallets/nfts/src/features/settings.rs index d4f7533f..9c7ac7ca 100644 --- a/pallets/nfts/src/features/settings.rs +++ b/pallets/nfts/src/features/settings.rs @@ -17,9 +17,10 @@ //! This module provides helper methods to configure collection settings for the NFTs pallet. -use crate::*; use frame_support::pallet_prelude::*; +use crate::*; + impl, I: 'static> Pallet { /// Forcefully change the configuration of a collection. /// diff --git a/pallets/nfts/src/features/transfer.rs b/pallets/nfts/src/features/transfer.rs index bba83448..b7223a7c 100644 --- a/pallets/nfts/src/features/transfer.rs +++ b/pallets/nfts/src/features/transfer.rs @@ -18,9 +18,10 @@ //! This module contains helper methods to perform the transfer functionalities //! of the NFTs pallet. -use crate::*; use frame_support::pallet_prelude::*; +use crate::*; + impl, I: 'static> Pallet { /// Transfer an NFT to the specified destination account. /// @@ -160,6 +161,7 @@ impl, I: 'static> Pallet { Ok(()) }) } + /// Set or unset the ownership acceptance for an account regarding a specific collection. /// /// - `who`: The account for which to set or unset the ownership acceptance. diff --git a/pallets/nfts/src/impl_nonfungibles.rs b/pallets/nfts/src/impl_nonfungibles.rs index c90655aa..362cccd9 100644 --- a/pallets/nfts/src/impl_nonfungibles.rs +++ b/pallets/nfts/src/impl_nonfungibles.rs @@ -17,7 +17,6 @@ //! Implementations for `nonfungibles` traits. -use super::*; use frame_support::{ ensure, storage::KeyPrefixIterator, @@ -26,9 +25,11 @@ use frame_support::{ }; use sp_runtime::{DispatchError, DispatchResult}; +use super::*; + impl, I: 'static> Inspect<::AccountId> for Pallet { - type ItemId = T::ItemId; type CollectionId = T::CollectionId; + type ItemId = T::ItemId; fn owner( collection: &Self::CollectionId, @@ -140,9 +141,11 @@ impl, I: 'static> InspectRole<::AccountId> for P fn is_issuer(collection: &Self::CollectionId, who: &::AccountId) -> bool { Self::has_role(collection, who, CollectionRole::Issuer) } + fn is_admin(collection: &Self::CollectionId, who: &::AccountId) -> bool { Self::has_role(collection, who, CollectionRole::Admin) } + fn is_freezer(collection: &Self::CollectionId, who: &::AccountId) -> bool { Self::has_role(collection, who, CollectionRole::Freezer) } @@ -469,9 +472,9 @@ impl, I: 'static> Trading> for Pallet impl, I: 'static> InspectEnumerable for Pallet { type CollectionsIterator = KeyPrefixIterator<>::CollectionId>; type ItemsIterator = KeyPrefixIterator<>::ItemId>; + type OwnedInCollectionIterator = KeyPrefixIterator<>::ItemId>; type OwnedIterator = KeyPrefixIterator<(>::CollectionId, >::ItemId)>; - type OwnedInCollectionIterator = KeyPrefixIterator<>::ItemId>; /// Returns an iterator of the collections in existence. /// diff --git a/pallets/nfts/src/lib.rs b/pallets/nfts/src/lib.rs index 4e5493a3..89bfb963 100644 --- a/pallets/nfts/src/lib.rs +++ b/pallets/nfts/src/lib.rs @@ -51,18 +51,18 @@ pub mod weights; extern crate alloc; use alloc::{boxed::Box, vec, vec::Vec}; + use codec::{Decode, Encode}; use frame_support::traits::{ tokens::Locker, BalanceStatus::Reserved, Currency, EnsureOriginWithArg, Incrementable, ReservableCurrency, }; use frame_system::Config as SystemConfig; +pub use pallet::*; use sp_runtime::{ traits::{IdentifyAccount, Saturating, StaticLookup, Verify, Zero}, RuntimeDebug, }; - -pub use pallet::*; pub use types::*; pub use weights::WeightInfo; @@ -74,10 +74,11 @@ type AccountIdLookupOf = <::Lookup as StaticLookup>::Sourc #[frame_support::pallet] pub mod pallet { - use super::*; use frame_support::{pallet_prelude::*, traits::ExistenceRequirement}; use frame_system::pallet_prelude::*; + use super::*; + /// The in-code storage version. const STORAGE_VERSION: StorageVersion = StorageVersion::new(1); @@ -108,14 +109,17 @@ pub mod pallet { fn collection(i: u16) -> CollectionId { i.into() } + fn item(i: u16) -> ItemId { i.into() } + fn signer() -> (sp_runtime::MultiSigner, sp_runtime::AccountId32) { let public = sp_io::crypto::sr25519_generate(0.into(), None); let account = sp_runtime::MultiSigner::Sr25519(public).into_account(); (public.into(), account) } + fn sign(signer: &sp_runtime::MultiSigner, message: &[u8]) -> sp_runtime::MultiSignature { sp_runtime::MultiSignature::Sr25519( sp_io::crypto::sr25519_sign(0.into(), &signer.clone().try_into().unwrap(), message) diff --git a/pallets/nfts/src/migration.rs b/pallets/nfts/src/migration.rs index 8f82e092..af611bf1 100644 --- a/pallets/nfts/src/migration.rs +++ b/pallets/nfts/src/migration.rs @@ -15,13 +15,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -use super::*; use frame_support::traits::OnRuntimeUpgrade; use log; - #[cfg(feature = "try-runtime")] use sp_runtime::TryRuntimeError; +use super::*; + pub mod v1 { use frame_support::{pallet_prelude::*, weights::Weight}; diff --git a/pallets/nfts/src/mock.rs b/pallets/nfts/src/mock.rs index 5b589f59..5532be8f 100644 --- a/pallets/nfts/src/mock.rs +++ b/pallets/nfts/src/mock.rs @@ -17,9 +17,6 @@ //! Test environment for Nfts pallet. -use super::*; -use crate as pallet_nfts; - use frame_support::{ construct_runtime, derive_impl, parameter_types, traits::{AsEnsureOriginWithArg, ConstU32, ConstU64}, @@ -30,6 +27,9 @@ use sp_runtime::{ BuildStorage, MultiSignature, }; +use super::*; +use crate as pallet_nfts; + type Block = frame_system::mocking::MockBlock; construct_runtime!( @@ -47,10 +47,10 @@ pub type AccountId = ::AccountId; #[derive_impl(frame_system::config_preludes::TestDefaultConfig)] impl frame_system::Config for Test { + type AccountData = pallet_balances::AccountData; type AccountId = AccountId; - type Lookup = IdentityLookup; type Block = Block; - type AccountData = pallet_balances::AccountData; + type Lookup = IdentityLookup; } #[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] @@ -63,35 +63,35 @@ parameter_types! { } impl Config for Test { - type RuntimeEvent = RuntimeEvent; + type ApprovalsLimit = ConstU32<10>; + type AttributeDepositBase = ConstU64<1>; + type CollectionDeposit = ConstU64<2>; type CollectionId = u32; - type ItemId = u32; - type Currency = Balances; type CreateOrigin = AsEnsureOriginWithArg>; + type Currency = Balances; + type DepositPerByte = ConstU64<1>; + type Features = Features; type ForceOrigin = frame_system::EnsureRoot; - type Locker = (); - type CollectionDeposit = ConstU64<2>; + #[cfg(feature = "runtime-benchmarks")] + type Helper = (); + type ItemAttributesApprovalsLimit = ConstU32<2>; type ItemDeposit = ConstU64<1>; - type MetadataDepositBase = ConstU64<1>; - type AttributeDepositBase = ConstU64<1>; - type DepositPerByte = ConstU64<1>; - type StringLimit = ConstU32<50>; + type ItemId = u32; type KeyLimit = ConstU32<50>; - type ValueLimit = ConstU32<50>; - type ApprovalsLimit = ConstU32<10>; - type ItemAttributesApprovalsLimit = ConstU32<2>; - type MaxTips = ConstU32<10>; - type MaxDeadlineDuration = ConstU64<10000>; + type Locker = (); type MaxAttributesPerCall = ConstU32<2>; - type Features = Features; + type MaxDeadlineDuration = ConstU64<10000>; + type MaxTips = ConstU32<10>; + type MetadataDepositBase = ConstU64<1>; + /// Using `AccountPublic` here makes it trivial to convert to `AccountId` via `into_account()`. + type OffchainPublic = AccountPublic; /// Off-chain = signature On-chain - therefore no conversion needed. /// It needs to be From for benchmarking. type OffchainSignature = Signature; - /// Using `AccountPublic` here makes it trivial to convert to `AccountId` via `into_account()`. - type OffchainPublic = AccountPublic; + type RuntimeEvent = RuntimeEvent; + type StringLimit = ConstU32<50>; + type ValueLimit = ConstU32<50>; type WeightInfo = (); - #[cfg(feature = "runtime-benchmarks")] - type Helper = (); } pub(crate) fn new_test_ext() -> sp_io::TestExternalities { diff --git a/pallets/nfts/src/tests.rs b/pallets/nfts/src/tests.rs index e1b598ca..44f2f32a 100644 --- a/pallets/nfts/src/tests.rs +++ b/pallets/nfts/src/tests.rs @@ -17,7 +17,6 @@ //! Tests for Nfts pallet. -use crate::{mock::*, Event, SystemConfig, *}; use enumflags2::BitFlags; use frame_support::{ assert_noop, assert_ok, @@ -33,6 +32,8 @@ use sp_runtime::{ MultiSignature, MultiSigner, }; +use crate::{mock::*, Event, SystemConfig, *}; + type AccountIdOf = ::AccountId; fn account(id: u8) -> AccountIdOf { diff --git a/pallets/nfts/src/types.rs b/pallets/nfts/src/types.rs index 1687a035..f08f1d09 100644 --- a/pallets/nfts/src/types.rs +++ b/pallets/nfts/src/types.rs @@ -17,9 +17,8 @@ //! This module contains various basic types and data structures used in the NFTs pallet. -use super::*; -use crate::macros::*; use alloc::{vec, vec::Vec}; + use codec::EncodeLike; use enumflags2::{bitflags, BitFlags}; use frame_support::{ @@ -30,6 +29,9 @@ use frame_support::{ use frame_system::pallet_prelude::BlockNumberFor; use scale_info::{build::Fields, meta_type, Path, Type, TypeInfo, TypeParameter}; +use super::*; +use crate::macros::*; + /// A type alias for handling balance deposits. pub(super) type DepositBalanceOf = <>::Currency as Currency<::AccountId>>::Balance; @@ -276,12 +278,15 @@ impl CollectionSettings { pub fn all_enabled() -> Self { Self(BitFlags::EMPTY) } + pub fn get_disabled(&self) -> BitFlags { self.0 } + pub fn is_disabled(&self, setting: CollectionSetting) -> bool { self.0.contains(setting) } + pub fn from_disabled(settings: BitFlags) -> Self { Self(settings) } @@ -377,12 +382,15 @@ impl CollectionConfig bool { !self.settings.is_disabled(setting) } + pub fn has_disabled_setting(&self, setting: CollectionSetting) -> bool { self.settings.is_disabled(setting) } + pub fn enable_setting(&mut self, setting: CollectionSetting) { self.settings.0.remove(setting); } + pub fn disable_setting(&mut self, setting: CollectionSetting) { self.settings.0.insert(setting); } @@ -409,12 +417,15 @@ impl ItemSettings { pub fn all_enabled() -> Self { Self(BitFlags::EMPTY) } + pub fn get_disabled(&self) -> BitFlags { self.0 } + pub fn is_disabled(&self, setting: ItemSetting) -> bool { self.0.contains(setting) } + pub fn from_disabled(settings: BitFlags) -> Self { Self(settings) } @@ -435,15 +446,19 @@ impl ItemConfig { pub fn is_setting_enabled(&self, setting: ItemSetting) -> bool { !self.settings.is_disabled(setting) } + pub fn has_disabled_setting(&self, setting: ItemSetting) -> bool { self.settings.is_disabled(setting) } + pub fn has_disabled_settings(&self) -> bool { !self.settings.get_disabled().is_empty() } + pub fn enable_setting(&mut self, setting: ItemSetting) { self.settings.0.remove(setting); } + pub fn disable_setting(&mut self, setting: ItemSetting) { self.settings.0.insert(setting); } @@ -472,9 +487,11 @@ impl PalletFeatures { pub fn all_enabled() -> Self { Self(BitFlags::EMPTY) } + pub fn from_disabled(features: BitFlags) -> Self { Self(features) } + pub fn is_enabled(&self, feature: PalletFeature) -> bool { !self.0.contains(feature) } @@ -502,12 +519,15 @@ impl CollectionRoles { pub fn none() -> Self { Self(BitFlags::EMPTY) } + pub fn has_role(&self, role: CollectionRole) -> bool { self.0.contains(role) } + pub fn add_role(&mut self, role: CollectionRole) { self.0.insert(role); } + pub fn max_roles() -> u8 { let all: BitFlags = BitFlags::all(); all.len() as u8