difftreelog
fix use OptionQuery for TokenProperties
in: master
9 files changed
pallets/balances-adapter/src/common.rsdiffbeforeafterboth1use alloc::{vec, vec::Vec};2use core::marker::PhantomData;3use crate::{Config, NativeFungibleHandle, Pallet};4use frame_support::{fail, weights::Weight};5use pallet_balances::{weights::SubstrateWeight as BalancesWeight, WeightInfo};6use pallet_common::{CommonCollectionOperations, CommonWeightInfo};7use up_data_structs::TokenId;89pub struct CommonWeights<T: Config>(PhantomData<T>);1011// All implementations with `Weight::default` used in methods that return error `UnsupportedOperation`.12impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {13 fn create_multiple_items(_amount: &[up_data_structs::CreateItemData]) -> Weight {14 Weight::default()15 }1617 fn create_multiple_items_ex(18 _cost: &up_data_structs::CreateItemExData<T::CrossAccountId>,19 ) -> Weight {20 Weight::default()21 }2223 fn burn_item() -> Weight {24 Weight::default()25 }2627 fn set_collection_properties(_amount: u32) -> Weight {28 Weight::default()29 }3031 fn delete_collection_properties(_amount: u32) -> Weight {32 Weight::default()33 }3435 fn set_token_properties(_amount: u32) -> Weight {36 Weight::default()37 }3839 fn delete_token_properties(_amount: u32) -> Weight {40 Weight::default()41 }4243 fn set_token_property_permissions(_amount: u32) -> Weight {44 Weight::default()45 }4647 fn transfer() -> Weight {48 <BalancesWeight<T> as WeightInfo>::transfer_allow_death()49 }5051 fn approve() -> Weight {52 Weight::default()53 }5455 fn approve_from() -> Weight {56 Weight::default()57 }5859 fn transfer_from() -> Weight {60 <BalancesWeight<T> as WeightInfo>::transfer_allow_death()61 }6263 fn burn_from() -> Weight {64 Weight::default()65 }6667 fn burn_recursively_self_raw() -> Weight {68 Weight::default()69 }7071 fn burn_recursively_breadth_raw(_amount: u32) -> Weight {72 Weight::default()73 }7475 fn token_owner() -> Weight {76 Weight::default()77 }7879 fn set_allowance_for_all() -> Weight {80 Weight::default()81 }8283 fn force_repair_item() -> Weight {84 Weight::default()85 }86}8788/// Implementation of `CommonCollectionOperations` for `FungibleHandle`. It wraps FungibleHandle Pallet89/// methods and adds weight info.90impl<T: Config> CommonCollectionOperations<T> for NativeFungibleHandle<T> {91 fn create_item(92 &self,93 _sender: <T>::CrossAccountId,94 _to: <T>::CrossAccountId,95 _data: up_data_structs::CreateItemData,96 _nesting_budget: &dyn up_data_structs::budget::Budget,97 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {98 fail!(<pallet_common::Error<T>>::UnsupportedOperation);99 }100101 fn create_multiple_items(102 &self,103 _sender: <T>::CrossAccountId,104 _to: <T>::CrossAccountId,105 _data: Vec<up_data_structs::CreateItemData>,106 _nesting_budget: &dyn up_data_structs::budget::Budget,107 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {108 fail!(<pallet_common::Error<T>>::UnsupportedOperation);109 }110111 fn create_multiple_items_ex(112 &self,113 _sender: <T>::CrossAccountId,114 _data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,115 _nesting_budget: &dyn up_data_structs::budget::Budget,116 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {117 fail!(<pallet_common::Error<T>>::UnsupportedOperation);118 }119120 fn burn_item(121 &self,122 _sender: <T>::CrossAccountId,123 _token: TokenId,124 _amount: u128,125 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {126 fail!(<pallet_common::Error<T>>::UnsupportedOperation);127 }128129 fn burn_item_recursively(130 &self,131 _sender: <T>::CrossAccountId,132 _token: TokenId,133 _self_budget: &dyn up_data_structs::budget::Budget,134 _breadth_budget: &dyn up_data_structs::budget::Budget,135 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {136 fail!(<pallet_common::Error<T>>::UnsupportedOperation);137 }138139 fn set_collection_properties(140 &self,141 _sender: <T>::CrossAccountId,142 _properties: Vec<up_data_structs::Property>,143 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {144 fail!(<pallet_common::Error<T>>::UnsupportedOperation);145 }146147 fn delete_collection_properties(148 &self,149 _sender: &<T>::CrossAccountId,150 _property_keys: Vec<up_data_structs::PropertyKey>,151 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {152 fail!(<pallet_common::Error<T>>::UnsupportedOperation);153 }154155 fn set_token_properties(156 &self,157 _sender: <T>::CrossAccountId,158 _token_id: TokenId,159 _properties: Vec<up_data_structs::Property>,160 _budget: &dyn up_data_structs::budget::Budget,161 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {162 fail!(<pallet_common::Error<T>>::UnsupportedOperation);163 }164165 fn delete_token_properties(166 &self,167 _sender: <T>::CrossAccountId,168 _token_id: TokenId,169 _property_keys: Vec<up_data_structs::PropertyKey>,170 _budget: &dyn up_data_structs::budget::Budget,171 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {172 fail!(<pallet_common::Error<T>>::UnsupportedOperation);173 }174175 fn get_token_properties_map(&self, _token_id: TokenId) -> up_data_structs::TokenProperties {176 // No token properties are defined on fungibles177 up_data_structs::TokenProperties::new()178 }179180 fn set_token_properties_map(&self, _token_id: TokenId, _map: up_data_structs::TokenProperties) {181 // No token properties are defined on fungibles182 }183184 fn properties_exist(&self, _token: TokenId) -> bool {185 // No token properties are defined on fungibles186 false187 }188189 fn set_token_property_permissions(190 &self,191 _sender: &<T>::CrossAccountId,192 _property_permissions: Vec<up_data_structs::PropertyKeyPermission>,193 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {194 fail!(<pallet_common::Error<T>>::UnsupportedOperation);195 }196197 fn transfer(198 &self,199 sender: <T>::CrossAccountId,200 to: <T>::CrossAccountId,201 _token: TokenId,202 amount: u128,203 budget: &dyn up_data_structs::budget::Budget,204 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {205 <Pallet<T>>::transfer(self, &sender, &to, amount, budget)206 }207208 fn approve(209 &self,210 _sender: <T>::CrossAccountId,211 _spender: <T>::CrossAccountId,212 _token: TokenId,213 _amount: u128,214 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {215 fail!(<pallet_common::Error<T>>::UnsupportedOperation);216 }217218 fn approve_from(219 &self,220 _sender: <T>::CrossAccountId,221 _from: <T>::CrossAccountId,222 _to: <T>::CrossAccountId,223 _token: TokenId,224 _amount: u128,225 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {226 fail!(<pallet_common::Error<T>>::UnsupportedOperation);227 }228229 fn transfer_from(230 &self,231 sender: <T>::CrossAccountId,232 from: <T>::CrossAccountId,233 to: <T>::CrossAccountId,234 _token: TokenId,235 amount: u128,236 budget: &dyn up_data_structs::budget::Budget,237 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {238 <Pallet<T>>::transfer_from(self, &sender, &from, &to, amount, budget)239 }240241 fn burn_from(242 &self,243 _sender: <T>::CrossAccountId,244 _from: <T>::CrossAccountId,245 _token: TokenId,246 _amount: u128,247 _budget: &dyn up_data_structs::budget::Budget,248 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {249 fail!(<pallet_common::Error<T>>::UnsupportedOperation);250 }251252 fn check_nesting(253 &self,254 _sender: <T>::CrossAccountId,255 _from: (up_data_structs::CollectionId, TokenId),256 _under: TokenId,257 _budget: &dyn up_data_structs::budget::Budget,258 ) -> frame_support::sp_runtime::DispatchResult {259 fail!(<pallet_common::Error<T>>::UnsupportedOperation);260 }261262 fn nest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}263264 fn unnest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}265266 fn account_tokens(&self, account: <T>::CrossAccountId) -> Vec<TokenId> {267 let balance = <Pallet<T>>::total_balance(&account);268 if balance != 0 {269 vec![TokenId::default()]270 } else {271 vec![]272 }273 }274275 fn collection_tokens(&self) -> Vec<TokenId> {276 vec![TokenId::default()]277 }278279 fn token_exists(&self, token: TokenId) -> bool {280 token == TokenId::default()281 }282283 fn last_token_id(&self) -> TokenId {284 TokenId::default()285 }286287 fn token_owner(288 &self,289 _token: TokenId,290 ) -> Result<<T>::CrossAccountId, up_data_structs::TokenOwnerError> {291 Err(up_data_structs::TokenOwnerError::MultipleOwners)292 }293294 fn check_token_indirect_owner(295 &self,296 _token: TokenId,297 _maybe_owner: &<T>::CrossAccountId,298 _nesting_budget: &dyn up_data_structs::budget::Budget,299 ) -> Result<bool, frame_support::sp_runtime::DispatchError> {300 Ok(false)301 }302303 fn token_owners(&self, _token: TokenId) -> Vec<<T>::CrossAccountId> {304 vec![]305 }306307 fn token_property(308 &self,309 _token_id: TokenId,310 _key: &up_data_structs::PropertyKey,311 ) -> Option<up_data_structs::PropertyValue> {312 None313 }314315 fn token_properties(316 &self,317 _token: TokenId,318 _keys: Option<Vec<up_data_structs::PropertyKey>>,319 ) -> Vec<up_data_structs::Property> {320 vec![]321 }322323 fn total_supply(&self) -> u32 {324 1325 }326327 fn account_balance(&self, account: T::CrossAccountId) -> u32 {328 let balance = <Pallet<T>>::balance_of(&account);329 (balance != 0).into()330 }331332 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {333 if token != TokenId::default() {334 return 0;335 }336 <Pallet<T>>::balance_of(&account)337 }338339 fn total_pieces(&self, token: TokenId) -> Option<u128> {340 if token != TokenId::default() {341 return None;342 }343 Some(<Pallet<T>>::total_issuance())344 }345346 fn allowance(347 &self,348 _sender: <T>::CrossAccountId,349 _spender: <T>::CrossAccountId,350 _token: TokenId,351 ) -> u128 {352 0353 }354355 fn refungible_extensions(&self) -> Option<&dyn pallet_common::RefungibleExtensions<T>> {356 None357 }358359 fn set_allowance_for_all(360 &self,361 _owner: <T>::CrossAccountId,362 _operator: <T>::CrossAccountId,363 _approve: bool,364 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {365 fail!(<pallet_common::Error<T>>::UnsupportedOperation);366 }367368 fn allowance_for_all(369 &self,370 _owner: <T>::CrossAccountId,371 _operator: <T>::CrossAccountId,372 ) -> bool {373 false374 }375376 fn repair_item(377 &self,378 _token: TokenId,379 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {380 fail!(<pallet_common::Error<T>>::UnsupportedOperation);381 }382}1use alloc::{vec, vec::Vec};2use core::marker::PhantomData;3use crate::{Config, NativeFungibleHandle, Pallet};4use frame_support::{fail, weights::Weight};5use pallet_balances::{weights::SubstrateWeight as BalancesWeight, WeightInfo};6use pallet_common::{CommonCollectionOperations, CommonWeightInfo};7use up_data_structs::TokenId;89pub struct CommonWeights<T: Config>(PhantomData<T>);1011// All implementations with `Weight::default` used in methods that return error `UnsupportedOperation`.12impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {13 fn create_multiple_items(_amount: &[up_data_structs::CreateItemData]) -> Weight {14 Weight::default()15 }1617 fn create_multiple_items_ex(18 _cost: &up_data_structs::CreateItemExData<T::CrossAccountId>,19 ) -> Weight {20 Weight::default()21 }2223 fn burn_item() -> Weight {24 Weight::default()25 }2627 fn set_collection_properties(_amount: u32) -> Weight {28 Weight::default()29 }3031 fn delete_collection_properties(_amount: u32) -> Weight {32 Weight::default()33 }3435 fn set_token_properties(_amount: u32) -> Weight {36 Weight::default()37 }3839 fn delete_token_properties(_amount: u32) -> Weight {40 Weight::default()41 }4243 fn set_token_property_permissions(_amount: u32) -> Weight {44 Weight::default()45 }4647 fn transfer() -> Weight {48 <BalancesWeight<T> as WeightInfo>::transfer_allow_death()49 }5051 fn approve() -> Weight {52 Weight::default()53 }5455 fn approve_from() -> Weight {56 Weight::default()57 }5859 fn transfer_from() -> Weight {60 <BalancesWeight<T> as WeightInfo>::transfer_allow_death()61 }6263 fn burn_from() -> Weight {64 Weight::default()65 }6667 fn burn_recursively_self_raw() -> Weight {68 Weight::default()69 }7071 fn burn_recursively_breadth_raw(_amount: u32) -> Weight {72 Weight::default()73 }7475 fn token_owner() -> Weight {76 Weight::default()77 }7879 fn set_allowance_for_all() -> Weight {80 Weight::default()81 }8283 fn force_repair_item() -> Weight {84 Weight::default()85 }86}8788/// Implementation of `CommonCollectionOperations` for `FungibleHandle`. It wraps FungibleHandle Pallet89/// methods and adds weight info.90impl<T: Config> CommonCollectionOperations<T> for NativeFungibleHandle<T> {91 fn create_item(92 &self,93 _sender: <T>::CrossAccountId,94 _to: <T>::CrossAccountId,95 _data: up_data_structs::CreateItemData,96 _nesting_budget: &dyn up_data_structs::budget::Budget,97 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {98 fail!(<pallet_common::Error<T>>::UnsupportedOperation);99 }100101 fn create_multiple_items(102 &self,103 _sender: <T>::CrossAccountId,104 _to: <T>::CrossAccountId,105 _data: Vec<up_data_structs::CreateItemData>,106 _nesting_budget: &dyn up_data_structs::budget::Budget,107 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {108 fail!(<pallet_common::Error<T>>::UnsupportedOperation);109 }110111 fn create_multiple_items_ex(112 &self,113 _sender: <T>::CrossAccountId,114 _data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,115 _nesting_budget: &dyn up_data_structs::budget::Budget,116 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {117 fail!(<pallet_common::Error<T>>::UnsupportedOperation);118 }119120 fn burn_item(121 &self,122 _sender: <T>::CrossAccountId,123 _token: TokenId,124 _amount: u128,125 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {126 fail!(<pallet_common::Error<T>>::UnsupportedOperation);127 }128129 fn burn_item_recursively(130 &self,131 _sender: <T>::CrossAccountId,132 _token: TokenId,133 _self_budget: &dyn up_data_structs::budget::Budget,134 _breadth_budget: &dyn up_data_structs::budget::Budget,135 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {136 fail!(<pallet_common::Error<T>>::UnsupportedOperation);137 }138139 fn set_collection_properties(140 &self,141 _sender: <T>::CrossAccountId,142 _properties: Vec<up_data_structs::Property>,143 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {144 fail!(<pallet_common::Error<T>>::UnsupportedOperation);145 }146147 fn delete_collection_properties(148 &self,149 _sender: &<T>::CrossAccountId,150 _property_keys: Vec<up_data_structs::PropertyKey>,151 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {152 fail!(<pallet_common::Error<T>>::UnsupportedOperation);153 }154155 fn set_token_properties(156 &self,157 _sender: <T>::CrossAccountId,158 _token_id: TokenId,159 _properties: Vec<up_data_structs::Property>,160 _budget: &dyn up_data_structs::budget::Budget,161 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {162 fail!(<pallet_common::Error<T>>::UnsupportedOperation);163 }164165 fn delete_token_properties(166 &self,167 _sender: <T>::CrossAccountId,168 _token_id: TokenId,169 _property_keys: Vec<up_data_structs::PropertyKey>,170 _budget: &dyn up_data_structs::budget::Budget,171 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {172 fail!(<pallet_common::Error<T>>::UnsupportedOperation);173 }174175 fn get_token_properties_raw(176 &self,177 _token_id: TokenId,178 ) -> Option<up_data_structs::TokenProperties> {179 // No token properties are defined on fungibles180 None181 }182183 fn set_token_properties_raw(&self, _token_id: TokenId, _map: up_data_structs::TokenProperties) {184 // No token properties are defined on fungibles185 }186187 fn set_token_property_permissions(188 &self,189 _sender: &<T>::CrossAccountId,190 _property_permissions: Vec<up_data_structs::PropertyKeyPermission>,191 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {192 fail!(<pallet_common::Error<T>>::UnsupportedOperation);193 }194195 fn transfer(196 &self,197 sender: <T>::CrossAccountId,198 to: <T>::CrossAccountId,199 _token: TokenId,200 amount: u128,201 budget: &dyn up_data_structs::budget::Budget,202 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {203 <Pallet<T>>::transfer(self, &sender, &to, amount, budget)204 }205206 fn approve(207 &self,208 _sender: <T>::CrossAccountId,209 _spender: <T>::CrossAccountId,210 _token: TokenId,211 _amount: u128,212 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {213 fail!(<pallet_common::Error<T>>::UnsupportedOperation);214 }215216 fn approve_from(217 &self,218 _sender: <T>::CrossAccountId,219 _from: <T>::CrossAccountId,220 _to: <T>::CrossAccountId,221 _token: TokenId,222 _amount: u128,223 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {224 fail!(<pallet_common::Error<T>>::UnsupportedOperation);225 }226227 fn transfer_from(228 &self,229 sender: <T>::CrossAccountId,230 from: <T>::CrossAccountId,231 to: <T>::CrossAccountId,232 _token: TokenId,233 amount: u128,234 budget: &dyn up_data_structs::budget::Budget,235 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {236 <Pallet<T>>::transfer_from(self, &sender, &from, &to, amount, budget)237 }238239 fn burn_from(240 &self,241 _sender: <T>::CrossAccountId,242 _from: <T>::CrossAccountId,243 _token: TokenId,244 _amount: u128,245 _budget: &dyn up_data_structs::budget::Budget,246 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {247 fail!(<pallet_common::Error<T>>::UnsupportedOperation);248 }249250 fn check_nesting(251 &self,252 _sender: <T>::CrossAccountId,253 _from: (up_data_structs::CollectionId, TokenId),254 _under: TokenId,255 _budget: &dyn up_data_structs::budget::Budget,256 ) -> frame_support::sp_runtime::DispatchResult {257 fail!(<pallet_common::Error<T>>::UnsupportedOperation);258 }259260 fn nest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}261262 fn unnest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}263264 fn account_tokens(&self, account: <T>::CrossAccountId) -> Vec<TokenId> {265 let balance = <Pallet<T>>::total_balance(&account);266 if balance != 0 {267 vec![TokenId::default()]268 } else {269 vec![]270 }271 }272273 fn collection_tokens(&self) -> Vec<TokenId> {274 vec![TokenId::default()]275 }276277 fn token_exists(&self, token: TokenId) -> bool {278 token == TokenId::default()279 }280281 fn last_token_id(&self) -> TokenId {282 TokenId::default()283 }284285 fn token_owner(286 &self,287 _token: TokenId,288 ) -> Result<<T>::CrossAccountId, up_data_structs::TokenOwnerError> {289 Err(up_data_structs::TokenOwnerError::MultipleOwners)290 }291292 fn check_token_indirect_owner(293 &self,294 _token: TokenId,295 _maybe_owner: &<T>::CrossAccountId,296 _nesting_budget: &dyn up_data_structs::budget::Budget,297 ) -> Result<bool, frame_support::sp_runtime::DispatchError> {298 Ok(false)299 }300301 fn token_owners(&self, _token: TokenId) -> Vec<<T>::CrossAccountId> {302 vec![]303 }304305 fn token_property(306 &self,307 _token_id: TokenId,308 _key: &up_data_structs::PropertyKey,309 ) -> Option<up_data_structs::PropertyValue> {310 None311 }312313 fn token_properties(314 &self,315 _token: TokenId,316 _keys: Option<Vec<up_data_structs::PropertyKey>>,317 ) -> Vec<up_data_structs::Property> {318 vec![]319 }320321 fn total_supply(&self) -> u32 {322 1323 }324325 fn account_balance(&self, account: T::CrossAccountId) -> u32 {326 let balance = <Pallet<T>>::balance_of(&account);327 (balance != 0).into()328 }329330 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {331 if token != TokenId::default() {332 return 0;333 }334 <Pallet<T>>::balance_of(&account)335 }336337 fn total_pieces(&self, token: TokenId) -> Option<u128> {338 if token != TokenId::default() {339 return None;340 }341 Some(<Pallet<T>>::total_issuance())342 }343344 fn allowance(345 &self,346 _sender: <T>::CrossAccountId,347 _spender: <T>::CrossAccountId,348 _token: TokenId,349 ) -> u128 {350 0351 }352353 fn refungible_extensions(&self) -> Option<&dyn pallet_common::RefungibleExtensions<T>> {354 None355 }356357 fn set_allowance_for_all(358 &self,359 _owner: <T>::CrossAccountId,360 _operator: <T>::CrossAccountId,361 _approve: bool,362 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {363 fail!(<pallet_common::Error<T>>::UnsupportedOperation);364 }365366 fn allowance_for_all(367 &self,368 _owner: <T>::CrossAccountId,369 _operator: <T>::CrossAccountId,370 ) -> bool {371 false372 }373374 fn repair_item(375 &self,376 _token: TokenId,377 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {378 fail!(<pallet_common::Error<T>>::UnsupportedOperation);379 }380}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.rsdiffbeforeafterboth--- a/pallets/fungible/src/common.rs
+++ b/pallets/fungible/src/common.rs
@@ -364,18 +364,16 @@
fail!(<Error<T>>::SettingPropertiesNotAllowed)
}
- 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 check_nesting(
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(())