From 434d582f1e7b0dd9ebfac4927493419e08d3a510 Mon Sep 17 00:00:00 2001 From: Jegor Sidorenko Date: Mon, 21 Aug 2023 14:06:26 +0200 Subject: [PATCH] Make owned_item in MintWitness optional --- frame/nfts/src/lib.rs | 3 ++- frame/nfts/src/tests.rs | 6 +++--- frame/nfts/src/types.rs | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/frame/nfts/src/lib.rs b/frame/nfts/src/lib.rs index 333fe97dd4a1e..92b27432ab215 100644 --- a/frame/nfts/src/lib.rs +++ b/frame/nfts/src/lib.rs @@ -662,7 +662,7 @@ pub mod pallet { /// /// The origin must be Signed and the sender must have sufficient funds free. /// - /// `ItemDeposit` funds of sender are reserved. + /// `CollectionDeposit` funds of sender are reserved. /// /// Parameters: /// - `admin`: The admin of this collection. The admin is the initial address of each @@ -844,6 +844,7 @@ pub mod pallet { MintType::HolderOf(collection_id) => { let MintWitness { owned_item, .. } = witness_data.clone().ok_or(Error::::WitnessRequired)?; + let owned_item = owned_item.ok_or(Error::::BadWitness)?; let owns_item = Account::::contains_key(( &caller, diff --git a/frame/nfts/src/tests.rs b/frame/nfts/src/tests.rs index c94e75d343930..f7879570a4cb7 100644 --- a/frame/nfts/src/tests.rs +++ b/frame/nfts/src/tests.rs @@ -427,7 +427,7 @@ fn mint_should_work() { 1, 42, account(2), - Some(MintWitness { owned_item: 42, ..Default::default() }) + Some(MintWitness { owned_item: Some(42), ..Default::default() }) ), Error::::BadWitness ); @@ -436,7 +436,7 @@ fn mint_should_work() { 1, 42, account(2), - Some(MintWitness { owned_item: 43, ..Default::default() }) + Some(MintWitness { owned_item: Some(43), ..Default::default() }) )); // can't mint twice @@ -446,7 +446,7 @@ fn mint_should_work() { 1, 46, account(2), - Some(MintWitness { owned_item: 43, ..Default::default() }) + Some(MintWitness { owned_item: Some(43), ..Default::default() }) ), Error::::AlreadyClaimed ); diff --git a/frame/nfts/src/types.rs b/frame/nfts/src/types.rs index f083b116fe938..5a9f6ae2f0e21 100644 --- a/frame/nfts/src/types.rs +++ b/frame/nfts/src/types.rs @@ -133,7 +133,7 @@ impl CollectionDetails { #[derive(Clone, Encode, Decode, Default, Eq, PartialEq, RuntimeDebug, TypeInfo)] pub struct MintWitness { /// Provide the id of the item in a required collection. - pub owned_item: ItemId, + pub owned_item: Option, /// The price specified in mint settings. pub mint_price: Option, }