git.delta.rocks / unique-network / refs/commits / 95510b917c06

difftreelog

code refactor

PraetorP2022-09-07parent: #8c250ff.patch.diff
in: master

4 files changed

modifiedpallets/app-promotion/Cargo.tomldiffbeforeafterboth
--- a/pallets/app-promotion/Cargo.toml
+++ b/pallets/app-promotion/Cargo.toml
@@ -15,7 +15,7 @@
 targets = ['x86_64-unknown-linux-gnu']
 
 [features]
-default = ['std',]
+default = ['std']
 runtime-benchmarks = [
     'frame-benchmarking',
     'frame-support/runtime-benchmarks',
@@ -38,104 +38,36 @@
     'serde/std',
 
 ]
-
+[dependencies]
+scale-info = { version = "2.0.1", default-features = false, features = [
+    "derive",
+] }
 ################################################################################
 # Substrate Dependencies
-
-[dependencies.codec]
-default-features = false
-features = ['derive']
-package = 'parity-scale-codec'
-version = '3.1.2'
-
-[dependencies.frame-benchmarking]
-default-features = false
-optional = true
-git = "https://github.com/paritytech/substrate"
-branch = "polkadot-v0.9.27"
-
-[dependencies.frame-support]
-default-features = false
-git = "https://github.com/paritytech/substrate"
-branch = "polkadot-v0.9.27"
-
-[dependencies.frame-system]
-default-features = false
-git = "https://github.com/paritytech/substrate"
-branch = "polkadot-v0.9.27"
 
