git.delta.rocks / unique-network / refs/commits / b4e7cb4fb12a

difftreelog

source

pallets/balances-adapter/src/common.rs9.1 KiBsourcehistory
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 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 = <Pallet<T>>::total_balance(&account);254		if balance != 0 {255			vec![TokenId::default()]256		} else {257			vec![]258		}259	}260261	fn collection_tokens(&self) -> Vec<TokenId> {262		vec![TokenId::default()]263	}264265	fn token_exists(&self, token: TokenId) -> bool {266		token == TokenId::default()267	}268269	fn last_token_id(&self) -> TokenId {270		TokenId::default()271	}272273	fn token_owner(274		&self,275		_token: TokenId,276	) -> Result<<T>::CrossAccountId, up_data_structs::TokenOwnerError> {277		Err(up_data_structs::TokenOwnerError::MultipleOwners)278	}279280	fn token_owners(&self, _token: TokenId) -> Vec<<T>::CrossAccountId> {281		vec![]282	}283284	fn token_property(285		&self,286		_token_id: TokenId,287		_key: &up_data_structs::PropertyKey,288	) -> Option<up_data_structs::PropertyValue> {289		None290	}291292	fn token_properties(293		&self,294		_token: TokenId,295		_keys: Option<Vec<up_data_structs::PropertyKey>>,296	) -> Vec<up_data_structs::Property> {297		vec![]298	}299300	fn total_supply(&self) -> u32 {301		1302	}303304	fn account_balance(&self, account: T::CrossAccountId) -> u32 {305		let balance = <Pallet<T>>::balance_of(&account);306		(balance != 0).into()307	}308309	fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {310		if token != TokenId::default() {311			return 0;312		}313		<Pallet<T>>::balance_of(&account)314	}315316	fn total_pieces(&self, token: TokenId) -> Option<u128> {317		if token != TokenId::default() {318			return None;319		}320		Some(<Pallet<T>>::total_issuance())321	}322323	fn allowance(324		&self,325		_sender: <T>::CrossAccountId,326		_spender: <T>::CrossAccountId,327		_token: TokenId,328	) -> u128 {329		0330	}331332	fn refungible_extensions(&self) -> Option<&dyn pallet_common::RefungibleExtensions<T>> {333		None334	}335336	fn set_allowance_for_all(337		&self,338		_owner: <T>::CrossAccountId,339		_operator: <T>::CrossAccountId,340		_approve: bool,341	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {342		fail!(<pallet_common::Error<T>>::UnsupportedOperation);343	}344345	fn allowance_for_all(346		&self,347		_owner: <T>::CrossAccountId,348		_operator: <T>::CrossAccountId,349	) -> bool {350		false351	}352353	fn repair_item(354		&self,355		_token: TokenId,356	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {357		fail!(<pallet_common::Error<T>>::UnsupportedOperation);358	}359}