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

difftreelog

feat switch `common` from `Currency` trait to `fungible::*` traits

Grigoriy Simonov2023-05-22parent: #3539f20.patch.diff
in: master

2 files changed

modifiedpallets/common/src/benchmarking.rsdiffbeforeafterboth
--- a/pallets/common/src/benchmarking.rs
+++ b/pallets/common/src/benchmarking.rs
@@ -27,12 +27,12 @@
 	MAX_PROPERTIES_PER_ITEM,
 };
 use frame_support::{
-	traits::{Currency, Get},
+	traits::{Get, fungible::Balanced, Imbalance, tokens::Precision},
 	pallet_prelude::ConstU32,
 	BoundedVec,
 };
 use core::convert::TryInto;
-use sp_runtime::DispatchError;
+use sp_runtime::{DispatchError, traits::Zero};
 
 const SEED: u32 = 1;
 
@@ -85,7 +85,12 @@
 	) -> Result<CollectionId, DispatchError>,
 	cast: impl FnOnce(CollectionHandle<T>) -> R,
 ) -> Result<R, DispatchError> {
-	<T as Config>::Currency::deposit_creating(&owner.as_sub(), T::CollectionCreationPrice::get());
+	let imbalance = <T as Config>::Currency::deposit(
+		&owner.as_sub(),
+		T::CollectionCreationPrice::get(),
+		Precision::Exact,
+	)?;
+	debug_assert!(imbalance.peek().is_zero());
 	let name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();
 	let description = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();
 	let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();
modifiedpallets/common/src/lib.rsdiffbeforeafterboth
64use frame_support::{64use frame_support::{
65 dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo, Weight, PostDispatchInfo},65 dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo, Weight, PostDispatchInfo},
66 ensure,66 ensure,
67 traits::{Imbalance, Get, Currency, WithdrawReasons, ExistenceRequirement},67 traits::{
68 Get,
69 fungible::{Balanced, Debt, Inspect},
70 tokens::{Imbalance, Precision, Preservation},
71 },
68 dispatch::Pays,72 dispatch::Pays,
69 transactional, fail,73 transactional, fail,
8589
86pub use pallet::*;90pub use pallet::*;
87use sp_core::H160;91use sp_core::H160;
88use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};92use sp_runtime::{ArithmeticError, DispatchError, DispatchResult, traits::Zero};
8993
90#[cfg(feature = "runtime-benchmarks")]94#[cfg(feature = "runtime-benchmarks")]
91pub mod benchmarking;95pub mod benchmarking;
424 use super::*;428 use super::*;
425 use dispatch::CollectionDispatch;429 use dispatch::CollectionDispatch;
426 use frame_support::{Blake2_128Concat, pallet_prelude::*, storage::Key, traits::StorageVersion};430 use frame_support::{Blake2_128Concat, pallet_prelude::*, storage::Key, traits::StorageVersion};
427 use frame_support::traits::Currency;
428 use up_data_structs::{TokenId, mapping::TokenAddressMapping};431 use up_data_structs::{TokenId, mapping::TokenAddressMapping};
429 use scale_info::TypeInfo;432 use scale_info::TypeInfo;
430 use weights::WeightInfo;433 use weights::WeightInfo;
440 type RuntimeEvent: IsType<<Self as frame_system::Config>::RuntimeEvent> + From<Event<Self>>;443 type RuntimeEvent: IsType<<Self as frame_system::Config>::RuntimeEvent> + From<Event<Self>>;
441444
442 /// Handler of accounts and payment.445 /// Handler of accounts and payment.
443 type Currency: Currency<Self::AccountId>;446 type Currency: Balanced<Self::AccountId> + Inspect<Self::AccountId>;
444447
445 /// Set price to create a collection.448 /// Set price to create a collection.
446 #[pallet::constant]449 #[pallet::constant]
447 type CollectionCreationPrice: Get<450 type CollectionCreationPrice: Get<
448 <<Self as Config>::Currency as Currency<Self::AccountId>>::Balance,451 <<Self as Config>::Currency as Inspect<Self::AccountId>>::Balance,
449 >;452 >;
450453
451 /// Dispatcher of operations on collections.454 /// Dispatcher of operations on collections.
11121115
1113 // Take a (non-refundable) deposit of collection creation1116 // Take a (non-refundable) deposit of collection creation
1114 {1117 {
1115 let mut imbalance =1118 let mut imbalance = <Debt<T::AccountId, <T as Config>::Currency>>::zero();
1116 <<<T as Config>::Currency as Currency<T::AccountId>>::PositiveImbalance>::zero();
1117 imbalance.subsume(1119 imbalance.subsume(<T as Config>::Currency::deposit(
1118 <<T as Config>::Currency as Currency<T::AccountId>>::deposit_creating(
1119 &T::TreasuryAccountId::get(),1120 &T::TreasuryAccountId::get(),
1120 T::CollectionCreationPrice::get(),1121 T::CollectionCreationPrice::get(),
1122 Precision::Exact,
1121 ),1123 )?);
1122 );1124 let credit =
1123 <T as Config>::Currency::settle(1125 <T as Config>::Currency::settle(payer.as_sub(), imbalance, Preservation::Preserve)
1124 payer.as_sub(),
1125 imbalance,
1126 WithdrawReasons::TRANSFER,
1127 ExistenceRequirement::KeepAlive,
1128 )
1129 .map_err(|_| Error::<T>::NotSufficientFounds)?;1126 .map_err(|_| Error::<T>::NotSufficientFounds)?;
1127
1128 debug_assert!(credit.peek().is_zero())
1130 }1129 }
11311130
1132 <CreatedCollectionCount<T>>::put(created_count);1131 <CreatedCollectionCount<T>>::put(created_count);