From 95510b917c0645f70a10473d0688da00cdbe0128 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Wed, 07 Sep 2022 13:06:39 +0000 Subject: [PATCH] code refactor --- --- 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", -] } --- a/pallets/app-promotion/src/lib.rs +++ b/pallets/app-promotion/src/lib.rs @@ -110,10 +110,6 @@ #[pallet::constant] type PendingInterval: Get; - // /// In chain blocks. - // #[pallet::constant] - // type Day: Get; // useless - #[pallet::constant] type Nominal: Get>; @@ -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 = StorageMap<_, Blake2_128Concat, T::AccountId, u8, ValueQuery>; - /// Amount of tokens pending unstake per user per block. - // #[pallet::storage] - // pub type PendingUnstake = StorageNMap< - // Key = ( - // Key, - // Key, - // ), - // Value = BalanceOf, - // QueryKind = ValueQuery, - // >; #[pallet::storage] pub type PendingUnstake = StorageMap< _, @@ -202,16 +188,6 @@ BoundedVec<(T::AccountId, BalanceOf), ConstU32>, ValueQuery, >; - - // /// A block when app-promotion has started .I think this is redundant, because we only need `NextInterestBlock`. - // #[pallet::storage] - // pub type StartBlock = StorageValue; - - // /// Next target block when interest is recalculated - // #[pallet::storage] - // #[pallet::getter(fn get_interest_block)] - // pub type NextInterestBlock = - // StorageValue; /// 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::::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(>::InvalidArgument)? + T::CollectionHandler::sponsor(collection_id)?.ok_or(>::SponsorNotSet)? == Self::account_id(), >::NoPermission ); @@ -425,7 +400,7 @@ ); ensure!( - T::ContractHandler::sponsor(contract_id)?.ok_or(>::InvalidArgument)? + T::ContractHandler::sponsor(contract_id)?.ok_or(>::SponsorNotSet)? == T::CrossAccountId::from_sub(Self::account_id()), >::NoPermission ); @@ -712,14 +687,13 @@ staker.map_or(Some(>::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 { - Self::get_locked_balance(staker.as_sub()) - .map(|l| l.amount) - .unwrap_or_default() - } + // pub fn cross_id_locked_balance(staker: T::CrossAccountId) -> BalanceOf { + // 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, --- a/pallets/app-promotion/src/types.rs +++ b/pallets/app-promotion/src/types.rs @@ -5,9 +5,9 @@ use pallet_common::CollectionHandle; use sp_runtime::DispatchError; -use up_data_structs::{CollectionId, SponsorshipState}; +use up_data_structs::{CollectionId}; use sp_std::borrow::ToOwned; -use pallet_evm_contract_helpers::{Pallet as EvmHelpersPallet, Config as EvmHelpersConfig, Sponsoring}; +use pallet_evm_contract_helpers::{Pallet as EvmHelpersPallet, Config as EvmHelpersConfig}; pub trait ExtendedLockableCurrency: LockableCurrency { fn locks(who: KArg) -> WeakBoundedVec, Self::MaxLocks> --- 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 = StorageMap< + pub(super) type Sponsoring = StorageMap< Hasher = Twox64Concat, Key = H160, Value = SponsorshipState, -- gitstuff