1use alloc::{vec, vec::Vec};2use core::marker::PhantomData;34use frame_support::{ensure, fail, weights::Weight};5use pallet_balances::{weights::SubstrateWeight as BalancesWeight, WeightInfo};6use pallet_common::{CommonCollectionOperations, CommonWeightInfo, Error as CommonError};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 set_token_properties(_amount: u32) -> Weight {34 Weight::default()35 }3637 fn set_token_property_permissions(_amount: u32) -> Weight {38 Weight::default()39 }4041 fn transfer() -> Weight {42 <BalancesWeight<T> as WeightInfo>::transfer_allow_death()43 }4445 fn approve() -> Weight {46 Weight::default()47 }4849 fn approve_from() -> Weight {50 Weight::default()51 }5253 fn transfer_from() -> Weight {54 <BalancesWeight<T> as WeightInfo>::transfer_allow_death()55 }5657 fn burn_from() -> Weight {58 Weight::default()59 }6061 fn set_allowance_for_all() -> Weight {62 Weight::default()63 }6465 fn force_repair_item() -> Weight {66 Weight::default()67 }68}69707172impl<T: Config> CommonCollectionOperations<T> for NativeFungibleHandle<T> {73 fn create_item(74 &self,75 _sender: <T>::CrossAccountId,76 _to: <T>::CrossAccountId,77 _data: up_data_structs::CreateItemData,78 _nesting_budget: &dyn up_data_structs::budget::Budget,79 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {80 fail!(<CommonError<T>>::UnsupportedOperation);81 }8283 fn create_multiple_items(84 &self,85 _sender: <T>::CrossAccountId,86 _to: <T>::CrossAccountId,87 _data: Vec<up_data_structs::CreateItemData>,88 _nesting_budget: &dyn up_data_structs::budget::Budget,89 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {90 fail!(<CommonError<T>>::UnsupportedOperation);91 }9293 fn create_multiple_items_ex(94 &self,95 _sender: <T>::CrossAccountId,96 _data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,97 _nesting_budget: &dyn up_data_structs::budget::Budget,98 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {99 fail!(<CommonError<T>>::UnsupportedOperation);100 }101102 fn burn_item(103 &self,104 _sender: <T>::CrossAccountId,105 _token: TokenId,106 _amount: u128,107 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {108 fail!(<CommonError<T>>::UnsupportedOperation);109 }110111 fn set_collection_properties(112 &self,113 _sender: <T>::CrossAccountId,114 _properties: Vec<up_data_structs::Property>,115 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {116 fail!(<CommonError<T>>::UnsupportedOperation);117 }118119 fn delete_collection_properties(120 &self,121 _sender: &<T>::CrossAccountId,122 _property_keys: Vec<up_data_structs::PropertyKey>,123 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {124 fail!(<CommonError<T>>::UnsupportedOperation);125 }126127 fn set_token_properties(128 &self,129 _sender: <T>::CrossAccountId,130 _token_id: TokenId,131 _properties: Vec<up_data_structs::Property>,132 _budget: &dyn up_data_structs::budget::Budget,133 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {134 fail!(<CommonError<T>>::UnsupportedOperation);135 }136137 fn delete_token_properties(138 &self,139 _sender: <T>::CrossAccountId,140 _token_id: TokenId,141 _property_keys: Vec<up_data_structs::PropertyKey>,142 _budget: &dyn up_data_structs::budget::Budget,143 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {144 fail!(<CommonError<T>>::UnsupportedOperation);145 }146147 fn get_token_properties_raw(148 &self,149 _token_id: TokenId,150 ) -> Option<up_data_structs::TokenProperties> {151 152 None153 }154155 fn set_token_properties_raw(&self, _token_id: TokenId, _map: up_data_structs::TokenProperties) {156 157 }158159 fn set_token_property_permissions(160 &self,161 _sender: &<T>::CrossAccountId,162 _property_permissions: Vec<up_data_structs::PropertyKeyPermission>,163 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {164 fail!(<CommonError<T>>::UnsupportedOperation);165 }166167 fn transfer(168 &self,169 sender: <T>::CrossAccountId,170 to: <T>::CrossAccountId,171 token: TokenId,172 amount: u128,173 _budget: &dyn up_data_structs::budget::Budget,174 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {175 ensure!(176 token == TokenId::default(),177 <CommonError<T>>::FungibleItemsHaveNoId178 );179180 <Pallet<T>>::transfer(&sender, &to, amount)181 }182183 fn approve(184 &self,185 _sender: <T>::CrossAccountId,186 _spender: <T>::CrossAccountId,187 _token: TokenId,188 _amount: u128,189 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {190 fail!(<CommonError<T>>::UnsupportedOperation);191 }192193 fn approve_from(194 &self,195 _sender: <T>::CrossAccountId,196 _from: <T>::CrossAccountId,197 _to: <T>::CrossAccountId,198 _token: TokenId,199 _amount: u128,200 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {201 fail!(<CommonError<T>>::UnsupportedOperation);202 }203204 fn transfer_from(205 &self,206 sender: <T>::CrossAccountId,207 from: <T>::CrossAccountId,208 to: <T>::CrossAccountId,209 token: TokenId,210 amount: u128,211 budget: &dyn up_data_structs::budget::Budget,212 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {213 ensure!(214 token == TokenId::default(),215 <CommonError<T>>::FungibleItemsHaveNoId216 );217218 <Pallet<T>>::transfer_from(&sender, &from, &to, amount, budget)219 }220221 fn burn_from(222 &self,223 _sender: <T>::CrossAccountId,224 _from: <T>::CrossAccountId,225 _token: TokenId,226 _amount: u128,227 _budget: &dyn up_data_structs::budget::Budget,228 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {229 fail!(<CommonError<T>>::UnsupportedOperation);230 }231232 fn check_nesting(233 &self,234 _sender: &<T>::CrossAccountId,235 _from: (up_data_structs::CollectionId, TokenId),236 _under: TokenId,237 _budget: &dyn up_data_structs::budget::Budget,238 ) -> frame_support::sp_runtime::DispatchResult {239 fail!(<CommonError<T>>::UnsupportedOperation);240 }241242 fn nest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}243244 fn unnest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}245246 fn account_tokens(&self, account: <T>::CrossAccountId) -> Vec<TokenId> {247 let balance = <Pallet<T>>::total_balance(&account);248 if balance != 0 {249 vec![TokenId::default()]250 } else {251 vec![]252 }253 }254255 fn collection_tokens(&self) -> Vec<TokenId> {256 vec![TokenId::default()]257 }258259 fn token_exists(&self, token: TokenId) -> bool {260 token == TokenId::default()261 }262263 fn last_token_id(&self) -> TokenId {264 TokenId::default()265 }266267 fn token_owner(268 &self,269 _token: TokenId,270 ) -> Result<<T>::CrossAccountId, up_data_structs::TokenOwnerError> {271 Err(up_data_structs::TokenOwnerError::MultipleOwners)272 }273274 fn check_token_indirect_owner(275 &self,276 _token: TokenId,277 _maybe_owner: &<T>::CrossAccountId,278 _nesting_budget: &dyn up_data_structs::budget::Budget,279 ) -> Result<bool, frame_support::sp_runtime::DispatchError> {280 Ok(false)281 }282283 fn token_owners(&self, _token: TokenId) -> Vec<<T>::CrossAccountId> {284 vec![]285 }286287 fn token_property(288 &self,289 _token_id: TokenId,290 _key: &up_data_structs::PropertyKey,291 ) -> Option<up_data_structs::PropertyValue> {292 None293 }294295 fn token_properties(296 &self,297 _token: TokenId,298 _keys: Option<Vec<up_data_structs::PropertyKey>>,299 ) -> Vec<up_data_structs::Property> {300 vec![]301 }302303 fn total_supply(&self) -> u32 {304 1305 }306307 fn account_balance(&self, account: T::CrossAccountId) -> u32 {308 let balance = <Pallet<T>>::balance_of(&account);309 (balance != 0).into()310 }311312 fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {313 if token != TokenId::default() {314 return 0;315 }316 <Pallet<T>>::balance_of(&account)317 }318319 fn total_pieces(&self, token: TokenId) -> Option<u128> {320 if token != TokenId::default() {321 return None;322 }323 Some(<Pallet<T>>::total_issuance())324 }325326 fn allowance(327 &self,328 _sender: <T>::CrossAccountId,329 _spender: <T>::CrossAccountId,330 _token: TokenId,331 ) -> u128 {332 0333 }334335 fn refungible_extensions(&self) -> Option<&dyn pallet_common::RefungibleExtensions<T>> {336 None337 }338339 fn set_allowance_for_all(340 &self,341 _owner: <T>::CrossAccountId,342 _operator: <T>::CrossAccountId,343 _approve: bool,344 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {345 fail!(<CommonError<T>>::UnsupportedOperation);346 }347348 fn allowance_for_all(349 &self,350 _owner: <T>::CrossAccountId,351 _operator: <T>::CrossAccountId,352 ) -> bool {353 false354 }355356 fn repair_item(357 &self,358 _token: TokenId,359 ) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {360 fail!(<CommonError<T>>::UnsupportedOperation);361 }362}