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

difftreelog

feat impl dispatchable methods

Trubnikov Sergey2023-04-26parent: #82643c5.patch.diff
in: master

5 files changed

modifiedpallets/balances-adapter/src/common.rsdiffbeforeafterboth
--- a/pallets/balances-adapter/src/common.rs
+++ b/pallets/balances-adapter/src/common.rs
@@ -1,7 +1,12 @@
-use alloc::vec::Vec;
+use alloc::{vec, vec::Vec};
 use core::marker::PhantomData;
 use crate::{Config, NativeFungibleHandle};
-use pallet_common::{CommonCollectionOperations, CommonWeightInfo};
+use frame_support::{
+	traits::{Currency, ExistenceRequirement},
+	fail,
+};
+use pallet_common::{erc::CrossAccountId, CommonCollectionOperations, CommonWeightInfo, with_weight};
+use up_data_structs::TokenId;
 
 pub struct CommonWeights<T: Config>(PhantomData<T>);
 impl<T: Config> CommonWeightInfo<T::CrossAccountId> for CommonWeights<T> {
@@ -92,7 +97,7 @@
 		data: up_data_structs::CreateItemData,
 		nesting_budget: &dyn up_data_structs::budget::Budget,
 	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
-		todo!()
+		fail!(<pallet_common::Error<T>>::UnsupportedOperation);
 	}
 
 	fn create_multiple_items(
@@ -102,7 +107,7 @@
 		data: Vec<up_data_structs::CreateItemData>,
 		nesting_budget: &dyn up_data_structs::budget::Budget,
 	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
-		todo!()
+		fail!(<pallet_common::Error<T>>::UnsupportedOperation);
 	}
 
 	fn create_multiple_items_ex(
@@ -111,26 +116,26 @@
 		data: up_data_structs::CreateItemExData<<T>::CrossAccountId>,
 		nesting_budget: &dyn up_data_structs::budget::Budget,
 	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
-		todo!()
+		fail!(<pallet_common::Error<T>>::UnsupportedOperation);
 	}
 
 	fn burn_item(
 		&self,
 		sender: <T>::CrossAccountId,
-		token: up_data_structs::TokenId,
+		token: TokenId,
 		amount: u128,
 	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
-		todo!()
+		fail!(<pallet_common::Error<T>>::UnsupportedOperation);
 	}
 
 	fn burn_item_recursively(
 		&self,
 		sender: <T>::CrossAccountId,
-		token: up_data_structs::TokenId,
+		token: TokenId,
 		self_budget: &dyn up_data_structs::budget::Budget,
 		breadth_budget: &dyn up_data_structs::budget::Budget,
 	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
-		todo!()
+		fail!(<pallet_common::Error<T>>::UnsupportedOperation);
 	}
 
 	fn set_collection_properties(
@@ -138,7 +143,7 @@
 		sender: <T>::CrossAccountId,
 		properties: Vec<up_data_structs::Property>,
 	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
-		todo!()
+		fail!(<pallet_common::Error<T>>::UnsupportedOperation);
 	}
 
 	fn delete_collection_properties(
@@ -146,27 +151,27 @@
 		sender: &<T>::CrossAccountId,
 		property_keys: Vec<up_data_structs::PropertyKey>,
 	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
-		todo!()
+		fail!(<pallet_common::Error<T>>::UnsupportedOperation);
 	}
 
 	fn set_token_properties(
 		&self,
 		sender: <T>::CrossAccountId,
-		token_id: up_data_structs::TokenId,
+		token_id: TokenId,
 		properties: Vec<up_data_structs::Property>,
 		budget: &dyn up_data_structs::budget::Budget,
 	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
-		todo!()
+		fail!(<pallet_common::Error<T>>::UnsupportedOperation);
 	}
 
 	fn delete_token_properties(
 		&self,
 		sender: <T>::CrossAccountId,
-		token_id: up_data_structs::TokenId,
+		token_id: TokenId,
 		property_keys: Vec<up_data_structs::PropertyKey>,
 		budget: &dyn up_data_structs::budget::Budget,
 	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
-		todo!()
+		fail!(<pallet_common::Error<T>>::UnsupportedOperation);
 	}
 
 	fn set_token_property_permissions(
@@ -174,28 +179,36 @@
 		sender: &<T>::CrossAccountId,
 		property_permissions: Vec<up_data_structs::PropertyKeyPermission>,
 	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
-		todo!()
+		fail!(<pallet_common::Error<T>>::UnsupportedOperation);
 	}
 
 	fn transfer(
 		&self,
 		sender: <T>::CrossAccountId,
 		to: <T>::CrossAccountId,
-		token: up_data_structs::TokenId,
+		token: TokenId,
 		amount: u128,
 		budget: &dyn up_data_structs::budget::Budget,
 	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
-		todo!()
+		with_weight(
+			<T as Config>::Currency::transfer(
+				sender.as_sub(),
+				to.as_sub(),
+				amount.into(),
+				ExistenceRequirement::KeepAlive,
+			),
+			Default::default(),
+		)
 	}
 
 	fn approve(
 		&self,
 		sender: <T>::CrossAccountId,
 		spender: <T>::CrossAccountId,
-		token: up_data_structs::TokenId,
+		token: TokenId,
 		amount: u128,
 	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
-		todo!()
+		fail!(<pallet_common::Error<T>>::UnsupportedOperation);
 	}
 
 	fn approve_from(
@@ -203,10 +216,10 @@
 		sender: <T>::CrossAccountId,
 		from: <T>::CrossAccountId,
 		to: <T>::CrossAccountId,
-		token: up_data_structs::TokenId,
+		token: TokenId,
 		amount: u128,
 	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
-		todo!()
+		fail!(<pallet_common::Error<T>>::UnsupportedOperation);
 	}
 
 	fn transfer_from(
@@ -214,120 +227,129 @@
 		sender: <T>::CrossAccountId,
 		from: <T>::CrossAccountId,
 		to: <T>::CrossAccountId,
-		token: up_data_structs::TokenId,
+		token: TokenId,
 		amount: u128,
 		budget: &dyn up_data_structs::budget::Budget,
 	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
-		todo!()
+		with_weight(
+			<T as Config>::Currency::transfer(
+				sender.as_sub(),
+				to.as_sub(),
+				amount.into(),
+				ExistenceRequirement::KeepAlive,
+			),
+			Default::default(),
+		)
 	}
 
 	fn burn_from(
 		&self,
 		sender: <T>::CrossAccountId,
 		from: <T>::CrossAccountId,
-		token: up_data_structs::TokenId,
+		token: TokenId,
 		amount: u128,
 		budget: &dyn up_data_structs::budget::Budget,
 	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
-		todo!()
+		fail!(<pallet_common::Error<T>>::UnsupportedOperation);
 	}
 
 	fn check_nesting(
 		&self,
 		sender: <T>::CrossAccountId,
-		from: (up_data_structs::CollectionId, up_data_structs::TokenId),
-		under: up_data_structs::TokenId,
+		from: (up_data_structs::CollectionId, TokenId),
+		under: TokenId,
 		budget: &dyn up_data_structs::budget::Budget,
 	) -> frame_support::sp_runtime::DispatchResult {
-		todo!()
+		fail!(<pallet_common::Error<T>>::UnsupportedOperation);
 	}
 