-[dependencies.pallet-balances]
-default-features = false
-git = "https://github.com/paritytech/substrate"
-branch = "polkadot-v0.9.27"
-
-[dependencies.pallet-timestamp]
-default-features = false
-git = "https://github.com/paritytech/substrate"
-branch = "polkadot-v0.9.27"
-
-[dependencies.pallet-randomness-collective-flip]
-default-features = false
-git = "https://github.com/paritytech/substrate"
-branch = "polkadot-v0.9.27"
-
-[dependencies.sp-std]
-default-features = false
-git = "https://github.com/paritytech/substrate"
-branch = "polkadot-v0.9.27"
-
-[dependencies.serde]
-default-features = false
-features = ['derive']
-version = '1.0.130'
-
-[dependencies.sp-runtime]
-default-features = false
-git = "https://github.com/paritytech/substrate"
-branch = "polkadot-v0.9.27"
-
-[dependencies.sp-core]
-default-features = false
-git = "https://github.com/paritytech/substrate"
-branch = "polkadot-v0.9.27"
-
-[dependencies.sp-io]
-default-features = false
-git = "https://github.com/paritytech/substrate"
-branch = "polkadot-v0.9.27"
-
-[dependencies.pallet-evm]
-default-features = false
-git = "https://github.com/uniquenetwork/frontier"
-branch = "unique-polkadot-v0.9.27"
+codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = '3.1.2' }
+frame-benchmarking = {default-features = false, optional = true,  git = "https://github.com/paritytech/substrate",  branch = "polkadot-v0.9.27" }
+frame-support = { default-features = false,  git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
+frame-system ={ default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
+pallet-balances ={ default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
+pallet-timestamp ={ default-features = false,  git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
+pallet-randomness-collective-flip ={ default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
+pallet-evm ={ default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.27" }
+sp-std ={ default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
+sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
+sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
+sp-io ={ default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
+serde = { default-features = false, features = ['derive'], version = '1.0.130' }
 
 ################################################################################
 # local dependencies
-[dependencies.up-data-structs]
-default-features = false
-path = "../../primitives/data-structs"
 
-[dependencies.pallet-common]
-default-features = false
-path = "../common"
-
-[dependencies.pallet-unique]
-default-features = false
-path = "../unique"
+up-data-structs ={ default-features = false, path = "../../primitives/data-structs" }
+pallet-common ={ default-features = false, path = "../common" }
+pallet-unique ={ default-features = false, path = "../unique" }
+pallet-evm-contract-helpers ={ default-features = false, path = "../evm-contract-helpers" }
 
-[dependencies.pallet-evm-contract-helpers]
-default-features = false
-path = "../evm-contract-helpers"
-
 [dev-dependencies]
-[dependencies.pallet-evm-migration]
-default-features = false
-path = "../evm-migration"
-
+pallet-evm-migration ={ default-features = false, path = "../evm-migration" }
 
 ################################################################################
-
-[dependencies]
-scale-info = { version = "2.0.1", default-features = false, features = [
-    "derive",
-] }
modifiedpallets/app-promotion/src/lib.rsdiffbeforeafterboth
--- a/pallets/app-promotion/src/lib.rs
+++ b/pallets/app-promotion/src/lib.rs
@@ -110,10 +110,6 @@
 		#[pallet::constant]
 		type PendingInterval: Get<Self::BlockNumber>;
 
-		// /// In chain blocks.
-		// #[pallet::constant]
-		// type Day: Get<Self::BlockNumber>; // useless
-
 		#[pallet::constant]
 		type Nominal: Get<BalanceOf<Self>>;
 
@@ -160,7 +156,7 @@
 		NotSufficientFunds,
 		PendingForBlockOverflow,
 		/// An error related to the fact that an invalid argument was passed to perform an action
-		InvalidArgument,
+		SponsorNotSet,
 	}
 
 	#[pallet::storage]
@@ -184,16 +180,6 @@
 	pub type StakesPerAccount<T: Config> =
 		StorageMap<_, Blake2_128Concat, T::AccountId, u8, ValueQuery>;
 
-	/// Amount of tokens pending unstake per user per block.
-	// #[pallet::storage]
-	// pub type PendingUnstake<T: Config> = StorageNMap<
-	// 	Key = (
-	// 		Key<Blake2_128Concat, T::AccountId>,
-	// 		Key<Twox64Concat, T::BlockNumber>,
-	// 	),
-	// 	Value = BalanceOf<T>,
-	// 	QueryKind = ValueQuery,
-	// >;
 	#[pallet::storage]
 	pub type PendingUnstake<T: Config> = StorageMap<
 		_,
@@ -202,16 +188,6 @@
 		BoundedVec<(T::AccountId, BalanceOf<T>), ConstU32<PENDING_LIMIT_PER_BLOCK>>,
 		ValueQuery,
 	>;
-
-	// /// A block when app-promotion has started .I think this is redundant, because we only need `NextInterestBlock`.
-	// #[pallet::storage]
-	// pub type StartBlock<T: Config> = StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;
-
-	// /// Next target block when interest is recalculated
-	// #[pallet::storage]
-	// #[pallet::getter(fn get_interest_block)]
-	// pub type NextInterestBlock<T: Config> =
-	// 	StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;
 
 	/// Stores hash a record for which the last revenue recalculation was performed.
 	/// If `None`, then recalculation has not yet been performed or calculations have been completed for all stakers.
@@ -228,7 +204,6 @@
 		{
 			let block_pending = PendingUnstake::<T>::take(current_block_number);
 			let counter = block_pending.len() as u32;
-			// add_weight(0, 1, 0);
 
 			if !block_pending.is_empty() {
 				block_pending.into_iter().for_each(|(staker, amount)| {
@@ -393,7 +368,7 @@
 			);
 
 			ensure!(
-				T::CollectionHandler::sponsor(collection_id)?.ok_or(<Error<T>>::InvalidArgument)?
+				T::CollectionHandler::sponsor(collection_id)?.ok_or(<Error<T>>::SponsorNotSet)?
 					== Self::account_id(),
 				<Error<T>>::NoPermission
 			);
@@ -425,7 +400,7 @@
 			);
 
 			ensure!(
-				T::ContractHandler::sponsor(contract_id)?.ok_or(<Error<T>>::InvalidArgument)?
+				T::ContractHandler::sponsor(contract_id)?.ok_or(<Error<T>>::SponsorNotSet)?
 					== T::CrossAccountId::from_sub(Self::account_id()),
 				<Error<T>>::NoPermission
 			);
@@ -712,14 +687,13 @@
 		staker.map_or(Some(<TotalStaked<T>>::get()), |s| {
 			Self::total_staked_by_id(s.as_sub())
 		})
-		// Self::total_staked_by_id(staker.as_sub())
 	}
 
-	pub fn cross_id_locked_balance(staker: T::CrossAccountId) -> BalanceOf<T> {
-		Self::get_locked_balance(staker.as_sub())
-			.map(|l| l.amount)
-			.unwrap_or_default()
-	}
+	// pub fn cross_id_locked_balance(staker: T::CrossAccountId) -> BalanceOf<T> {
+	// 	Self::get_locked_balance(staker.as_sub())
+	// 		.map(|l| l.amount)
+	// 		.unwrap_or_default()
+	// }
 
 	pub fn cross_id_total_staked_per_block(
 		staker: T::CrossAccountId,
modifiedpallets/app-promotion/src/types.rsdiffbeforeafterboth
before · pallets/app-promotion/src/types.rs
1use codec::EncodeLike;2use frame_support::{traits::LockableCurrency, WeakBoundedVec, Parameter, dispatch::DispatchResult};34use pallet_balances::{BalanceLock, Config as BalancesConfig, Pallet as PalletBalances};5use pallet_common::CollectionHandle;67use sp_runtime::DispatchError;8use up_data_structs::{CollectionId, SponsorshipState};9use sp_std::borrow::ToOwned;10use pallet_evm_contract_helpers::{Pallet as EvmHelpersPallet, Config as EvmHelpersConfig, Sponsoring};1112pub trait ExtendedLockableCurrency<AccountId: Parameter>: LockableCurrency<AccountId> {13	fn locks<KArg>(who: KArg) -> WeakBoundedVec<BalanceLock<Self::Balance>, Self::MaxLocks>14	where15		KArg: EncodeLike<AccountId>;16}1718impl<T: BalancesConfig<I>, I: 'static> ExtendedLockableCurrency<T::AccountId>19	for PalletBalances<T, I>20{21	fn locks<KArg>(who: KArg) -> WeakBoundedVec<BalanceLock<Self::Balance>, Self::MaxLocks>22	where23		KArg: EncodeLike<T::AccountId>,24	{25		Self::locks(who)26	}27}2829pub trait CollectionHandler {30	type CollectionId;31	type AccountId;3233	fn set_sponsor(34		sponsor_id: Self::AccountId,35		collection_id: Self::CollectionId,36	) -> DispatchResult;3738	fn remove_collection_sponsor(collection_id: Self::CollectionId) -> DispatchResult;3940	fn sponsor(collection_id: Self::CollectionId)41		-> Result<Option<Self::AccountId>, DispatchError>;42}4344impl<T: pallet_unique::Config> CollectionHandler for pallet_unique::Pallet<T> {45	type CollectionId = CollectionId;4647	type AccountId = T::AccountId;4849	fn set_sponsor(50		sponsor_id: Self::AccountId,51		collection_id: Self::CollectionId,52	) -> DispatchResult {53		Self::force_set_sponsor(sponsor_id, collection_id)54	}5556	fn remove_collection_sponsor(collection_id: Self::CollectionId) -> DispatchResult {57		Self::force_remove_collection_sponsor(collection_id)58	}5960	fn sponsor(61		collection_id: Self::CollectionId,62	) -> Result<Option<Self::AccountId>, DispatchError> {63		Ok(<CollectionHandle<T>>::try_get(collection_id)?64			.sponsorship65			.sponsor()66			.map(|acc| acc.to_owned()))67	}68}6970pub trait ContractHandler {71	type ContractId;72	type AccountId;7374	fn set_sponsor(75		sponsor_id: Self::AccountId,76		contract_address: Self::ContractId,77	) -> DispatchResult;7879	fn remove_contract_sponsor(contract_address: Self::ContractId) -> DispatchResult;8081	fn sponsor(82		contract_address: Self::ContractId,83	) -> Result<Option<Self::AccountId>, DispatchError>;84}8586impl<T: EvmHelpersConfig> ContractHandler for EvmHelpersPallet<T> {87	type ContractId = sp_core::H160;8889	type AccountId = T::CrossAccountId;9091	fn set_sponsor(92		sponsor_id: Self::AccountId,93		contract_address: Self::ContractId,94	) -> DispatchResult {95		Self::force_set_sponsor(contract_address, &sponsor_id)96	}9798	fn remove_contract_sponsor(contract_address: Self::ContractId) -> DispatchResult {99		Self::force_remove_sponsor(contract_address)100	}101102	fn sponsor(103		contract_address: Self::ContractId,104	) -> Result<Option<Self::AccountId>, DispatchError> {105		Ok(Self::get_sponsor(contract_address))106	}107}
after · pallets/app-promotion/src/types.rs
1use codec::EncodeLike;2use frame_support::{traits::LockableCurrency, WeakBoundedVec, Parameter, dispatch::DispatchResult};34use pallet_balances::{BalanceLock, Config as BalancesConfig, Pallet as PalletBalances};5use pallet_common::CollectionHandle;67use sp_runtime::DispatchError;8use up_data_structs::{CollectionId};9use sp_std::borrow::ToOwned;10use pallet_evm_contract_helpers::{Pallet as EvmHelpersPallet, Config as EvmHelpersConfig};1112pub trait ExtendedLockableCurrency<AccountId: Parameter>: LockableCurrency<AccountId> {13	fn locks<KArg>(who: KArg) -> WeakBoundedVec<BalanceLock<Self::Balance>, Self::MaxLocks>14	where15		KArg: EncodeLike<AccountId>;16}1718impl<T: BalancesConfig<I>, I: 'static> ExtendedLockableCurrency<T::AccountId>19	for PalletBalances<T, I>20{21	fn locks<KArg>(who: KArg) -> WeakBoundedVec<BalanceLock<Self::Balance>, Self::MaxLocks>22	where23		KArg: EncodeLike<T::AccountId>,24	{25		Self::locks(who)26	}27}2829pub trait CollectionHandler {30	type CollectionId;31	type AccountId;3233	fn set_sponsor(34		sponsor_id: Self::AccountId,35		collection_id: Self::CollectionId,36	) -> DispatchResult;3738	fn remove_collection_sponsor(collection_id: Self::CollectionId) -> DispatchResult;3940	fn sponsor(collection_id: Self::CollectionId)41		-> Result<Option<Self::AccountId>, DispatchError>;42}4344impl<T: pallet_unique::Config> CollectionHandler for pallet_unique::Pallet<T> {45	type CollectionId = CollectionId;4647	type AccountId = T::AccountId;4849	fn set_sponsor(50		sponsor_id: Self::AccountId,51		collection_id: Self::CollectionId,52	) -> DispatchResult {53		Self::force_set_sponsor(sponsor_id, collection_id)54	}5556	fn remove_collection_sponsor(collection_id: Self::CollectionId) -> DispatchResult {57		Self::force_remove_collection_sponsor(collection_id)58	}5960	fn sponsor(61		collection_id: Self::CollectionId,62	) -> Result<Option<Self::AccountId>, DispatchError> {63		Ok(<CollectionHandle<T>>::try_get(collection_id)?64			.sponsorship65			.sponsor()66			.map(|acc| acc.to_owned()))67	}68}6970pub trait ContractHandler {71	type ContractId;72	type AccountId;7374	fn set_sponsor(75		sponsor_id: Self::AccountId,76		contract_address: Self::ContractId,77	) -> DispatchResult;7879	fn remove_contract_sponsor(contract_address: Self::ContractId) -> DispatchResult;8081	fn sponsor(82		contract_address: Self::ContractId,83	) -> Result<Option<Self::AccountId>, DispatchError>;84}8586impl<T: EvmHelpersConfig> ContractHandler for EvmHelpersPallet<T> {87	type ContractId = sp_core::H160;8889	type AccountId = T::CrossAccountId;9091	fn set_sponsor(92		sponsor_id: Self::AccountId,93		contract_address: Self::ContractId,94	) -> DispatchResult {95		Self::force_set_sponsor(contract_address, &sponsor_id)96	}9798	fn remove_contract_sponsor(contract_address: Self::ContractId) -> DispatchResult {99		Self::force_remove_sponsor(contract_address)100	}101102	fn sponsor(103		contract_address: Self::ContractId,104	) -> Result<Option<Self::AccountId>, DispatchError> {105		Ok(Self::get_sponsor(contract_address))106	}107}
modifiedpallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth
--- a/pallets/evm-contract-helpers/src/lib.rs
+++ b/pallets/evm-contract-helpers/src/lib.rs
@@ -81,7 +81,7 @@
 	/// * **Key** - contract address.
 	/// * **Value** - sponsorship state.
 	#[pallet::storage]
-	pub type Sponsoring<T: Config> = StorageMap<
+	pub(super) type Sponsoring<T: Config> = StorageMap<
 		Hasher = Twox64Concat,
 		Key = H160,
 		Value = SponsorshipState<T::CrossAccountId>,