Skip to content

Commit

Permalink
Nfts: minor fixes (paritytech#13576)
Browse files Browse the repository at this point in the history
* Rename owner_of_item to owned_item

* Move AttributeNamespace into the types file
  • Loading branch information
jsidorenko authored and nathanwhit committed Jul 19, 2023
1 parent 7dd18f0 commit c7de5ab
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 28 deletions.
10 changes: 4 additions & 6 deletions frame/nfts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ pub mod weights;

use codec::{Decode, Encode};
use frame_support::traits::{
tokens::{AttributeNamespace, Locker},
BalanceStatus::Reserved,
Currency, EnsureOriginWithArg, ReservableCurrency,
tokens::Locker, BalanceStatus::Reserved, Currency, EnsureOriginWithArg, ReservableCurrency,
};
use frame_system::Config as SystemConfig;
use sp_runtime::{
Expand Down Expand Up @@ -809,13 +807,13 @@ pub mod pallet {
match mint_settings.mint_type {
MintType::Issuer => return Err(Error::<T, I>::NoPermission.into()),
MintType::HolderOf(collection_id) => {
let MintWitness { owner_of_item } =
let MintWitness { owned_item } =
witness_data.ok_or(Error::<T, I>::BadWitness)?;

let owns_item = Account::<T, I>::contains_key((
&caller,
&collection_id,
&owner_of_item,
&owned_item,
));
ensure!(owns_item, Error::<T, I>::BadWitness);

Expand All @@ -824,7 +822,7 @@ pub mod pallet {

let key = (
&collection_id,
Some(owner_of_item),
Some(owned_item),
AttributeNamespace::Pallet,
&Self::construct_attribute_key(pallet_attribute.encode())?,
);
Expand Down
6 changes: 3 additions & 3 deletions frame/nfts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ fn mint_should_work() {
1,
42,
account(2),
Some(MintWitness { owner_of_item: 42 })
Some(MintWitness { owned_item: 42 })
),
Error::<Test>::BadWitness
);
Expand All @@ -344,7 +344,7 @@ fn mint_should_work() {
1,
42,
account(2),
Some(MintWitness { owner_of_item: 43 })
Some(MintWitness { owned_item: 43 })
));

// can't mint twice
Expand All @@ -354,7 +354,7 @@ fn mint_should_work() {
1,
46,
account(2),
Some(MintWitness { owner_of_item: 43 })
Some(MintWitness { owned_item: 43 })
),
Error::<Test>::AlreadyClaimed
);
Expand Down
17 changes: 16 additions & 1 deletion frame/nfts/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ impl<AccountId, DepositBalance> CollectionDetails<AccountId, DepositBalance> {
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub struct MintWitness<ItemId> {
/// Provide the id of the item in a required collection.
pub owner_of_item: ItemId,
pub owned_item: ItemId,
}

/// Information concerning the ownership of a single unique item.
Expand Down Expand Up @@ -317,6 +317,21 @@ impl<Price, BlockNumber, CollectionId> Default for MintSettings<Price, BlockNumb
}
}

/// Attribute namespaces for non-fungible tokens.
#[derive(
Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, scale_info::TypeInfo, MaxEncodedLen,
)]
pub enum AttributeNamespace<AccountId> {
/// An attribute was set by the pallet.
Pallet,
/// An attribute was set by collection's owner.
CollectionOwner,
/// An attribute was set by item's owner.
ItemOwner,
/// An attribute was set by pre-approved account.
Account(AccountId),
}

/// A witness data to cancel attributes approval operation.
#[derive(Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, TypeInfo)]
pub struct CancelAttributesApprovalWitness {
Expand Down
5 changes: 2 additions & 3 deletions frame/support/src/traits/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ 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, Balance, BalanceConversion, BalanceStatus, ConvertRank, DepositConsequence,
ExistenceRequirement, GetSalary, Locker, WithdrawConsequence, WithdrawReasons,
};
15 changes: 0 additions & 15 deletions frame/support/src/traits/tokens/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,6 @@ pub enum BalanceStatus {
Reserved,
}

/// Attribute namespaces for non-fungible tokens.
#[derive(
Clone, Encode, Decode, Eq, PartialEq, RuntimeDebug, scale_info::TypeInfo, MaxEncodedLen,
)]
pub enum AttributeNamespace<AccountId> {
/// An attribute was set by the pallet.
Pallet,
/// An attribute was set by collection's owner.
CollectionOwner,
/// An attribute was set by item's owner.
ItemOwner,
/// An attribute was set by pre-approved account.
Account(AccountId),
}

bitflags::bitflags! {
/// Reasons for moving funds out of an account.
#[derive(Encode, Decode, MaxEncodedLen)]
Expand Down

0 comments on commit c7de5ab

Please sign in to comment.