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
3939
40]40]
41
42################################################################################
43# Substrate Dependencies
44
45[dependencies.codec]41[dependencies]
46default-features = false42scale-info = { version = "2.0.1", default-features = false, features = [
43 "derive",
44] }
45################################################################################
46# Substrate Dependencies
47
47features = ['derive']48codec = { default-features = false, features = ['derive'], package = 'parity-scale-codec', version = '3.1.2' }
48package = 'parity-scale-codec'
49version = '3.1.2'
50
51[dependencies.frame-benchmarking]49frame-benchmarking = {default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
52default-features = false
53optional = true
54git = "https://github.com/paritytech/substrate"
55branch = "polkadot-v0.9.27"
56
57[dependencies.frame-support]50frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
58default-features = false
59git = "https://github.com/paritytech/substrate"
60branch = "polkadot-v0.9.27"
61
62[dependencies.frame-system]51frame-system ={ default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
63default-features = false
64git = "https://github.com/paritytech/substrate"
65branch = "polkadot-v0.9.27"
66
67[dependencies.pallet-balances]52pallet-balances ={ default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
68default-features = false
69git = "https://github.com/paritytech/substrate"
70branch = "polkadot-v0.9.27"
71
72[dependencies.pallet-timestamp]53pallet-timestamp ={ default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
73default-features = false
74git = "https://github.com/paritytech/substrate"
75branch = "polkadot-v0.9.27"
76
77[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 = false
79git = "https://github.com/paritytech/substrate"
80branch = "polkadot-v0.9.27"
81
82[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"
86
87[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'
91
92[dependencies.sp-runtime]57sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
93default-features = false
94git = "https://github.com/paritytech/substrate"
95branch = "polkadot-v0.9.27"
96
97[dependencies.sp-core]58sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
98default-features = false
99git = "https://github.com/paritytech/substrate"
100branch = "polkadot-v0.9.27"
101
102[dependencies.sp-io]59sp-io ={ default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
103default-features = false
104git = "https://github.com/paritytech/substrate"
105branch = "polkadot-v0.9.27"
106
107[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"
11161
112################################################################################62################################################################################
113# local dependencies63# local dependencies
64
114[dependencies.up-data-structs]65up-data-structs ={ default-features = false, path = "../../primitives/data-structs" }
115default-features = false
116path = "../../primitives/data-structs"
117
118[dependencies.pallet-common]66pallet-common ={ default-features = false, path = "../common" }
119default-features = false
120path = "../common"
121
122[dependencies.pallet-unique]67pallet-unique ={ default-features = false, path = "../unique" }
123default-features = false
124path = "../unique"
125
126[dependencies.pallet-evm-contract-helpers]68pallet-evm-contract-helpers ={ default-features = false, path = "../evm-contract-helpers" }
127default-features = false
128path = "../evm-contract-helpers"
12969
130[dev-dependencies]70[dev-dependencies]
131[dependencies.pallet-evm-migration]71pallet-evm-migration ={ default-features = false, path = "../evm-migration" }
132default-features = false
133path = "../evm-migration"
134
13572
136################################################################################73################################################################################
137
138[dependencies]
139scale-info = { version = "2.0.1", default-features = false, features = [
140 "derive",
141] }
14274
modifiedpallets/app-promotion/src/lib.rsdiffbeforeafterboth
110 #[pallet::constant]110 #[pallet::constant]
111 type PendingInterval: Get<Self::BlockNumber>;111 type PendingInterval: Get<Self::BlockNumber>;
112
113 // /// In chain blocks.
114 // #[pallet::constant]
115 // type Day: Get<Self::BlockNumber>; // useless
116112
117 #[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 action
163 InvalidArgument,159 SponsorNotSet,
164 }160 }
165161
166 #[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>;
186182
187 /// 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 >;
205
206 // /// 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>;
209
210 // /// Next target block when interest is recalculated
211 // #[pallet::storage]
212 // #[pallet::getter(fn get_interest_block)]
213 // pub type NextInterestBlock<T: Config> =
214 // StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;
215191
216 /// 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);
232207
233 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 );
394369
395 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>>::NoPermission
399 );374 );
425 );400 );
426401
427 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>>::NoPermission
431 );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 }
717691
718 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 // }
723697
724 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,
modifiedpallets/app-promotion/src/types.rsdiffbeforeafterboth
5use pallet_common::CollectionHandle;5use pallet_common::CollectionHandle;
66
7use 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};
1111
12pub 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>
modifiedpallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth
81 /// * **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>,