mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 07:41:08 +00:00
Stash/controller model for staking (#1782)
* First steps to stash/controller separation * More drafting * More drafting * Finish draft. * Optimisation * Remove accidental commit * Make it build. * Fix linked map for traits. * Fix Option<_> variant. * Improve naming a tad * Rebuild runtime * Builds! * First test. * Bump RT version * Minor fix * Update Mock * adds the correct reward testcase (+staking eras which was already ok) * fixes the basic staking testcase to work properly (along with a small fix in the module) * New logic to avoid controller transferring stash. * Fix some build issues. * adding some comments to tests * Fix impls. * adds a few more lines to explain the test case * More fixes. * gets the basic test up and running again * Fix rest of build * Rebuild wasm * Fix docs. * fix staking test with new chnages * updating some tests, pending questions * More working tests * adds double staking test * Docs * remove invalid slashing test * Payee stuff. * Fix build * Docs * Fix test * Fix a couple of tests * Layout plan for finishing tests before Pragmen * Add some working tests * re-build staking and reward tests * Add more tests * fix offline grace test * Nominator should have payee checked for cleanup * adds more nomination tets * adds validator prefs tests * Fix and clean up some TODOs * Fix a couple of issues * Fix tests * noting warnings from tests * final fix of local tests * Fix slot_stake bug * Half baked test * Add logic to limit `unstake_threshold` set in storage * Make sure to check before writing! Almost forgot this one * Move a couple of comments * fix last broken slot_stake test * Ignore broken test
This commit is contained in:
@@ -19,10 +19,12 @@
|
||||
// Ensure we're `no_std` when compiling for Wasm.
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
use srml_support::{dispatch::Result, traits::ArithmeticType, StorageMap, decl_event, decl_storage, decl_module};
|
||||
use srml_support::{
|
||||
dispatch::Result, StorageMap, decl_event, decl_storage, decl_module,
|
||||
traits::{ArithmeticType, ChargeBytesFee, ChargeFee, TransferAsset, WithdrawReason}
|
||||
};
|
||||
use runtime_primitives::traits::{
|
||||
As, ChargeBytesFee, ChargeFee,
|
||||
TransferAsset, CheckedAdd, CheckedSub, CheckedMul, Zero
|
||||
As, CheckedAdd, CheckedSub, CheckedMul, Zero
|
||||
};
|
||||
use system;
|
||||
|
||||
@@ -96,7 +98,7 @@ impl<T: Trait> ChargeFee<T::AccountId> for Module<T> {
|
||||
let current_fee = Self::current_transaction_fee(extrinsic_index);
|
||||
let new_fee = current_fee.checked_add(&amount).ok_or_else(|| "fee got overflow after charge")?;
|
||||
|
||||
T::TransferAsset::remove_from(transactor, amount)?;
|
||||
T::TransferAsset::withdraw(transactor, amount, WithdrawReason::TransactionPayment)?;
|
||||
|
||||
<CurrentTransactionFee<T>>::insert(extrinsic_index, new_fee);
|
||||
Ok(())
|
||||
@@ -107,7 +109,7 @@ impl<T: Trait> ChargeFee<T::AccountId> for Module<T> {
|
||||
let current_fee = Self::current_transaction_fee(extrinsic_index);
|
||||
let new_fee = current_fee.checked_sub(&amount).ok_or_else(|| "fee got underflow after refund")?;
|
||||
|
||||
T::TransferAsset::add_to(transactor, amount)?;
|
||||
T::TransferAsset::deposit(transactor, amount)?;
|
||||
|
||||
<CurrentTransactionFee<T>>::insert(extrinsic_index, new_fee);
|
||||
Ok(())
|
||||
|
||||
@@ -20,12 +20,15 @@
|
||||
|
||||
use runtime_primitives::BuildStorage;
|
||||
use runtime_primitives::{
|
||||
traits::{IdentityLookup, BlakeTwo256, TransferAsset},
|
||||
traits::{IdentityLookup, BlakeTwo256},
|
||||
testing::{Digest, DigestItem, Header},
|
||||
};
|
||||
use primitives::{H256, Blake2Hasher};
|
||||
use runtime_io;
|
||||
use srml_support::{impl_outer_origin, impl_outer_event, traits::ArithmeticType};
|
||||
use srml_support::{
|
||||
impl_outer_origin, impl_outer_event,
|
||||
traits::{ArithmeticType, TransferAsset, WithdrawReason}
|
||||
};
|
||||
use crate::{GenesisConfig, Module, Trait, system};
|
||||
|
||||
impl_outer_origin!{
|
||||
@@ -48,8 +51,8 @@ impl<AccountId> TransferAsset<AccountId> for TransferAssetMock {
|
||||
type Amount = u64;
|
||||
|
||||
fn transfer(_: &AccountId, _: &AccountId, _: Self::Amount) -> Result<(), &'static str> { Ok(()) }
|
||||
fn remove_from(_: &AccountId, _: Self::Amount) -> Result<(), &'static str> { Ok(()) }
|
||||
fn add_to(_: &AccountId, _: Self::Amount) -> Result<(), &'static str> { Ok(()) }
|
||||
fn withdraw(_: &AccountId, _: Self::Amount, _: WithdrawReason) -> Result<(), &'static str> { Ok(()) }
|
||||
fn deposit(_: &AccountId, _: Self::Amount) -> Result<(), &'static str> { Ok(()) }
|
||||
}
|
||||
|
||||
impl ArithmeticType for TransferAssetMock {
|
||||
|
||||
Reference in New Issue
Block a user