difftreelog
feat switch `common` from `Currency` trait to `fungible::*` traits
in: master
2 files changed
pallets/common/src/benchmarking.rsdiffbeforeafterboth27 MAX_PROPERTIES_PER_ITEM,27 MAX_PROPERTIES_PER_ITEM,28};28};29use frame_support::{29use frame_support::{30 traits::{Currency, Get},30 traits::{Get, fungible::Balanced, Imbalance, tokens::Precision},31 pallet_prelude::ConstU32,31 pallet_prelude::ConstU32,32 BoundedVec,32 BoundedVec,33};33};34use core::convert::TryInto;34use core::convert::TryInto;35use sp_runtime::DispatchError;35use sp_runtime::{DispatchError, traits::Zero};363637const SEED: u32 = 1;37const SEED: u32 = 1;383885 ) -> Result<CollectionId, DispatchError>,85 ) -> Result<CollectionId, DispatchError>,86 cast: impl FnOnce(CollectionHandle<T>) -> R,86 cast: impl FnOnce(CollectionHandle<T>) -> R,87) -> Result<R, DispatchError> {87) -> Result<R, DispatchError> {88 <T as Config>::Currency::deposit_creating(&owner.as_sub(), T::CollectionCreationPrice::get());88 let imbalance = <T as Config>::Currency::deposit(89 &owner.as_sub(),90 T::CollectionCreationPrice::get(),91 Precision::Exact,92 )?;93 debug_assert!(imbalance.peek().is_zero());89 let name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();94 let name = create_u16_data::<MAX_COLLECTION_NAME_LENGTH>();90 let description = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();95 let description = create_u16_data::<MAX_COLLECTION_DESCRIPTION_LENGTH>();91 let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();96 let token_prefix = create_data::<MAX_TOKEN_PREFIX_LENGTH>();pallets/common/src/lib.rsdiffbeforeafterboth64use 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,858986pub 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};899390#[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>>;441444442 /// 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>;444447445 /// 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 >;450453451 /// Dispatcher of operations on collections.454 /// Dispatcher of operations on collections.111211151113 // Take a (non-refundable) deposit of collection creation1116 // Take a (non-refundable) deposit of collection creation1114 {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)?;11271128 debug_assert!(credit.peek().is_zero())1130 }1129 }113111301132 <CreatedCollectionCount<T>>::put(created_count);1131 <CreatedCollectionCount<T>>::put(created_count);