difftreelog
code refactor
in: master
4 files changed
pallets/app-promotion/Cargo.tomldiffbeforeafterboth393940]40]4142################################################################################43# Substrate Dependencies4445[dependencies.codec]41[dependencies]46default-features = false42scale-info = { version = "2.0.1", default-features = false, features = [43 "derive",44] }45################################################################################46# Substrate Dependencies4747features = ['derive']48codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = '3.1.2' }48package = 'parity-scale-codec'49version = '3.1.2'5051[dependencies.frame-benchmarking]49frame-benchmarking = {default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }52default-features = false53optional = true54git = "https://github.com/paritytech/substrate"55branch = "polkadot-v0.9.27"5657[dependencies.frame-support]50frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }58default-features = false59git = "https://github.com/paritytech/substrate"60branch = "polkadot-v0.9.27"6162[dependencies.frame-system]51frame-system ={ default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }63default-features = false64git = "https://github.com/paritytech/substrate"65branch = "polkadot-v0.9.27"6667[dependencies.pallet-balances]52pallet-balances ={ default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }68default-features = false69git = "https://github.com/paritytech/substrate"70branch = "polkadot-v0.9.27"7172[dependencies.pallet-timestamp]53pallet-timestamp ={ default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }73default-features = false74git = "https://github.com/paritytech/substrate"75branch = "polkadot-v0.9.27"7677[dependencies.pallet-randomness-collective-flip]54pallet-randomness-collective-flip ={ default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }78default-features = false79git = "https://github.com/paritytech/substrate"80branch = "polkadot-v0.9.27"8182[dependencies.sp-std]83default-features = false55pallet-evm ={ default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.27" }84git = "https://github.com/paritytech/substrate"85branch = "polkadot-v0.9.27"8687[dependencies.serde]88default-features = false56sp-std ={ default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }89features = ['derive']90version = '1.0.130'9192[dependencies.sp-runtime]57sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }93default-features = false94git = "https://github.com/paritytech/substrate"95branch = "polkadot-v0.9.27"9697[dependencies.sp-core]58sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }98default-features = false99git = "https://github.com/paritytech/substrate"100branch = "polkadot-v0.9.27"101102[dependencies.sp-io]59sp-io ={ default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }103default-features = false104git = "https://github.com/paritytech/substrate"105branch = "polkadot-v0.9.27"106107[dependencies.pallet-evm]108default-features = false60serde = { default-features = false, features = ['derive'], version = '1.0.130' }109git = "https://github.com/uniquenetwork/frontier"110branch = "unique-polkadot-v0.9.27"11161112################################################################################62################################################################################113# local dependencies63# local dependencies64114[dependencies.up-data-structs]65up-data-structs ={ default-features = false, path = "../../primitives/data-structs" }115default-features = false116path = "../../primitives/data-structs"117118[dependencies.pallet-common]66pallet-common ={ default-features = false, path = "../common" }119default-features = false120path = "../common"121122[dependencies.pallet-unique]67pallet-unique ={ default-features = false, path = "../unique" }123default-features = false124path = "../unique"125126[dependencies.pallet-evm-contract-helpers]68pallet-evm-contract-helpers ={ default-features = false, path = "../evm-contract-helpers" }127default-features = false128path = "../evm-contract-helpers"12969130[dev-dependencies]70[dev-dependencies]131[dependencies.pallet-evm-migration]71pallet-evm-migration ={ default-features = false, path = "../evm-migration" }132default-features = false133path = "../evm-migration"13413572136################################################################################73################################################################################137138[dependencies]139scale-info = { version = "2.0.1", default-features = false, features = [140 "derive",141] }14274pallets/app-promotion/src/lib.rsdiffbeforeafterboth110 #[pallet::constant]110 #[pallet::constant]111 type PendingInterval: Get<Self::BlockNumber>;111 type PendingInterval: Get<Self::BlockNumber>;112113 // /// In chain blocks.114 // #[pallet::constant]115 // type Day: Get<Self::BlockNumber>; // useless116112117 #[pallet::constant]113 #[pallet::constant]118 type Nominal: Get<BalanceOf<Self>>;114 type Nominal: Get<BalanceOf<Self>>;160 NotSufficientFunds,156 NotSufficientFunds,161 PendingForBlockOverflow,157 PendingForBlockOverflow,162 /// An error related to the fact that an invalid argument was passed to perform an action158 /// An error related to the fact that an invalid argument was passed to perform an action163 InvalidArgument,159 SponsorNotSet,164 }160 }165161166 #[pallet::storage]162 #[pallet::storage]184 pub type StakesPerAccount<T: Config> =180 pub type StakesPerAccount<T: Config> =185 StorageMap<_, Blake2_128Concat, T::AccountId, u8, ValueQuery>;181 StorageMap<_, Blake2_128Concat, T::AccountId, u8, ValueQuery>;186182187 /// Amount of tokens pending unstake per user per block.188 // #[pallet::storage]189 // pub type PendingUnstake<T: Config> = StorageNMap<190 // Key = (191 // Key<Blake2_128Concat, T::AccountId>,192 // Key<Twox64Concat, T::BlockNumber>,193 // ),194 // Value = BalanceOf<T>,195 // QueryKind = ValueQuery,196 // >;197 #[pallet::storage]183 #[pallet::storage]198 pub type PendingUnstake<T: Config> = StorageMap<184 pub type PendingUnstake<T: Config> = StorageMap<199 _,185 _,203 ValueQuery,189 ValueQuery,204 >;190 >;205206 // /// A block when app-promotion has started .I think this is redundant, because we only need `NextInterestBlock`.207 // #[pallet::storage]208 // pub type StartBlock<T: Config> = StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;209210 // /// Next target block when interest is recalculated211 // #[pallet::storage]212 // #[pallet::getter(fn get_interest_block)]213 // pub type NextInterestBlock<T: Config> =214 // StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;215191216 /// Stores hash a record for which the last revenue recalculation was performed.192 /// Stores hash a record for which the last revenue recalculation was performed.217 /// If `None`, then recalculation has not yet been performed or calculations have been completed for all stakers.193 /// If `None`, then recalculation has not yet been performed or calculations have been completed for all stakers.228 {204 {229 let block_pending = PendingUnstake::<T>::take(current_block_number);205 let block_pending = PendingUnstake::<T>::take(current_block_number);230 let counter = block_pending.len() as u32;206 let counter = block_pending.len() as u32;231 // add_weight(0, 1, 0);232207233 if !block_pending.is_empty() {208 if !block_pending.is_empty() {234 block_pending.into_iter().for_each(|(staker, amount)| {209 block_pending.into_iter().for_each(|(staker, amount)| {393 );368 );394369395 ensure!(370 ensure!(396 T::CollectionHandler::sponsor(collection_id)?.ok_or(<Error<T>>::InvalidArgument)?371 T::CollectionHandler::sponsor(collection_id)?.ok_or(<Error<T>>::SponsorNotSet)?397 == Self::account_id(),372 == Self::account_id(),398 <Error<T>>::NoPermission373 <Error<T>>::NoPermission399 );374 );425 );400 );426401427 ensure!(402 ensure!(428 T::ContractHandler::sponsor(contract_id)?.ok_or(<Error<T>>::InvalidArgument)?403 T::ContractHandler::sponsor(contract_id)?.ok_or(<Error<T>>::SponsorNotSet)?429 == T::CrossAccountId::from_sub(Self::account_id()),404 == T::CrossAccountId::from_sub(Self::account_id()),430 <Error<T>>::NoPermission405 <Error<T>>::NoPermission431 );406 );712 staker.map_or(Some(<TotalStaked<T>>::get()), |s| {687 staker.map_or(Some(<TotalStaked<T>>::get()), |s| {713 Self::total_staked_by_id(s.as_sub())688 Self::total_staked_by_id(s.as_sub())714 })689 })715 // Self::total_staked_by_id(staker.as_sub())716 }690 }717691718 pub fn cross_id_locked_balance(staker: T::CrossAccountId) -> BalanceOf<T> {692 // pub fn cross_id_locked_balance(staker: T::CrossAccountId) -> BalanceOf<T> {719 Self::get_locked_balance(staker.as_sub())693 // Self::get_locked_balance(staker.as_sub())720 .map(|l| l.amount)694 // .map(|l| l.amount)721 .unwrap_or_default()695 // .unwrap_or_default()722 }696 // }723697724 pub fn cross_id_total_staked_per_block(698 pub fn cross_id_total_staked_per_block(725 staker: T::CrossAccountId,699 staker: T::CrossAccountId,pallets/app-promotion/src/types.rsdiffbeforeafterboth5use pallet_common::CollectionHandle;5use pallet_common::CollectionHandle;667use sp_runtime::DispatchError;7use sp_runtime::DispatchError;8use up_data_structs::{CollectionId, SponsorshipState};8use up_data_structs::{CollectionId};9use sp_std::borrow::ToOwned;9use sp_std::borrow::ToOwned;10use pallet_evm_contract_helpers::{Pallet as EvmHelpersPallet, Config as EvmHelpersConfig, Sponsoring};10use pallet_evm_contract_helpers::{Pallet as EvmHelpersPallet, Config as EvmHelpersConfig};111112pub trait ExtendedLockableCurrency<AccountId: Parameter>: LockableCurrency<AccountId> {12pub trait ExtendedLockableCurrency<AccountId: Parameter>: LockableCurrency<AccountId> {13 fn locks<KArg>(who: KArg) -> WeakBoundedVec<BalanceLock<Self::Balance>, Self::MaxLocks>13 fn locks<KArg>(who: KArg) -> WeakBoundedVec<BalanceLock<Self::Balance>, Self::MaxLocks>pallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth81 /// * **Key** - contract address.81 /// * **Key** - contract address.82 /// * **Value** - sponsorship state.82 /// * **Value** - sponsorship state.83 #[pallet::storage]83 #[pallet::storage]84 pub type Sponsoring<T: Config> = StorageMap<84 pub(super) type Sponsoring<T: Config> = StorageMap<85 Hasher = Twox64Concat,85 Hasher = Twox64Concat,86 Key = H160,86 Key = H160,87 Value = SponsorshipState<T::CrossAccountId>,87 Value = SponsorshipState<T::CrossAccountId>,