1use alloc::{vec, vec::Vec};2use core::marker::PhantomData;34use frame_support::{fail, weights::Weight};5use pallet_balances::{weights::SubstrateWeight as BalancesWeight, WeightInfo};6use pallet_common::{CommonCollectionOperations, CommonWeightInfo};7use up_data_structs::TokenId;89use crate::{Config, NativeFungibleHandle, Pallet};1011pub struct CommonWeights<T: Config>(PhantomData<T>);121314impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {15 fn create_multiple_items(_amount: &[up_data_structs::CreateItemData]) -> Weight {16 Weight::default()17 }1819 fn create_multiple_items_ex(20 _cost: &up_data_structs::CreateItemExData<T::CrossAccountId>,21 ) -> Weight {22 Weight::default()23 }2425 fn burn_item() -> Weight {26 Weight::default()27 }2829 fn set_collection_properties(_amount: u32) -> Weight {30 Weight::default()31 }3233 fn delete_collection_properties(_amount: u32) -> Weight {34 Weight::default()35 }3637 fn set_token_properties(_amount: u32) -> Weight {38 Weight::default()39 }4041 fn delete_token_properties(_amount: u32) -> Weight {42 Weight::default()43 }4445 fn set_token_property_permissions(_amount: u32) -> Weight {46 Weight::default()47 }4849 fn transfer() -> Weight {50 <BalancesWeight<T> as WeightInfo>::transfer_allow_death()51 }5253 fn approve() -> Weight {54 Weight::default()55 }5657 fn approve_from() -> Weight {58 Weight::default()59 }6061 fn transfer_from() -> Weight {62 <BalancesWeight<T> as WeightInfo>::transfer_allow_death()63 }6465 fn burn_from() -> Weight {66 Weight::default()67 }6869 fn burn_recursively_self_raw() -> Weight {70 Weight::default()71 }7273 fn burn_recursively_breadth_raw(_amount: u32) -> Weight {74 Weight::default()75 }7677 fn token_owner() -> Weight {78 Weight::default()79 }8081 fn set_allowance_for_all() -> Weight {82 Weight::default()83 }8485 fn force_repair_item() -> Weight {86 Weight::default()87 }88}89909192impl<T: Config> CommonCollectionOperations<T> for NativeFungibleHandle<T> {93 fn create_item(94 &self,95 _sender: <T>::CrossAccountId,96 _to: <T>::CrossAccountId,97 _data: up_data_structs::CreateItemData,98 _nesting_budget: &dyn up_data_structs::budget::Budget,99 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {100 fail!(<pallet_common::Error<T>>::UnsupportedOperation);101 }102103 fn create_multiple_items(104 &self,105 _sender: <T>::CrossAccountId,106 _to: <T>::CrossAccountId,107 _data: Vec<up_data_structs::CreateItemData>,108 _nesting_budget: &dyn up_data_structs::budget::Budget,109 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {110 fail!(<pallet_common::Error<T>>::UnsupportedOperation);111 }112113 fn create_multiple_items_ex(114 &self,115 _sender: <T>::CrossAccountId,116 _data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,117 _nesting_budget: &dyn up_data_structs::budget::Budget,118 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {119 fail!(<pallet_common::Error<T>>::UnsupportedOperation);120 }121122 fn burn_item(123 &self,124 _sender: <T>::CrossAccountId,125 _token: TokenId,126 _amount: u128,127 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {128 fail!(<pallet_common::Error<T>>::UnsupportedOperation);129 }130131 fn burn_item_recursively(132 &self,133 _sender: <T>::CrossAccountId,134 _token: TokenId,135 _self_budget: &dyn up_data_structs::budget::Budget,136 _breadth_budget: &dyn up_data_structs::budget::Budget,137 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {138 fail!(<pallet_common::Error<T>>::UnsupportedOperation);139 }140141 fn set_collection_properties(142 &self,143 _sender: <T>::CrossAccountId,144 _properties: Vec<up_data_structs::Property>,145 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {146 fail!(<pallet_common::Error<T>>::UnsupportedOperation);147 }148149 fn delete_collection_properties(150 &self,151 _sender: &<T>::CrossAccountId,152 _property_keys: Vec<up_data_structs::PropertyKey>,153 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {154 fail!(<pallet_common::Error<T>>::UnsupportedOperation);155 }156157 fn set_token_properties(158 &self,159 _sender: <T>::CrossAccountId,160 _token_id: TokenId,161 _properties: Vec<up_data_structs::Property>,162 _budget: &dyn up_data_structs::budget::Budget,163 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {164 fail!(<pallet_common::Error<T>>::UnsupportedOperation);165 }166167 fn delete_token_properties(168 &self,169 _sender: <T>::CrossAccountId,170 _token_id: TokenId,171 _property_keys: Vec<up_data_structs::PropertyKey>,172 _budget: &dyn up_data_structs::budget::Budget,173 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {174 fail!(<pallet_common::Error<T>>::UnsupportedOperation);175 }176177 fn get_token_properties_raw(178 &self,179 _token_id: TokenId,180 ) -> Option<up_data_structs::TokenProperties> {181 182 None183 }184185 fn set_token_properties_raw(&self, _token_id: TokenId, _map: up_data_structs::TokenProperties) {186 187 }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}