-	fn nest(
-		&self,
-		under: up_data_structs::TokenId,
-		to_nest: (up_data_structs::CollectionId, up_data_structs::TokenId),
-	) {
-		todo!()
-	}
+	fn nest(&self, under: TokenId, to_nest: (up_data_structs::CollectionId, TokenId)) {}
 
-	fn unnest(
-		&self,
-		under: up_data_structs::TokenId,
-		to_nest: (up_data_structs::CollectionId, up_data_structs::TokenId),
-	) {
-		todo!()
-	}
+	fn unnest(&self, under: TokenId, to_nest: (up_data_structs::CollectionId, TokenId)) {}
 
-	fn account_tokens(&self, account: <T>::CrossAccountId) -> Vec<up_data_structs::TokenId> {
-		todo!()
+	fn account_tokens(&self, account: <T>::CrossAccountId) -> Vec<TokenId> {
+		let balance = <T as Config>::Currency::total_balance(account.as_sub());
+		if balance != 0 {
+			vec![TokenId::default()]
+		} else {
+			vec![]
+		}
 	}
 
-	fn collection_tokens(&self) -> Vec<up_data_structs::TokenId> {
-		todo!()
+	fn collection_tokens(&self) -> Vec<TokenId> {
+		vec![TokenId::default()]
 	}
 
-	fn token_exists(&self, token: up_data_structs::TokenId) -> bool {
-		todo!()
+	fn token_exists(&self, token: TokenId) -> bool {
+		token == TokenId::default()
 	}
 
-	fn last_token_id(&self) -> up_data_structs::TokenId {
-		todo!()
+	fn last_token_id(&self) -> TokenId {
+		TokenId::default()
 	}
 
 	fn token_owner(
 		&self,
-		token: up_data_structs::TokenId,
+		token: TokenId,
 	) -> Result<<T>::CrossAccountId, up_data_structs::TokenOwnerError> {
-		todo!()
+		Err(up_data_structs::TokenOwnerError::MultipleOwners)
 	}
 
-	fn token_owners(&self, token: up_data_structs::TokenId) -> Vec<<T>::CrossAccountId> {
-		todo!()
+	fn token_owners(&self, token: TokenId) -> Vec<<T>::CrossAccountId> {
+		vec![]
 	}
 
 	fn token_property(
 		&self,
-		token_id: up_data_structs::TokenId,
+		token_id: TokenId,
 		key: &up_data_structs::PropertyKey,
 	) -> Option<up_data_structs::PropertyValue> {
-		todo!()
+		None
 	}
 
 	fn token_properties(
 		&self,
-		token: up_data_structs::TokenId,
+		token: TokenId,
 		keys: Option<Vec<up_data_structs::PropertyKey>>,
 	) -> Vec<up_data_structs::Property> {
-		todo!()
+		vec![]
 	}
 
 	fn total_supply(&self) -> u32 {
-		todo!()
+		1
 	}
 
 	fn account_balance(&self, account: <T>::CrossAccountId) -> u32 {
-		todo!()
+		let balance: u128 = <T as Config>::Currency::free_balance(account.as_sub()).into();
+		(balance != 0).into()
 	}
 
-	fn balance(&self, account: <T>::CrossAccountId, token: up_data_structs::TokenId) -> u128 {
-		todo!()
+	fn balance(&self, account: <T>::CrossAccountId, token: TokenId) -> u128 {
+		if token != TokenId::default() {
+			return 0;
+		}
+		<T as Config>::Currency::free_balance(account.as_sub()).into()
 	}
 
-	fn total_pieces(&self, token: up_data_structs::TokenId) -> Option<u128> {
-		todo!()
+	fn total_pieces(&self, token: TokenId) -> Option<u128> {
+		if token != TokenId::default() {
+			return None;
+		}
+		let total = <T as Config>::Currency::total_issuance();
+		Some(total.into())
 	}
 
 	fn allowance(
 		&self,
 		sender: <T>::CrossAccountId,
 		spender: <T>::CrossAccountId,
-		token: up_data_structs::TokenId,
+		token: TokenId,
 	) -> u128 {
-		todo!()
+		0
 	}
 
 	fn refungible_extensions(&self) -> Option<&dyn pallet_common::RefungibleExtensions<T>> {
-		todo!()
+		None
 	}
 
 	fn set_allowance_for_all(
@@ -336,17 +358,17 @@
 		operator: <T>::CrossAccountId,
 		approve: bool,
 	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
-		todo!()
+		fail!(<pallet_common::Error<T>>::UnsupportedOperation);
 	}
 
 	fn allowance_for_all(&self, owner: <T>::CrossAccountId, operator: <T>::CrossAccountId) -> bool {
-		todo!()
+		false
 	}
 
 	fn repair_item(
 		&self,
-		token: up_data_structs::TokenId,
+		token: TokenId,
 	) -> frame_support::pallet_prelude::DispatchResultWithPostInfo {
-		todo!()
+		fail!(<pallet_common::Error<T>>::UnsupportedOperation);
 	}
 }
modifiedpallets/balances-adapter/src/lib.rsdiffbeforeafterboth
44 Self::AccountId,44 Self::AccountId,
45 Balance = Self::CurrencyBalance,45 Balance = Self::CurrencyBalance,
46 >;46 >;
47 type CurrencyBalance: Into<U256> + TryFrom<U256>;47 type CurrencyBalance: Into<U256> + TryFrom<U256> + PartialEq<u128> + From<u128> + Into<u128>;
4848
49 type Decimals: Get<u8>;49 type Decimals: Get<u8>;
50 type Name: Get<String>;50 type Name: Get<String>;
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -462,6 +462,7 @@
 	}
 
 	const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
+	pub const NATIVE_FINGIBLE_COLLECTION_ID: CollectionId = CollectionId(0);
 
 	#[pallet::pallet]
 	#[pallet::storage_version(STORAGE_VERSION)]
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -440,6 +440,10 @@
 			collection_id: CollectionId,
 			address: T::CrossAccountId,
 		) -> DispatchResult {
+			if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+				fail!(<pallet_common::Error<T>>::UnsupportedOperation);
+			}
+
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
 			let collection = <CollectionHandle<T>>::try_get(collection_id)?;
 			collection.check_is_internal()?;
@@ -467,6 +471,10 @@
 			collection_id: CollectionId,
 			address: T::CrossAccountId,
 		) -> DispatchResult {
+			if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+				fail!(<pallet_common::Error<T>>::UnsupportedOperation);
+			}
+
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
 			let collection = <CollectionHandle<T>>::try_get(collection_id)?;
 			collection.check_is_internal()?;
@@ -493,6 +501,9 @@
 			collection_id: CollectionId,
 			new_owner: T::AccountId,
 		) -> DispatchResult {
+			if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+				fail!(<pallet_common::Error<T>>::UnsupportedOperation);
+			}
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
 			let new_owner = T::CrossAccountId::from_sub(new_owner);
 			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
@@ -522,6 +533,9 @@
 			collection_id: CollectionId,
 			new_admin_id: T::CrossAccountId,
 		) -> DispatchResult {
+			if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+				fail!(<pallet_common::Error<T>>::UnsupportedOperation);
+			}
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
 			let collection = <CollectionHandle<T>>::try_get(collection_id)?;
 			<PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)
