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

difftreelog

source

pallets/balances-adapter/src/common.rs9.6 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_raw(176		&self,177		_token_id: TokenId,178	) -> Option<up_data_structs::TokenProperties> {179		// No token properties are defined on fungibles180		None181	}182183	fn set_token_properties_raw(&self, _token_id: TokenId, _map: up_data_structs::TokenProperties) {184		// No token properties are defined on fungibles185	}186187	fn set_token_property_permissions(188		&self,189		_sender: &<T>::CrossAccountId,190		_property_permissions: Vec<up_data_structs::PropertyKeyPermission>,191	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {192		fail!(<pallet_common::Error<T>>::UnsupportedOperation);193	}194195	fn transfer(196		&self,197		sender: <T>::CrossAccountId,198		to: <T>::CrossAccountId,199		_token: TokenId,200		amount: u128,201		budget: &dyn up_data_structs::budget::Budget,202	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {203		<Pallet<T>>::transfer(self, &sender, &to, amount, budget)204	}205206	fn approve(207		&self,208		_sender: <T>::CrossAccountId,209		_spender: <T>::CrossAccountId,210		_token: TokenId,211		_amount: u128,212	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {213		fail!(<pallet_common::Error<T>>::UnsupportedOperation);214	}215216	fn approve_from(217		&self,218		_sender: <T>::CrossAccountId,219		_from: <T>::CrossAccountId,220		_to: <T>::CrossAccountId,221		_token: TokenId,222		_amount: u128,223	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {224		fail!(<pallet_common::Error<T>>::UnsupportedOperation);225	}226227	fn transfer_from(228		&self,229		sender: <T>::CrossAccountId,230		from: <T>::CrossAccountId,231		to: <T>::CrossAccountId,232		_token: TokenId,233		amount: u128,234		budget: &dyn up_data_structs::budget::Budget,235	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {236		<Pallet<T>>::transfer_from(self, &sender, &from, &to, amount, budget)237	}238239	fn burn_from(240		&self,241		_sender: <T>::CrossAccountId,242		_from: <T>::CrossAccountId,243		_token: TokenId,244		_amount: u128,245		_budget: &dyn up_data_structs::budget::Budget,246	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {247		fail!(<pallet_common::Error<T>>::UnsupportedOperation);248	}249250	fn check_nesting(251		&self,252		_sender: <T>::CrossAccountId,253		_from: (up_data_structs::CollectionId, TokenId),254		_under: TokenId,255		_budget: &dyn up_data_structs::budget::Budget,256	) -> frame_support::sp_runtime::DispatchResult {257		fail!(<pallet_common::Error<T>>::UnsupportedOperation);258	}259260	fn nest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}261262	fn unnest(&self, _under: TokenId, _to_nest: (up_data_structs::CollectionId, TokenId)) {}263264	fn account_tokens(&self, account: <T>::CrossAccountId) -> Vec<TokenId> {265		let balance = <Pallet<T>>::total_balance(&account);266		if balance != 0 {267			vec![TokenId::default()]268		} else {269			vec![]270		}271	}272273	fn collection_tokens(&self) -> Vec<TokenId> {274		vec![TokenId::default()]275	}276277	fn token_exists(&self, token: TokenId) -> bool {278		token == TokenId::default()279	}280281	fn last_token_id(&self) -> TokenId {282		TokenId::default()283	}284285	fn token_owner(286		&self,287		_token: TokenId,288	) -> Result<<T>::CrossAccountId, up_data_structs::TokenOwnerError> {289		Err(up_data_structs::TokenOwnerError::MultipleOwners)290	}291292	fn check_token_indirect_owner(293		&self,294		_token: TokenId,295		_maybe_owner: &<T>::CrossAccountId,296		_nesting_budget: &dyn up_data_structs::budget::Budget,297	) -> Result<bool, frame_support::sp_runtime::DispatchError> {298		Ok(false)299	}300301	fn token_owners(&self, _token: TokenId) -> Vec<<T>::CrossAccountId> {302		vec![]303	}304305	fn token_property(306		&self,307		_token_id: TokenId,308		_key: &up_data_structs::PropertyKey,309	) -> Option<up_data_structs::PropertyValue> {310		None311	}312313	fn token_properties(314		&self,315		_token: TokenId,316		_keys: Option<Vec<up_data_structs::PropertyKey>>,317	) -> Vec<up_data_structs::Property> {318		vec![]319	}320321	fn total_supply(&self) -> u32 {322		1323	}324325	fn account_balance(&self, account: T::CrossAccountId) -> u32 {326		let balance = <Pallet<T>>::balance_of(&account);327		(balance != 0).into()328	}329330	fn balance(&self, account: T::CrossAccountId, token: TokenId) -> u128 {331		if token != TokenId::default() {332			return 0;333		}334		<Pallet<T>>::balance_of(&account)335	}336337	fn total_pieces(&self, token: TokenId) -> Option<u128> {338		if token != TokenId::default() {339			return None;340		}341		Some(<Pallet<T>>::total_issuance())342	}343344	fn allowance(345		&self,346		_sender: <T>::CrossAccountId,347		_spender: <T>::CrossAccountId,348		_token: TokenId,349	) -> u128 {350		0351	}352353	fn refungible_extensions(&self) -> Option<&dyn pallet_common::RefungibleExtensions<T>> {354		None355	}356357	fn set_allowance_for_all(358		&self,359		_owner: <T>::CrossAccountId,360		_operator: <T>::CrossAccountId,361		_approve: bool,362	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {363		fail!(<pallet_common::Error<T>>::UnsupportedOperation);364	}365366	fn allowance_for_all(367		&self,368		_owner: <T>::CrossAccountId,369		_operator: <T>::CrossAccountId,370	) -> bool {371		false372	}373374	fn repair_item(375		&self,376		_token: TokenId,377	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {378		fail!(<pallet_common::Error<T>>::UnsupportedOperation);379	}380}