difftreelog
fix logic payout
in: master
3 files changed
client/rpc/src/lib.rsdiffbeforeafterboth--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -424,7 +424,7 @@
client: Arc<C>,
_marker: std::marker::PhantomData<P>,
}
-
+
impl<C, P> $name<C, P> {
pub fn new(client: Arc<C>) -> Self {
Self {
pallets/app-promotion/src/lib.rsdiffbeforeafterboth--- a/pallets/app-promotion/src/lib.rs
+++ b/pallets/app-promotion/src/lib.rs
@@ -41,6 +41,7 @@
vec,
iter::Sum,
borrow::ToOwned,
+ cell::RefCell,
};
use sp_core::H160;
use codec::EncodeLike;
@@ -474,58 +475,121 @@
let next_recalc_block = current_recalc_block + T::RecalculationInterval::get();
let mut storage_iterator = Self::get_next_calculated_key()
- .map_or(Staked::<T>::iter(), |key| {
- Staked::<T>::iter_from(key)
- });
+ .map_or(Staked::<T>::iter(), |key| Staked::<T>::iter_from(key));
NextCalculatedRecord::<T>::set(None);
+ // {
+ // let mut stakers_number = stakers_number.unwrap_or(20);
+ // let mut last_id = admin_id;
+ // let mut income_acc = BalanceOf::<T>::default();
+ // let mut amount_acc = BalanceOf::<T>::default();
+
+ // while let Some((
+ // (current_id, staked_block),
+ // (amount, next_recalc_block_for_stake),
+ // )) = storage_iterator.next()
+ // {
+ // if last_id != current_id {
+ // if income_acc != BalanceOf::<T>::default() {
+ // <T::Currency as Currency<T::AccountId>>::transfer(
+ // &T::TreasuryAccountId::get(),
+ // &last_id,
+ // income_acc,
+ // ExistenceRequirement::KeepAlive,
+ // )
+ // .and_then(|_| Self::add_lock_balance(&last_id, income_acc))?;
+
+ // Self::deposit_event(Event::StakingRecalculation(
+ // last_id, amount, income_acc,
+ // ));
+ // }
+
+ // if stakers_number == 0 {
+ // NextCalculatedRecord::<T>::set(Some((current_id, staked_block)));
+ // break;
+ // }
+ // stakers_number -= 1;
+ // income_acc = BalanceOf::<T>::default();
+ // last_id = current_id;
+ // };
+ // if current_recalc_block >= next_recalc_block_for_stake {
+ // Self::recalculate_and_insert_stake(
+ // &last_id,
+ // staked_block,
+ // next_recalc_block,
+ // amount,
+ // ((current_recalc_block - next_recalc_block_for_stake)
+ // / T::RecalculationInterval::get())
+ // .into() + 1,
+ // &mut income_acc,
+ // );
+ // }
+ // }
+ // }
+
{
let mut stakers_number = stakers_number.unwrap_or(20);
- let mut last_id = admin_id;
- let mut income_acc = BalanceOf::<T>::default();
-
- while let Some(((current_id, staked_block), (amount, next_recalc_block_for_stake))) =
- storage_iterator.next()
- {
- if last_id != current_id {
- if income_acc != BalanceOf::<T>::default() {
+ let last_id = RefCell::new(None);
+ let income_acc = RefCell::new(BalanceOf::<T>::default());
+ let amount_acc = RefCell::new(BalanceOf::<T>::default());
+
+ let flush_stake = || -> DispatchResult {
+ if let Some(last_id) = &*last_id.borrow() {
+ if !income_acc.borrow().is_zero() {
<T::Currency as Currency<T::AccountId>>::transfer(
&T::TreasuryAccountId::get(),
- &last_id,
- income_acc,
+ last_id,
+ *income_acc.borrow(),
ExistenceRequirement::KeepAlive,
)
- .and_then(|_| Self::add_lock_balance(&last_id, income_acc))?;
+ .and_then(|_| Self::add_lock_balance(last_id, *income_acc.borrow()))?;
Self::deposit_event(Event::StakingRecalculation(
- last_id, amount, income_acc,
+ last_id.clone(),
+ *amount_acc.borrow(),
+ *income_acc.borrow(),
));
}
- if stakers_number == 0 {
- NextCalculatedRecord::<T>::set(Some((current_id, staked_block)));
- break;
- }
- stakers_number -= 1;
- income_acc = BalanceOf::<T>::default();
- last_id = current_id;
+ *income_acc.borrow_mut() = BalanceOf::<T>::default();
+ *amount_acc.borrow_mut() = BalanceOf::<T>::default();
+ }
+ Ok(())
+ };
+
+ while let Some((
+ (current_id, staked_block),
+ (amount, next_recalc_block_for_stake),
+ )) = storage_iterator.next()
+ {
+ if stakers_number == 0 {
+ NextCalculatedRecord::<T>::set(Some((current_id, staked_block)));
+ break;
+ }
+ stakers_number -= 1;
+ if last_id.borrow().as_ref() != Some(¤t_id) {
+ flush_stake()?;
};
+ *last_id.borrow_mut() = Some(current_id.clone());
if current_recalc_block >= next_recalc_block_for_stake {
+ *amount_acc.borrow_mut() += amount;
Self::recalculate_and_insert_stake(
- &last_id,
+ ¤t_id,
staked_block,
next_recalc_block,
amount,
((current_recalc_block - next_recalc_block_for_stake)
/ T::RecalculationInterval::get())
.into() + 1,
- &mut income_acc,
+ &mut *income_acc.borrow_mut(),
);
}
}
+ flush_stake()?;
}
+
Ok(())
}
}
runtime/common/config/pallets/app_promotion.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617use crate::{18 runtime_common::config::pallets::{TreasuryAccountId, RelayChainBlockNumberProvider},19 Runtime, Balances, BlockNumber, Unique, Event, EvmContractHelpers,20};2122use frame_support::{parameter_types, PalletId};23use sp_arithmetic::Perbill;24use up_common::{25 constants::{DAYS, UNIQUE, RELAY_DAYS},26 types::Balance,27};2829#[cfg(all(not(feature = "unique-runtime"), not(feature = "quartz-runtime")))]30parameter_types! {31 pub const AppPromotionId: PalletId = PalletId(*b"appstake");32 pub const RecalculationInterval: BlockNumber = 20;33 pub const PendingInterval: BlockNumber = 20;34 pub const Nominal: Balance = UNIQUE;35 pub const Day: BlockNumber = DAYS;36 pub IntervalIncome: Perbill = Perbill::from_rational(RecalculationInterval::get(), RELAY_DAYS) * Perbill::from_rational(5u32, 10_000);37}3839#[cfg(any(feature = "unique-runtime", feature = "quartz-runtime"))]40parameter_types! {41 pub const AppPromotionId: PalletId = PalletId(*b"appstake");42 pub const RecalculationInterval: BlockNumber = RELAY_DAYS;43 pub const PendingInterval: BlockNumber = 7 * RELAY_DAYS;44 pub const Nominal: Balance = UNIQUE;45 pub const Day: BlockNumber = RELAY_DAYS;46 pub IntervalIncome: Perbill = Perbill::from_rational(5u32, 10_000);47}4849impl pallet_app_promotion::Config for Runtime {50 type PalletId = AppPromotionId;51 type CollectionHandler = Unique;52 type ContractHandler = EvmContractHelpers;53 type Currency = Balances;54 type WeightInfo = pallet_app_promotion::weights::SubstrateWeight<Self>;55 type TreasuryAccountId = TreasuryAccountId;56 type RelayBlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;57 type RecalculationInterval = RecalculationInterval;58 type PendingInterval = PendingInterval;59 type Day = Day;60 type Nominal = Nominal;61 type IntervalIncome = IntervalIncome;62 type Event = Event;63}