git.delta.rocks / unique-network / refs/commits / 8855177f64d7

difftreelog

refactor renaming, clearing code

PraetorP2023-01-31parent: #2e3b6c3.patch.diff
in: master

1 file changed

modifiedpallets/app-promotion/src/lib.rsdiffbeforeafterboth
234 QueryKind = ValueQuery,234 QueryKind = ValueQuery,
235 >;235 >;
236236
237 /// Stores amount of stakes for an `Account`.237 /// Stores number of stake records for an `Account`.
238 ///238 ///
239 /// * **Key** - Staker account.239 /// * **Key** - Staker account.
240 /// * **Value** - Amount of stakes.240 /// * **Value** - Amount of stakes.
241 #[pallet::storage]241 #[pallet::storage]
242 pub type StakesPerAccount<T: Config> =242 pub type StakesPerAccount<T: Config> =
243 StorageMap<_, Blake2_128Concat, T::AccountId, u8, ValueQuery>;243 StorageMap<_, Blake2_128Concat, T::AccountId, u8, ValueQuery>;
244244
245 /// Stores amount of stakes for an `Account`.245 /// Pending unstake records for an `Account`.
246 ///246 ///
247 /// * **Key** - Staker account.247 /// * **Key** - Staker account.
248 /// * **Value** - Amount of stakes.248 /// * **Value** - Amount of stakes.
263 StorageValue<Value = (T::AccountId, T::BlockNumber), QueryKind = OptionQuery>;263 StorageValue<Value = (T::AccountId, T::BlockNumber), QueryKind = OptionQuery>;
264264
265 #[pallet::storage]265 #[pallet::storage]
266 pub(crate) type IsMigrated<T: Config> = StorageValue<Value = bool, QueryKind = ValueQuery>;266 pub(crate) type UpgradedToReserves<T: Config> =
267 StorageValue<Value = bool, QueryKind = ValueQuery>;
267268
268 #[pallet::hooks]269 #[pallet::hooks]
296 consumed_weight += weight;297 consumed_weight += weight;
297 };298 };
298299
299 if <IsMigrated<T>>::get() {300 if <UpgradedToReserves<T>>::get() {
300 add_weight(1, 0, Weight::zero());301 add_weight(1, 0, Weight::zero());
301 return consumed_weight;302 return consumed_weight;
302 } else {303 } else {
303 add_weight(1, 1, Weight::zero());304 add_weight(1, 1, Weight::zero());
304 <IsMigrated<T>>::set(true);305 <UpgradedToReserves<T>>::set(true);
305 }306 }
306 <PendingUnstake<T>>::drain().for_each(|(_, v)| {307 <PendingUnstake<T>>::drain().for_each(|(_, v)| {
307 add_weight(1, 1, Weight::zero());308 add_weight(1, 1, Weight::zero());
319 #[cfg(feature = "try-runtime")]320 #[cfg(feature = "try-runtime")]
320 fn pre_upgrade() -> Result<Vec<u8>, &'static str> {321 fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
321 use sp_std::collections::btree_map::BTreeMap;322 use sp_std::collections::btree_map::BTreeMap;
322 if <IsMigrated<T>>::get() {323 if <UpgradedToReserves<T>>::get() {
323 return Ok(Default::default());324 return Ok(Default::default());
324 }325 }
325 // Staker -> (total amount of reserved balance, reserved by promotion);326 // Staker -> (total amount of reserved balance, reserved by promotion);
346 fn post_upgrade(pre_state: Vec<u8>) -> Result<(), &'static str> {347 fn post_upgrade(pre_state: Vec<u8>) -> Result<(), &'static str> {
347 use sp_std::collections::btree_map::BTreeMap;348 use sp_std::collections::btree_map::BTreeMap;
348349
349 if <IsMigrated<T>>::get() {350 if <UpgradedToReserves<T>>::get() {
350 return Ok(());351 return Ok(());
351 }352 }
352353
808 T::PalletId::get().into_account_truncating()809 T::PalletId::get().into_account_truncating()
809 }810 }
810
811 // /// Unlocks the balance that was locked by the pallet.
812 // ///
813 // /// - `staker`: staker account.
814 // /// - `amount`: amount of unlocked funds.
815 // fn unlock_balance(staker: &T::AccountId, amount: BalanceOf<T>) -> DispatchResult {
816 // let locked_balance = Self::get_locked_balance(staker)
817 // .map(|l| l.amount)
818 // .ok_or(<Error<T>>::IncorrectLockedBalanceOperation)?;
819
820 // // It is understood that we cannot unlock more funds than were locked by staking.
821 // // Therefore, if implemented correctly, this error should not occur.
822 // Self::set_lock_unchecked(
823 // staker,
824 // locked_balance
825 // .checked_sub(&amount)
826 // .ok_or(ArithmeticError::Underflow)?,
827 // );
828 // Ok(())
829 // }
830811
831 /// Adds the balance to locked by the pallet.812 /// Adds the balance to locked by the pallet.
832 ///813 ///