Composite accounts (#4820)

* Basic account composition.

* Add try_mutate_exists

* De-duplicate

* Refactor away the UpdateBalanceOutcome

* Expunge final UpdateBalanceOutcome refs

* Refactor transfer

* Refactor reservable currency stuff.

* Test with the alternative setup.

* Fixes

* Test with both setups.

* Fixes

* Fix

* Fix macros

* Make indices opt-in

* Remove CreationFee, and make indices opt-in.

* Fix construct_runtime

* Fix last few bits

* Fix tests

* Update trait impls

* Don't hardcode the system event

* Make tests build and fix some stuff.

* Pointlessly bump runtime version

* Fix benchmark

* Another fix

* Whitespace

* Make indices module economically safe

* Migrations for indices.

* Fix

* Whilespace

* Trim defunct migrations

* Remove unused storage item

* More contains_key fixes

* Docs.

* Bump runtime

* Remove unneeded code

* Fix test

* Fix test

* Update frame/balances/src/lib.rs

Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com>

* Fix ED logic

* Repatriate reserved logic

* Typo

* Fix typo

* Update frame/system/src/lib.rs

Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com>

* Update frame/system/src/lib.rs

Co-Authored-By: Shawn Tabrizi <shawntabrizi@gmail.com>

* Last few fixes

* Another fix

* Build fix

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
Co-authored-by: Jaco Greeff <jacogr@gmail.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
Gavin Wood
2020-02-14 00:47:51 +00:00
committed by GitHub
parent d3fa8c91af
commit 5b7512e2e4
79 changed files with 2459 additions and 2100 deletions
+2 -2
View File
@@ -32,7 +32,7 @@ use frame_support::{
decl_storage, decl_event, ensure, decl_module, decl_error,
weights::SimpleDispatchInfo,
traits::{
Currency, ExistenceRequirement, Get, LockableCurrency, LockIdentifier,
Currency, ExistenceRequirement, Get, LockableCurrency, LockIdentifier, BalanceStatus,
OnUnbalanced, ReservableCurrency, WithdrawReason, WithdrawReasons, ChangeMembers
}
};
@@ -501,7 +501,7 @@ decl_module! {
if valid {
// This only fails if `reporter` doesn't exist, which it clearly must do since its
// the origin. Still, it's no more harmful to propagate any error at this point.
T::Currency::repatriate_reserved(&who, &reporter, T::VotingBond::get())?;
T::Currency::repatriate_reserved(&who, &reporter, T::VotingBond::get(), BalanceStatus::Free)?;
Self::deposit_event(RawEvent::VoterReaped(who, reporter));
} else {
let imbalance = T::Currency::slash_reserved(&reporter, T::VotingBond::get()).0;
+8 -10
View File
@@ -39,9 +39,9 @@ parameter_types! {
}
impl frame_system::Trait for Test {
type Origin = Origin;
type Call = ();
type Index = u64;
type BlockNumber = u64;
type Call = ();
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
@@ -54,21 +54,20 @@ impl frame_system::Trait for Test {
type AvailableBlockRatio = AvailableBlockRatio;
type Version = ();
type ModuleToIndex = ();
type AccountData = pallet_balances::AccountData<u64>;
type OnNewAccount = ();
type OnReapAccount = Balances;
}
parameter_types! {
pub const ExistentialDeposit: u64 = 1;
pub const CreationFee: u64 = 0;
}
impl pallet_balances::Trait for Test {
type Balance = u64;
type OnNewAccount = ();
type OnReapAccount = System;
type Event = Event;
type TransferPayment = ();
type DustRemoval = ();
type Event = Event;
type ExistentialDeposit = ExistentialDeposit;
type CreationFee = CreationFee;
type AccountStore = System;
}
parameter_types! {
@@ -151,7 +150,7 @@ frame_support::construct_runtime!(
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: system::{Module, Call, Event},
System: system::{Module, Call, Event<T>},
Balances: pallet_balances::{Module, Call, Event<T>, Config<T>},
Elections: elections::{Module, Call, Event<T>, Config<T>},
}
@@ -266,8 +265,7 @@ pub(crate) fn create_candidate(i: u64, index: u32) {
}
pub(crate) fn balances(who: &u64) -> (u64, u64) {
let a = Balances::account(who);
(a.free, a.reserved)
(Balances::free_balance(who), Balances::reserved_balance(who))
}
pub(crate) fn locks(who: &u64) -> Vec<u64> {