1use alloc::{vec, vec::Vec};2use core::marker::PhantomData;3use crate::{Config, NativeFungibleHandle, Pallet};4use frame_support::{fail, traits::Currency, weights::Weight};5use pallet_balances::{weights::SubstrateWeight as BalancesWeight, WeightInfo};6use pallet_common::{erc::CrossAccountId, CommonCollectionOperations, CommonWeightInfo};7use up_data_structs::TokenId;89pub struct CommonWeights<T: Config>(PhantomData<T>);101112impl<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()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()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}87888990impl<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 set_token_property_permissions(176 &self,177 _sender: &<T>::CrossAccountId,178 _property_permissions: Vec<up_data_structs::PropertyKeyPermission>,179 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {180 fail!(<pallet_common::Error<T>>::UnsupportedOperation);181 }182183 fn transfer(184 &self,185 sender: <T>::CrossAccountId,186 to: <T>::CrossAccountId,187 _token: TokenId,188 amount: u128,189 budget: &dyn up_data_structs::budget::Budget,190 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {191 <Pallet<T>>::transfer(self, &sender, &to, amount, budget)192 }193194 fn approve(195 &self,196 _sender: <T>::CrossAccountId,197 _spender: <T>::CrossAccountId,198 _token: TokenId,199 _amount: u128,200 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {201 fail!(<pallet_common::Error<T>>::UnsupportedOperation);202 }203204 fn approve_from(205 &self,206 _sender: <T>::CrossAccountId,207 _from: <T>::CrossAccountId,208 _to: <T>::CrossAccountId,209 _token: TokenId,210 _amount: u128,211 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {212 fail!(<pallet_common::Error<T>>::UnsupportedOperation);213 }214215 fn transfer_from(216 &self,217 sender: <T>::CrossAccountId,218 from: <T>::CrossAccountId,219 to: <T>::CrossAccountId,220 _token: TokenId,221 amount: u128,222 budget: &dyn up_data_structs::budget::Budget,223 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {224 <Pallet<T>>::transfer_from(self, &sender, &from, &to, amount, budget)225 }226227 fn burn_from(228 &self,229 _sender: <T>::CrossAccountId,230 _from: <T>::CrossAccountId,231 _token: TokenId,232 _amount: u128,233 _budget: &dyn up_data_structs::budget::Budget,234 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {235 fail!(<pallet_common::Error<T>>::UnsupportedOperation);236 }237238 fn check_nesting(239 &self,240 _sender: <T>::CrossAccountId,241 _from: (up_data_structs::CollectionId, TokenId),242 _under: TokenId,243 _budget: &dyn up_data_structs::budget::Budget,244 ) -> frame_support::sp_runtime::DispatchResult {245 fail!(<pallet_common::Error<T>>::UnsupportedOperation);246 }247248 fn nest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}249250 fn unnest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}251252 fn account_tokens(&self, account: <T>::CrossAccountId) -> Vec<TokenId> {253 let balance = <T as Config>::Currency::total_balance(account.as_sub());254 let balance: u128 = balance.into();255 if balance != 0 {256 vec![TokenId::default()]257 } else {258 vec![]259 }260 }261262 fn collection_tokens(&self) -> Vec<TokenId> {263 vec![TokenId::default()]264 }265266 fn token_exists(&self, token: TokenId) -> bool {267 token == TokenId::default()268 }269270 fn last_token_id(&self) -> TokenId {271 TokenId::default()272 }273274 fn token_owner(275 &self,276 _token: TokenId,277 ) -> Result<<T>::CrossAccountId, up_data_structs::TokenOwnerError> {278 Err(up_data_structs::TokenOwnerError::MultipleOwners)279 }280281 fn token_owners(&self, _token: TokenId) -> Vec<<T>::CrossAccountId> {282 vec![]283 }284285 fn token_property(286 &self,287 _token_id: TokenId,288 _key: &up_data_structs::PropertyKey,289 ) -> Option<up_data_structs::PropertyValue> {290 None291 }292293 fn token_properties(294 &self,295 _token: TokenId,296 _keys: Option<Vec<up_data_structs::PropertyKey>>,297 ) -> Vec<up_data_structs::Property> {298 vec![]299 }300301 fn total_supply(&self) -> u32 {302 1303 }304305 fn account_balance(&self, account: <T>::CrossAccountId) -> u32 {306 let balance: u128 = <T as Config>::Currency::free_balance(account.as_sub()).into();307 (balance != 0).into()308 }309310 fn balance(&self, account: <T>::CrossAccountId, token: TokenId) -> u128 {311 if token != TokenId::default() {312 return 0;313 }314 <T as Config>::Currency::free_balance(account.as_sub()).into()315 }316317 fn total_pieces(&self, token: TokenId) -> Option<u128> {318 if token != TokenId::default() {319 return None;320 }321 let total = <T as Config>::Currency::total_issuance();322 Some(total.into())323 }324325 fn allowance(326 &self,327 _sender: <T>::CrossAccountId,328 _spender: <T>::CrossAccountId,329 _token: TokenId,330 ) -> u128 {331 0332 }333334 fn refungible_extensions(&self) -> Option<&dyn pallet_common::RefungibleExtensions<T>> {335 None336 }337338 fn set_allowance_for_all(339 &self,340 _owner: <T>::CrossAccountId,341 _operator: <T>::CrossAccountId,342 _approve: bool,343 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {344 fail!(<pallet_common::Error<T>>::UnsupportedOperation);345 }346347 fn allowance_for_all(348 &self,349 _owner: <T>::CrossAccountId,350 _operator: <T>::CrossAccountId,351 ) -> bool {352 false353 }354355 fn repair_item(356 &self,357 _token: TokenId,358 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {359 fail!(<pallet_common::Error<T>>::UnsupportedOperation);360 }361}