@@ -548,6 +562,9 @@
 			collection_id: CollectionId,
 			account_id: T::CrossAccountId,
 		) -> DispatchResult {
+			if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+				fail!(<pallet_common::Error<T>>::UnsupportedOperation);
+			}
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
 			let collection = <CollectionHandle<T>>::try_get(collection_id)?;
 			<PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)
@@ -573,6 +590,9 @@
 			collection_id: CollectionId,
 			new_sponsor: T::AccountId,
 		) -> DispatchResult {
+			if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+				fail!(<pallet_common::Error<T>>::UnsupportedOperation);
+			}
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
 			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
 			target_collection.set_sponsor(&sender, new_sponsor.clone())
@@ -597,6 +617,9 @@
 			origin: OriginFor<T>,
 			collection_id: CollectionId,
 		) -> DispatchResult {
+			if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+				fail!(<pallet_common::Error<T>>::UnsupportedOperation);
+			}
 			let sender = ensure_signed(origin)?;
 			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
 			target_collection.confirm_sponsorship(&sender)
@@ -617,6 +640,9 @@
 			origin: OriginFor<T>,
 			collection_id: CollectionId,
 		) -> DispatchResult {
+			if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+				fail!(<pallet_common::Error<T>>::UnsupportedOperation);
+			}
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
 			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
 			target_collection.remove_sponsor(&sender)
