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

difftreelog

fix cargo fmt

Daniel Shiposha2022-12-13parent: #8634c0d.patch.diff
in: master

1 file changed

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, Perbill};8use up_data_structs::{CollectionId};9use sp_std::borrow::ToOwned;10use pallet_evm_contract_helpers::{Pallet as EvmHelpersPallet, Config as EvmHelpersConfig};11use pallet_configuration::{AppPromomotionConfigurationOverride};12use sp_core::Get;1314const MAX_NUMBER_PAYOUTS: u8 = 100;15pub(crate) const DEFAULT_NUMBER_PAYOUTS: u8 = 20;1617/// This trait was defined because `LockableCurrency`18/// has no way to know the state of the lock for an account.19pub trait ExtendedLockableCurrency<AccountId: Parameter>: LockableCurrency<AccountId> {20	/// Returns lock balance for an account. Allows to determine the cause of the lock.21	fn locks<KArg>(who: KArg) -> WeakBoundedVec<BalanceLock<Self::Balance>, Self::MaxLocks>22	where23		KArg: EncodeLike<AccountId>;24}2526impl<T: BalancesConfig<I>, I: 'static> ExtendedLockableCurrency<T::AccountId>27	for PalletBalances<T, I>28{29	fn locks<KArg>(who: KArg) -> WeakBoundedVec<BalanceLock<Self::Balance>, Self::MaxLocks>30	where31		KArg: EncodeLike<T::AccountId>,32	{33		Self::locks(who)34	}35}36/// Trait for interacting with collections.37pub trait CollectionHandler {38	type CollectionId;39	type AccountId;4041	/// Sets sponsor for a collection.42	///43	/// - `sponsor_id`: the account of the sponsor-to-be.44	/// - `collection_id`: ID of the modified collection.45	fn set_sponsor(46		sponsor_id: Self::AccountId,47		collection_id: Self::CollectionId,48	) -> DispatchResult;4950	/// Removes sponsor for a collection.51	///52	/// - `collection_id`: ID of the modified collection.53	fn remove_collection_sponsor(collection_id: Self::CollectionId) -> DispatchResult;5455	/// Retuns the current sponsor for a collection if one is set.56	///57	/// - `collection_id`: ID of the collection.58	fn sponsor(collection_id: Self::CollectionId)59		-> Result<Option<Self::AccountId>, DispatchError>;60}6162impl<T: pallet_unique::Config> CollectionHandler for pallet_unique::Pallet<T> {63	type CollectionId = CollectionId;6465	type AccountId = T::AccountId;6667	fn set_sponsor(68		sponsor_id: Self::AccountId,69		collection_id: Self::CollectionId,70	) -> DispatchResult {71		Self::force_set_sponsor(sponsor_id, collection_id)72	}7374	fn remove_collection_sponsor(collection_id: Self::CollectionId) -> DispatchResult {75		Self::force_remove_collection_sponsor(collection_id)76	}7778	fn sponsor(79		collection_id: Self::CollectionId,80	) -> Result<Option<Self::AccountId>, DispatchError> {81		Ok(<CollectionHandle<T>>::try_get(collection_id)?82			.sponsorship83			.sponsor()84			.map(|acc| acc.to_owned()))85	}86}87/// Trait for interacting with contracts.88pub trait ContractHandler {89	type ContractId;90	type AccountId;9192	/// Sets sponsor for a contract.93	///94	/// - `sponsor_id`: the account of the sponsor-to-be.95	/// - `contract_address`: the address of the modified contract.96	fn set_sponsor(97		sponsor_id: Self::AccountId,98		contract_address: Self::ContractId,99	) -> DispatchResult;100101	/// Removes sponsor for a contract.102	///103	/// - `contract_address`: the address of the modified contract.104	fn remove_contract_sponsor(contract_address: Self::ContractId) -> DispatchResult;105106	/// Retuns the current sponsor for a contract if one is set.107	///108	/// - `contract_address`: the contract address.109	fn sponsor(110		contract_address: Self::ContractId,111	) -> Result<Option<Self::AccountId>, DispatchError>;112}113114impl<T: EvmHelpersConfig> ContractHandler for EvmHelpersPallet<T> {115	type ContractId = sp_core::H160;116117	type AccountId = T::CrossAccountId;118119	fn set_sponsor(120		sponsor_id: Self::AccountId,121		contract_address: Self::ContractId,122	) -> DispatchResult {123		Self::force_set_sponsor(contract_address, &sponsor_id)124	}125126	fn remove_contract_sponsor(contract_address: Self::ContractId) -> DispatchResult {127		Self::force_remove_sponsor(contract_address)128	}129130	fn sponsor(131		contract_address: Self::ContractId,132	) -> Result<Option<Self::AccountId>, DispatchError> {133		Ok(Self::get_sponsor(contract_address))134	}135}136pub(crate) struct PalletConfiguration<T: crate::Config> {137	/// In relay blocks.138	pub recalculation_interval: T::BlockNumber,139	/// In parachain blocks.140	pub pending_interval: T::BlockNumber,141	/// Value for `RecalculationInterval` based on 0.05% per 24h.142	pub interval_income: Perbill,143	/// Maximum allowable number of stakers calculated per call of the `app-promotion::PayoutStakers` extrinsic.144	pub max_stakers_per_calculation: u8,145}146impl<T: crate::Config> PalletConfiguration<T> {147	pub fn get() -> Self {148		let config = <AppPromomotionConfigurationOverride<T>>::get();149		Self {150			recalculation_interval: config151				.recalculation_interval152				.unwrap_or_else(|| T::RecalculationInterval::get()),153			pending_interval: config154				.pending_interval155				.unwrap_or_else(|| T::PendingInterval::get()),156			interval_income: config157				.interval_income158				.unwrap_or_else(|| T::IntervalIncome::get()),159			max_stakers_per_calculation: config160				.max_stakers_per_calculation161				.unwrap_or_else(|| MAX_NUMBER_PAYOUTS),162		}163	}164}