git.delta.rocks / unique-network / refs/commits / 44071b633884

difftreelog

source

pallets/balances-adapter/src/common.rs9.7 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 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}