@@ -894,6 +920,9 @@
 			collection_id: CollectionId,
 			value: bool,
 		) -> DispatchResult {
+			if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+				fail!(<pallet_common::Error<T>>::UnsupportedOperation);
+			}
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
 			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
 			target_collection.check_is_internal()?;
@@ -1146,6 +1175,9 @@
 			collection_id: CollectionId,
 			new_limit: CollectionLimits,
 		) -> DispatchResult {
+			if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+				fail!(<pallet_common::Error<T>>::UnsupportedOperation);
+			}
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
 			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
 			<PalletCommon<T>>::update_limits(&sender, &mut target_collection, new_limit)
@@ -1170,6 +1202,9 @@
 			collection_id: CollectionId,
 			new_permission: CollectionPermissions,
 		) -> DispatchResult {
+			if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+				fail!(<pallet_common::Error<T>>::UnsupportedOperation);
+			}
 			let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
 			let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
 			<PalletCommon<T>>::update_permissions(&sender, &mut target_collection, new_permission)
@@ -1238,6 +1273,9 @@
 			origin: OriginFor<T>,
 			collection_id: CollectionId,
 		) -> DispatchResult {
+			if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+				fail!(<pallet_common::Error<T>>::UnsupportedOperation);
+			}
 			ensure_root(origin)?;
 			<PalletCommon<T>>::repair_collection(collection_id)
 		}
modifiedruntime/common/dispatch.rsdiffbeforeafterboth
--- a/runtime/common/dispatch.rs
+++ b/runtime/common/dispatch.rs
@@ -14,7 +14,7 @@
 // You should have received a copy of the GNU General Public License
 // along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
 
-use frame_support::{dispatch::DispatchResult, ensure};
+use frame_support::{dispatch::DispatchResult, ensure, fail};
 use pallet_evm::{PrecompileHandle, PrecompileResult};
 use sp_core::H160;
 use sp_runtime::DispatchError;
@@ -100,6 +100,10 @@
 	}
 
 	fn destroy(sender: T::CrossAccountId, collection_id: CollectionId) -> DispatchResult {
+		if collection_id == pallet_common::NATIVE_FINGIBLE_COLLECTION_ID {
+			fail!(<pallet_common::Error<T>>::UnsupportedOperation);
+		}
+
 		let collection = <CollectionHandle<T>>::try_get(collection_id)?;
 		collection.check_is_internal()?;