difftreelog
fix use OptionQuery for TokenProperties
in: master
9 files changed
pallets/balances-adapter/src/common.rsdiffbeforeafterboth--- a/pallets/balances-adapter/src/common.rs
+++ b/pallets/balances-adapter/src/common.rs
@@ -172,18 +172,16 @@
fail!(<pallet_common::Error<T>>::UnsupportedOperation);
}
- fn get_token_properties_map(&self, _token_id: TokenId) -> up_data_structs::TokenProperties {
+ fn get_token_properties_raw(
+ &self,
+ _token_id: TokenId,
+ ) -> Option<up_data_structs::TokenProperties> {
// No token properties are defined on fungibles
- up_data_structs::TokenProperties::new()
+ None
}
- fn set_token_properties_map(&self, _token_id: TokenId, _map: up_data_structs::TokenProperties) {
- // No token properties are defined on fungibles
- }
-
- fn properties_exist(&self, _token: TokenId) -> bool {
+ fn set_token_properties_raw(&self, _token_id: TokenId, _map: up_data_structs::TokenProperties) {
// No token properties are defined on fungibles
- false
}
fn set_token_property_permissions(
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -2098,18 +2098,13 @@
/// Get token properties raw map.
///
/// * `token_id` - The token which properties are needed.
- fn get_token_properties_map(&self, token_id: TokenId) -> TokenProperties;
+ fn get_token_properties_raw(&self, token_id: TokenId) -> Option<TokenProperties>;
/// Set token properties raw map.
///
/// * `token_id` - The token for which the properties are being set.
/// * `map` - The raw map containing the token's properties.
- fn set_token_properties_map(&self, token_id: TokenId, map: TokenProperties);
-
- /// Whether the given token has properties.
- ///
- /// * `token_id` - The token in question.
- fn properties_exist(&self, token: TokenId) -> bool;
+ fn set_token_properties_raw(&self, token_id: TokenId, map: TokenProperties);
/// Set token property permissions.
///
@@ -2590,7 +2585,7 @@
<PalletEvm<T>>::deposit_log(log);
self.collection
- .set_token_properties_map(token_id, stored_properties.into_inner());
+ .set_token_properties_raw(token_id, stored_properties.into_inner());
}
Ok(())
@@ -2624,7 +2619,7 @@
true
},
get_properties: |token_id| {
- debug_assert!(!collection.properties_exist(token_id));
+ debug_assert!(collection.get_token_properties_raw(token_id).is_none());
TokenProperties::new()
},
_phantom: PhantomData,
@@ -2686,7 +2681,11 @@
is_collection_admin: LazyValue::new(|| collection.is_owner_or_admin(sender)),
property_permissions: LazyValue::new(|| <Pallet<T>>::property_permissions(collection.id)),
check_token_exist: |token_id| collection.token_exists(token_id),
- get_properties: |token_id| collection.get_token_properties_map(token_id),
+ get_properties: |token_id| {
+ collection
+ .get_token_properties_raw(token_id)
+ .unwrap_or_default()
+ },
_phantom: PhantomData,
}
}
pallets/fungible/src/common.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use core::marker::PhantomData;1819use frame_support::{dispatch::DispatchResultWithPostInfo, ensure, fail, weights::Weight, traits::Get};20use up_data_structs::{21 TokenId, CollectionId, CreateItemExData, budget::Budget, CreateItemData, TokenOwnerError,22};23use pallet_common::{24 CommonCollectionOperations, CommonWeightInfo, RefungibleExtensions, with_weight,25 weights::WeightInfo as _, SelfWeightOf as PalletCommonWeightOf,26};27use pallet_structure::Error as StructureError;28use sp_runtime::{ArithmeticError, DispatchError};29use sp_std::{vec::Vec, vec};30use up_data_structs::{Property, PropertyKey, PropertyValue, PropertyKeyPermission};3132use crate::{33 Allowance, TotalSupply, Balance, Config, Error, FungibleHandle, Pallet, SelfWeightOf,34 weights::WeightInfo,35};3637pub struct CommonWeights<T: Config>(PhantomData<T>);38impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {39 fn create_multiple_items(_data: &[CreateItemData]) -> Weight {40 // All items minted for the same user, so it works same as create_item41 <SelfWeightOf<T>>::create_item()42 }4344 fn create_multiple_items_ex(data: &CreateItemExData<T::CrossAccountId>) -> Weight {45 match data {46 CreateItemExData::Fungible(f) => {47 <SelfWeightOf<T>>::create_multiple_items_ex(f.len() as u32)48 }49 _ => Weight::zero(),50 }51 }5253 fn burn_item() -> Weight {54 <SelfWeightOf<T>>::burn_item()55 }5657 fn set_collection_properties(amount: u32) -> Weight {58 <pallet_common::SelfWeightOf<T>>::set_collection_properties(amount)59 }6061 fn delete_collection_properties(amount: u32) -> Weight {62 <pallet_common::SelfWeightOf<T>>::delete_collection_properties(amount)63 }6465 fn set_token_properties(_amount: u32) -> Weight {66 // Error67 Weight::zero()68 }6970 fn delete_token_properties(_amount: u32) -> Weight {71 // Error72 Weight::zero()73 }7475 fn set_token_property_permissions(_amount: u32) -> Weight {76 // Error77 Weight::zero()78 }7980 fn transfer() -> Weight {81 <SelfWeightOf<T>>::transfer_raw() + <PalletCommonWeightOf<T>>::check_accesslist() * 282 }8384 fn approve() -> Weight {85 <SelfWeightOf<T>>::approve()86 }8788 fn approve_from() -> Weight {89 <SelfWeightOf<T>>::approve_from()90 }9192 fn transfer_from() -> Weight {93 Self::transfer()94 + <SelfWeightOf<T>>::check_allowed_raw()95 + <SelfWeightOf<T>>::set_allowance_unchecked_raw()96 }9798 fn burn_from() -> Weight {99 <SelfWeightOf<T>>::burn_from()100 }101102 fn burn_recursively_self_raw() -> Weight {103 // Read to get total balance104 Self::burn_item() + T::DbWeight::get().reads(1)105 }106107 fn burn_recursively_breadth_raw(_amount: u32) -> Weight {108 // Fungible tokens can't have children109 Weight::zero()110 }111112 fn token_owner() -> Weight {113 Weight::zero()114 }115116 fn set_allowance_for_all() -> Weight {117 Weight::zero()118 }119120 fn force_repair_item() -> Weight {121 Weight::zero()122 }123}124125/// Implementation of `CommonCollectionOperations` for `FungibleHandle`. It wraps FungibleHandle Pallete126/// methods and adds weight info.127impl<T: Config> CommonCollectionOperations<T> for FungibleHandle<T> {128 fn create_item(129 &self,130 sender: T::CrossAccountId,131 to: T::CrossAccountId,132 data: up_data_structs::CreateItemData,133 nesting_budget: &dyn Budget,134 ) -> DispatchResultWithPostInfo {135 match &data {136 up_data_structs::CreateItemData::Fungible(fungible_data) => with_weight(137 <Pallet<T>>::create_item(self, &sender, (to, fungible_data.value), nesting_budget),138 <CommonWeights<T>>::create_item(&data),139 ),140 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),141 }142 }143144 fn create_multiple_items(145 &self,146 sender: T::CrossAccountId,147 to: T::CrossAccountId,148 data: Vec<up_data_structs::CreateItemData>,149 nesting_budget: &dyn Budget,150 ) -> DispatchResultWithPostInfo {151 let mut sum: u128 = 0;152 for data in &data {153 match &data {154 up_data_structs::CreateItemData::Fungible(data) => {155 sum = sum156 .checked_add(data.value)157 .ok_or(ArithmeticError::Overflow)?;158 }159 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),160 }161 }162163 with_weight(164 <Pallet<T>>::create_item(self, &sender, (to, sum), nesting_budget),165 <CommonWeights<T>>::create_multiple_items(&data),166 )167 }168169 fn create_multiple_items_ex(170 &self,171 sender: <T>::CrossAccountId,172 data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,173 nesting_budget: &dyn Budget,174 ) -> DispatchResultWithPostInfo {175 let weight = <CommonWeights<T>>::create_multiple_items_ex(&data);176 let data = match data {177 up_data_structs::CreateItemExData::Fungible(f) => f,178 _ => fail!(<Error<T>>::NotFungibleDataUsedToMintFungibleCollectionToken),179 };180181 with_weight(182 <Pallet<T>>::create_multiple_items(self, &sender, data.into_inner(), nesting_budget),183 weight,184 )185 }186187 fn burn_item(188 &self,189 sender: T::CrossAccountId,190 token: TokenId,191 amount: u128,192 ) -> DispatchResultWithPostInfo {193 ensure!(194 token == TokenId::default(),195 <Error<T>>::FungibleItemsHaveNoId196 );197198 with_weight(199 <Pallet<T>>::burn(self, &sender, amount),200 <CommonWeights<T>>::burn_item(),201 )202 }203204 fn burn_item_recursively(205 &self,206 sender: T::CrossAccountId,207 token: TokenId,208 self_budget: &dyn Budget,209 _breadth_budget: &dyn Budget,210 ) -> DispatchResultWithPostInfo {211 // Should not happen?212 ensure!(213 token == TokenId::default(),214 <Error<T>>::FungibleItemsHaveNoId215 );216 ensure!(self_budget.consume(), <StructureError<T>>::DepthLimit,);217218 with_weight(219 <Pallet<T>>::burn(self, &sender, <Balance<T>>::get((self.id, &sender))),220 <CommonWeights<T>>::burn_recursively_self_raw(),221 )222 }223224 fn transfer(225 &self,226 from: T::CrossAccountId,227 to: T::CrossAccountId,228 token: TokenId,229 amount: u128,230 nesting_budget: &dyn Budget,231 ) -> DispatchResultWithPostInfo {232 ensure!(233 token == TokenId::default(),234 <Error<T>>::FungibleItemsHaveNoId235 );236237 <Pallet<T>>::transfer(self, &from, &to, amount, nesting_budget)238 }239240 fn approve(241 &self,242 sender: T::CrossAccountId,243 spender: T::CrossAccountId,244 token: TokenId,245 amount: u128,246 ) -> DispatchResultWithPostInfo {247 ensure!(248 token == TokenId::default(),249 <Error<T>>::FungibleItemsHaveNoId250 );251252 with_weight(253 <Pallet<T>>::set_allowance(self, &sender, &spender, amount),254 <CommonWeights<T>>::approve(),255 )256 }257258 fn approve_from(259 &self,260 sender: T::CrossAccountId,261 from: T::CrossAccountId,262 to: T::CrossAccountId,263 token: TokenId,264 amount: u128,265 ) -> DispatchResultWithPostInfo {266 ensure!(267 token == TokenId::default(),268 <Error<T>>::FungibleItemsHaveNoId269 );270271 with_weight(272 <Pallet<T>>::set_allowance_from(self, &sender, &from, &to, amount),273 <CommonWeights<T>>::approve_from(),274 )275 }276277 fn transfer_from(278 &self,279 sender: T::CrossAccountId,280 from: T::CrossAccountId,281 to: T::CrossAccountId,282 token: TokenId,283 amount: u128,284 nesting_budget: &dyn Budget,285 ) -> DispatchResultWithPostInfo {286 ensure!(287 token == TokenId::default(),288 <Error<T>>::FungibleItemsHaveNoId289 );290291 <Pallet<T>>::transfer_from(self, &sender, &from, &to, amount, nesting_budget)292 }293294 fn burn_from(295 &self,296 sender: T::CrossAccountId,297 from: T::CrossAccountId,298 token: TokenId,299 amount: u128,300 nesting_budget: &dyn Budget,301 ) -> DispatchResultWithPostInfo {302 ensure!(303 token == TokenId::default(),304 <Error<T>>::FungibleItemsHaveNoId305 );306307 with_weight(308 <Pallet<T>>::burn_from(self, &sender, &from, amount, nesting_budget),309 <CommonWeights<T>>::burn_from(),310 )311 }312313 fn set_collection_properties(314 &self,315 sender: T::CrossAccountId,316 properties: Vec<Property>,317 ) -> DispatchResultWithPostInfo {318 let weight = <CommonWeights<T>>::set_collection_properties(properties.len() as u32);319320 with_weight(321 <Pallet<T>>::set_collection_properties(self, &sender, properties),322 weight,323 )324 }325326 fn delete_collection_properties(327 &self,328 sender: &T::CrossAccountId,329 property_keys: Vec<PropertyKey>,330 ) -> DispatchResultWithPostInfo {331 let weight = <CommonWeights<T>>::delete_collection_properties(property_keys.len() as u32);332333 with_weight(334 <Pallet<T>>::delete_collection_properties(self, sender, property_keys),335 weight,336 )337 }338339 fn set_token_properties(340 &self,341 _sender: T::CrossAccountId,342 _token_id: TokenId,343 _property: Vec<Property>,344 _nesting_budget: &dyn Budget,345 ) -> DispatchResultWithPostInfo {346 fail!(<Error<T>>::SettingPropertiesNotAllowed)347 }348349 fn set_token_property_permissions(350 &self,351 _sender: &T::CrossAccountId,352 _property_permissions: Vec<PropertyKeyPermission>,353 ) -> DispatchResultWithPostInfo {354 fail!(<Error<T>>::SettingPropertiesNotAllowed)355 }356357 fn delete_token_properties(358 &self,359 _sender: T::CrossAccountId,360 _token_id: TokenId,361 _property_keys: Vec<PropertyKey>,362 _nesting_budget: &dyn Budget,363 ) -> DispatchResultWithPostInfo {364 fail!(<Error<T>>::SettingPropertiesNotAllowed)365 }366367 fn get_token_properties_map(&self, _token_id: TokenId) -> up_data_structs::TokenProperties {368 // No token properties are defined on fungibles369 up_data_structs::TokenProperties::new()370 }371372 fn set_token_properties_map(&self, _token_id: TokenId, _map: up_data_structs::TokenProperties) {373 // No token properties are defined on fungibles374 }375376 fn properties_exist(&self, _token: TokenId) -> bool {377 // No token properties are defined on fungibles378 false379 }380381 fn check_nesting(382 &self,383 _sender: <T>::CrossAccountId,384 _from: (CollectionId, TokenId),385 _under: TokenId,386 _nesting_budget: &dyn Budget,387 ) -> sp_runtime::DispatchResult {388 fail!(<Error<T>>::FungibleDisallowsNesting)389 }390391 fn nest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {}392393 fn unnest(&self, _under: TokenId, _to_nest: (CollectionId, TokenId)) {}394395 fn collection_tokens(&self) -> Vec<TokenId> {396 vec![TokenId::default()]397 }398399 fn account_tokens(&self, account: T::CrossAccountId) -> Vec<TokenId> {400 if <Balance<T>>::get((self.id, account)) != 0 {401 vec![TokenId::default()]402 } else {403 vec![]404 }405 }406407 fn token_exists(&self, token: TokenId) -> bool {408 token == TokenId::default()409 }410411 fn last_token_id(&self) -> TokenId {412 TokenId::default()413 }414415 fn token_owner(&self, _token: TokenId) -> Result<T::CrossAccountId, TokenOwnerError> {416 Err(TokenOwnerError::MultipleOwners)417 }418419 fn check_token_indirect_owner(420 &self,421 _token: TokenId,422 _maybe_owner: &T::CrossAccountId,423 _nesting_budget: &dyn Budget,424 ) -> Result<bool, DispatchError> {425 Ok(false)426 }427428 /// Returns 10 tokens owners in no particular order.429 fn token_owners(&self, token: TokenId) -> Vec<T::CrossAccountId> {430 <Pallet<T>>::token_owners(self.id, token).unwrap_or_default()431 }432433 fn token_property(&self, _token_id: TokenId, _key: &PropertyKey) -> Option<PropertyValue> {434 None435 }436437 fn token_properties(438 &self,439 _token_id: TokenId,440 _keys: Option<Vec<PropertyKey>>,441 ) -> Vec<Property> {442 Vec::new()443 }444445 fn total_supply(&self) -> u32 {446 1447 }448449 fn account_balance(&self, account: T::CrossAccountId) -> u32 {450 if <Balance<T>>::get((self.id, account)) != 0 {451 1452 } else {453 0454 }455 }456457 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {458 if token != TokenId::default() {459 return 0;460 }461 <Balance<T>>::get((self.id, account))462 }463464 fn allowance(465 &self,466 sender: T::CrossAccountId,467 spender: T::CrossAccountId,468 token: TokenId,469 ) -> u128 {470 if token != TokenId::default() {471 return 0;472 }473 <Allowance<T>>::get((self.id, sender, spender))474 }475476 fn refungible_extensions(&self) -> Option<&dyn RefungibleExtensions<T>> {477 None478 }479480 fn total_pieces(&self, token: TokenId) -> Option<u128> {481 if token != TokenId::default() {482 return None;483 }484 <TotalSupply<T>>::try_get(self.id).ok()485 }486487 fn set_allowance_for_all(488 &self,489 _owner: T::CrossAccountId,490 _operator: T::CrossAccountId,491 _approve: bool,492 ) -> DispatchResultWithPostInfo {493 fail!(<Error<T>>::SettingAllowanceForAllNotAllowed)494 }495496 fn allowance_for_all(&self, _owner: T::CrossAccountId, _operator: T::CrossAccountId) -> bool {497 false498 }499500 /// Repairs a possibly broken item.501 fn repair_item(&self, _token: TokenId) -> DispatchResultWithPostInfo {502 fail!(<Error<T>>::FungibleTokensAreAlwaysValid)503 }504}pallets/nonfungible/src/common.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/common.rs
+++ b/pallets/nonfungible/src/common.rs
@@ -265,12 +265,15 @@
)
}
- fn get_token_properties_map(&self, token_id: TokenId) -> up_data_structs::TokenProperties {
+ fn get_token_properties_raw(
+ &self,
+ token_id: TokenId,
+ ) -> Option<up_data_structs::TokenProperties> {
<TokenProperties<T>>::get((self.id, token_id))
}
- fn set_token_properties_map(&self, token_id: TokenId, map: up_data_structs::TokenProperties) {
- <TokenProperties<T>>::set((self.id, token_id), map)
+ fn set_token_properties_raw(&self, token_id: TokenId, map: up_data_structs::TokenProperties) {
+ <TokenProperties<T>>::insert((self.id, token_id), map)
}
fn set_token_property_permissions(
@@ -287,10 +290,6 @@
)
}
- fn properties_exist(&self, token: TokenId) -> bool {
- <TokenProperties<T>>::contains_key((self.id, token))
- }
-
fn burn_item(
&self,
sender: T::CrossAccountId,
@@ -482,13 +481,15 @@
}
fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option<PropertyValue> {
- <Pallet<T>>::token_properties((self.id, token_id))
+ <Pallet<T>>::token_properties((self.id, token_id))?
.get(key)
.cloned()
}
fn token_properties(&self, token_id: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property> {
- let properties = <Pallet<T>>::token_properties((self.id, token_id));
+ let Some(properties) = <Pallet<T>>::token_properties((self.id, token_id)) else {
+ return vec![];
+ };
keys.map(|keys| {
keys.into_iter()
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -272,7 +272,8 @@
.try_into()
.map_err(|_| "key too long")?;
- let props = <TokenProperties<T>>::get((self.id, token_id));
+ let props =
+ <TokenProperties<T>>::get((self.id, token_id)).ok_or("Token properties not found")?;
let prop = props.get(&key).ok_or("key not found")?;
Ok(prop.to_vec().into())
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -102,8 +102,8 @@
use up_data_structs::{
AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,
mapping::TokenAddressMapping, budget::Budget, Property, PropertyKey, PropertyValue,
- PropertyKeyPermission, PropertyScope, TrySetProperty, TokenChild, AuxPropertyValue,
- PropertiesPermissionMap, TokenProperties as TokenPropertiesT,
+ PropertyKeyPermission, PropertyScope, TokenChild, AuxPropertyValue, PropertiesPermissionMap,
+ TokenProperties as TokenPropertiesT,
};
use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
use pallet_common::{
@@ -201,7 +201,7 @@
pub type TokenProperties<T: Config> = StorageNMap<
Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
Value = TokenPropertiesT,
- QueryKind = ValueQuery,
+ QueryKind = OptionQuery,
>;
/// Custom data of a token that is serialized to bytes,
@@ -340,40 +340,8 @@
/// - `token`: Token ID.
pub fn token_exists(collection: &NonfungibleHandle<T>, token: TokenId) -> bool {
<TokenData<T>>::contains_key((collection.id, token))
- }
-
- /// Set the token property with the scope.
- ///
- /// - `property`: Contains key-value pair.
- pub fn set_scoped_token_property(
- collection_id: CollectionId,
- token_id: TokenId,
- scope: PropertyScope,
- property: Property,
- ) -> DispatchResult {
- TokenProperties::<T>::try_mutate((collection_id, token_id), |properties| {
- properties.try_scoped_set(scope, property.key, property.value)
- })
- .map_err(<CommonError<T>>::from)?;
-
- Ok(())
}
- /// Batch operation to set multiple properties with the same scope.
- pub fn set_scoped_token_properties(
- collection_id: CollectionId,
- token_id: TokenId,
- scope: PropertyScope,
- properties: impl Iterator<Item = Property>,
- ) -> DispatchResult {
- TokenProperties::<T>::try_mutate((collection_id, token_id), |stored_properties| {
- stored_properties.try_scoped_set_from_iter(scope, properties)
- })
- .map_err(<CommonError<T>>::from)?;
-
- Ok(())
- }
-
/// Add or edit auxiliary data for the property.
///
/// - `f`: function that adds or edits auxiliary data.
@@ -1394,7 +1362,9 @@
pub fn repair_item(collection: &NonfungibleHandle<T>, token: TokenId) -> DispatchResult {
<TokenProperties<T>>::mutate((collection.id, token), |properties| {
- properties.recompute_consumed_space();
+ if let Some(properties) = properties {
+ properties.recompute_consumed_space();
+ }
});
Ok(())
pallets/refungible/src/common.rsdiffbeforeafterboth--- a/pallets/refungible/src/common.rs
+++ b/pallets/refungible/src/common.rs
@@ -435,16 +435,15 @@
)
}
- fn get_token_properties_map(&self, token_id: TokenId) -> up_data_structs::TokenProperties {
+ fn get_token_properties_raw(
+ &self,
+ token_id: TokenId,
+ ) -> Option<up_data_structs::TokenProperties> {
<TokenProperties<T>>::get((self.id, token_id))
}
- fn set_token_properties_map(&self, token_id: TokenId, map: up_data_structs::TokenProperties) {
- <TokenProperties<T>>::set((self.id, token_id), map)
- }
-
- fn properties_exist(&self, token: TokenId) -> bool {
- <TokenProperties<T>>::contains_key((self.id, token))
+ fn set_token_properties_raw(&self, token_id: TokenId, map: up_data_structs::TokenProperties) {
+ <TokenProperties<T>>::insert((self.id, token_id), map)
}
fn check_nesting(
@@ -514,13 +513,15 @@
}
fn token_property(&self, token_id: TokenId, key: &PropertyKey) -> Option<PropertyValue> {
- <Pallet<T>>::token_properties((self.id, token_id))
+ <Pallet<T>>::token_properties((self.id, token_id))?
.get(key)
.cloned()
}
fn token_properties(&self, token_id: TokenId, keys: Option<Vec<PropertyKey>>) -> Vec<Property> {
- let properties = <Pallet<T>>::token_properties((self.id, token_id));
+ let Some(properties) = <Pallet<T>>::token_properties((self.id, token_id)) else {
+ return vec![];
+ };
keys.map(|keys| {
keys.into_iter()
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -283,7 +283,8 @@
.try_into()
.map_err(|_| "key too long")?;
- let props = <TokenProperties<T>>::get((self.id, token_id));
+ let props =
+ <TokenProperties<T>>::get((self.id, token_id)).ok_or("Token properties not found")?;
let prop = props.get(&key).ok_or("key not found")?;
Ok(prop.to_vec().into())
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -106,8 +106,8 @@
use up_data_structs::{
AccessMode, budget::Budget, CollectionId, CreateCollectionData, mapping::TokenAddressMapping,
MAX_REFUNGIBLE_PIECES, Property, PropertyKey, PropertyKeyPermission, PropertyScope,
- PropertyValue, TokenId, TrySetProperty, PropertiesPermissionMap,
- CreateRefungibleExMultipleOwners, TokenOwnerError, TokenProperties as TokenPropertiesT,
+ PropertyValue, TokenId, PropertiesPermissionMap, CreateRefungibleExMultipleOwners,
+ TokenOwnerError, TokenProperties as TokenPropertiesT,
};
pub use pallet::*;
@@ -175,7 +175,7 @@
pub type TokenProperties<T: Config> = StorageNMap<
Key = (Key<Twox64Concat, CollectionId>, Key<Twox64Concat, TokenId>),
Value = TokenPropertiesT,
- QueryKind = ValueQuery,
+ QueryKind = OptionQuery,
>;
/// Total amount of pieces for token
@@ -292,35 +292,7 @@
/// - `token`: Token ID.
pub fn token_exists(collection: &RefungibleHandle<T>, token: TokenId) -> bool {
<TotalSupply<T>>::contains_key((collection.id, token))
- }
-
- pub fn set_scoped_token_property(
- collection_id: CollectionId,
- token_id: TokenId,
- scope: PropertyScope,
- property: Property,
- ) -> DispatchResult {
- TokenProperties::<T>::try_mutate((collection_id, token_id), |properties| {
- properties.try_scoped_set(scope, property.key, property.value)
- })
- .map_err(<CommonError<T>>::from)?;
-
- Ok(())
}
-
- pub fn set_scoped_token_properties(
- collection_id: CollectionId,
- token_id: TokenId,
- scope: PropertyScope,
- properties: impl Iterator<Item = Property>,
- ) -> DispatchResult {
- TokenProperties::<T>::try_mutate((collection_id, token_id), |stored_properties| {
- stored_properties.try_scoped_set_from_iter(scope, properties)
- })
- .map_err(<CommonError<T>>::from)?;
-
- Ok(())
- }
}
// unchecked calls skips any permission checks
@@ -1426,7 +1398,9 @@
pub fn repair_item(collection: &RefungibleHandle<T>, token: TokenId) -> DispatchResult {
<TokenProperties<T>>::mutate((collection.id, token), |properties| {
- properties.recompute_consumed_space();
+ if let Some(properties) = properties {
+ properties.recompute_consumed_space();
+ }
});
Ok(())