Skip to content

Commit

Permalink
fix: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
chungquantin committed Oct 28, 2024
1 parent c82d14f commit d44ac5a
Show file tree
Hide file tree
Showing 19 changed files with 93 additions and 49 deletions.
2 changes: 1 addition & 1 deletion pallets/nfts/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion pallets/nfts/src/common_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

//! Various pieces of common functionality.
use crate::*;
use alloc::vec::Vec;

use frame_support::pallet_prelude::*;

use crate::*;

impl<T: Config<I>, I: 'static> Pallet<T, I> {
/// Get the owner of the item, if the item exists.
pub fn owner(collection: T::CollectionId, item: T::ItemId) -> Option<T::AccountId> {
Expand Down
3 changes: 2 additions & 1 deletion pallets/nfts/src/features/approvals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config<I>, I: 'static> Pallet<T, I> {
/// Approves the transfer of an item to a delegate.
///
Expand Down
4 changes: 3 additions & 1 deletion pallets/nfts/src/features/atomic_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config<I>, I: 'static> Pallet<T, I> {
/// Creates a new swap offer for the specified item.
///
Expand Down Expand Up @@ -101,6 +102,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {

Ok(())
}

/// Cancels the specified swap offer.
///
/// This function is used to cancel the specified swap offer created by the `caller` account. If
Expand Down
3 changes: 2 additions & 1 deletion pallets/nfts/src/features/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config<I>, I: 'static> Pallet<T, I> {
/// Sets the attribute of an item or a collection.
///
Expand Down
3 changes: 2 additions & 1 deletion pallets/nfts/src/features/buy_sell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config<I>, I: 'static> Pallet<T, I> {
/// Pays the specified tips to the corresponding receivers.
///
Expand Down
3 changes: 2 additions & 1 deletion pallets/nfts/src/features/create_delete_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config<I>, I: 'static> Pallet<T, I> {
/// Create a new collection with the given `collection`, `owner`, `admin`, `config`, `deposit`,
/// and `event`.
Expand Down
3 changes: 2 additions & 1 deletion pallets/nfts/src/features/create_delete_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config<I>, I: 'static> Pallet<T, I> {
/// Mint a new unique item with the given `collection`, `item`, and other minting configuration
/// details.
Expand Down
4 changes: 2 additions & 2 deletions pallets/nfts/src/features/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config<I>, I: 'static> Pallet<T, I> {
/// Locks a collection with specified settings.
///
Expand All @@ -29,7 +30,6 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
///
/// 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.
Expand Down
4 changes: 3 additions & 1 deletion pallets/nfts/src/features/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config<I>, I: 'static> Pallet<T, I> {
/// Sets the metadata for a specific item within a collection.
///
Expand Down
4 changes: 3 additions & 1 deletion pallets/nfts/src/features/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config<I>, I: 'static> Pallet<T, I> {
/// Set the team roles for a specific collection.
///
Expand Down
3 changes: 2 additions & 1 deletion pallets/nfts/src/features/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config<I>, I: 'static> Pallet<T, I> {
/// Forcefully change the configuration of a collection.
///
Expand Down
4 changes: 3 additions & 1 deletion pallets/nfts/src/features/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Config<I>, I: 'static> Pallet<T, I> {
/// Transfer an NFT to the specified destination account.
///
Expand Down Expand Up @@ -160,6 +161,7 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
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.
Expand Down
9 changes: 6 additions & 3 deletions pallets/nfts/src/impl_nonfungibles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

//! Implementations for `nonfungibles` traits.
use super::*;
use frame_support::{
ensure,
storage::KeyPrefixIterator,
Expand All @@ -26,9 +25,11 @@ use frame_support::{
};
use sp_runtime::{DispatchError, DispatchResult};

use super::*;

impl<T: Config<I>, I: 'static> Inspect<<T as SystemConfig>::AccountId> for Pallet<T, I> {
type ItemId = T::ItemId;
type CollectionId = T::CollectionId;
type ItemId = T::ItemId;

fn owner(
collection: &Self::CollectionId,
Expand Down Expand Up @@ -140,9 +141,11 @@ impl<T: Config<I>, I: 'static> InspectRole<<T as SystemConfig>::AccountId> for P
fn is_issuer(collection: &Self::CollectionId, who: &<T as SystemConfig>::AccountId) -> bool {
Self::has_role(collection, who, CollectionRole::Issuer)
}

fn is_admin(collection: &Self::CollectionId, who: &<T as SystemConfig>::AccountId) -> bool {
Self::has_role(collection, who, CollectionRole::Admin)
}

fn is_freezer(collection: &Self::CollectionId, who: &<T as SystemConfig>::AccountId) -> bool {
Self::has_role(collection, who, CollectionRole::Freezer)
}
Expand Down Expand Up @@ -469,9 +472,9 @@ impl<T: Config<I>, I: 'static> Trading<T::AccountId, ItemPrice<T, I>> for Pallet
impl<T: Config<I>, I: 'static> InspectEnumerable<T::AccountId> for Pallet<T, I> {
type CollectionsIterator = KeyPrefixIterator<<T as Config<I>>::CollectionId>;
type ItemsIterator = KeyPrefixIterator<<T as Config<I>>::ItemId>;
type OwnedInCollectionIterator = KeyPrefixIterator<<T as Config<I>>::ItemId>;
type OwnedIterator =
KeyPrefixIterator<(<T as Config<I>>::CollectionId, <T as Config<I>>::ItemId)>;
type OwnedInCollectionIterator = KeyPrefixIterator<<T as Config<I>>::ItemId>;

/// Returns an iterator of the collections in existence.
///
Expand Down
10 changes: 7 additions & 3 deletions pallets/nfts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -74,10 +74,11 @@ type AccountIdLookupOf<T> = <<T as SystemConfig>::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);

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pallets/nfts/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down
48 changes: 24 additions & 24 deletions pallets/nfts/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -30,6 +27,9 @@ use sp_runtime::{
BuildStorage, MultiSignature,
};

use super::*;
use crate as pallet_nfts;

type Block = frame_system::mocking::MockBlock<Test>;

construct_runtime!(
Expand All @@ -47,10 +47,10 @@ pub type AccountId = <AccountPublic as IdentifyAccount>::AccountId;

#[derive_impl(frame_system::config_preludes::TestDefaultConfig)]
impl frame_system::Config for Test {
type AccountData = pallet_balances::AccountData<u64>;
type AccountId = AccountId;
type Lookup = IdentityLookup<Self::AccountId>;
type Block = Block;
type AccountData = pallet_balances::AccountData<u64>;
type Lookup = IdentityLookup<Self::AccountId>;
}

#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)]
Expand All @@ -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<frame_system::EnsureSigned<Self::AccountId>>;
type Currency = Balances;
type DepositPerByte = ConstU64<1>;
type Features = Features;
type ForceOrigin = frame_system::EnsureRoot<Self::AccountId>;
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<MultiSignature> 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 {
Expand Down
Loading

0 comments on commit d44ac5a

Please sign in to comment.