From e3c90797812c0e1e14601b09cc446975943ad922 Mon Sep 17 00:00:00 2001 From: Daniel Shiposha Date: Mon, 25 Sep 2023 14:57:58 +0000 Subject: [PATCH] fix: dont read storage during minting when not needed --- --- a/pallets/nonfungible/src/lib.rs +++ b/pallets/nonfungible/src/lib.rs @@ -620,10 +620,22 @@ Ok(is_owned) }); - let mut is_token_exist = - pallet_common::LazyValue::new(|| Self::token_exists(collection, token_id)); + let is_new_token = matches!(mode, SetPropertyMode::NewToken { .. }); + + let mut is_token_exist = pallet_common::LazyValue::new(|| { + if is_new_token { + debug_assert!(Self::token_exists(collection, token_id)); + true + } else { + Self::token_exists(collection, token_id) + } + }); - let stored_properties = >::get((collection.id, token_id)); + let stored_properties = if is_new_token { + TokenPropertiesT::new() + } else { + >::get((collection.id, token_id)) + }; >::modify_token_properties( collection, --- a/pallets/refungible/src/lib.rs +++ b/pallets/refungible/src/lib.rs @@ -563,10 +563,22 @@ Ok(is_bundle_owner) }); - let mut is_token_exist = - pallet_common::LazyValue::new(|| Self::token_exists(collection, token_id)); + let is_new_token = matches!(mode, SetPropertyMode::NewToken { .. }); + + let mut is_token_exist = pallet_common::LazyValue::new(|| { + if is_new_token { + debug_assert!(Self::token_exists(collection, token_id)); + true + } else { + Self::token_exists(collection, token_id) + } + }); - let stored_properties = >::get((collection.id, token_id)); + let stored_properties = if is_new_token { + TokenPropertiesT::new() + } else { + >::get((collection.id, token_id)) + }; >::modify_token_properties( collection, -- gitstuff