From 8176e02b6cb12d280f3ddc618e970b7987660b63 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Mon, 25 Nov 2019 17:57:59 +0800 Subject: [PATCH 1/2] fix: `LockIdentifier` --- types.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types.json b/types.json index 081c517b0..f59e2e99b 100644 --- a/types.json +++ b/types.json @@ -43,7 +43,7 @@ }, "BalanceLock": { - "id": "Vec", + "id": "LockIdentifier", "withdraw_lock": "WithdrawLock", "reasons": "WithdrawReasons" }, From 21c00324c05a2314ae7e13fd75edb3a094cc3a01 Mon Sep 17 00:00:00 2001 From: Xavier Lau Date: Mon, 25 Nov 2019 18:00:16 +0800 Subject: [PATCH 2/2] update: custom balance lock, move all lock deps into `darwinia_support` --- srml/balances/src/lib.rs | 4 ++-- srml/balances/src/tests.rs | 12 ++++++------ srml/kton/src/lib.rs | 7 ++----- srml/kton/src/tests.rs | 7 +++---- srml/staking/src/lib.rs | 6 ++++-- srml/staking/src/tests.rs | 7 ++----- srml/support/src/lib.rs | 13 +++++-------- 7 files changed, 24 insertions(+), 32 deletions(-) diff --git a/srml/balances/src/lib.rs b/srml/balances/src/lib.rs index 9fb51b8f5..0287ca4fd 100644 --- a/srml/balances/src/lib.rs +++ b/srml/balances/src/lib.rs @@ -31,7 +31,7 @@ use support::{ dispatch::Result, traits::{ Currency, ExistenceRequirement, Get, Imbalance, OnFreeBalanceZero, OnUnbalanced, ReservableCurrency, - SignedImbalance, UpdateBalanceOutcome, WithdrawReason, WithdrawReasons, + SignedImbalance, UpdateBalanceOutcome, }, Parameter, StorageValue, }; @@ -41,7 +41,7 @@ mod mock; mod tests; pub use self::imbalances::{NegativeImbalance, PositiveImbalance}; -use darwinia_support::{BalanceLock, LockIdentifier, LockableCurrency, WithdrawLock}; +use darwinia_support::{BalanceLock, LockIdentifier, LockableCurrency, WithdrawLock, WithdrawReason, WithdrawReasons}; pub trait Subtrait: system::Trait + timestamp::Trait { /// The balance of an account. diff --git a/srml/balances/src/tests.rs b/srml/balances/src/tests.rs index c758341ca..b5fc61f5d 100644 --- a/srml/balances/src/tests.rs +++ b/srml/balances/src/tests.rs @@ -18,19 +18,19 @@ #![cfg(test)] -use super::*; -use mock::{info_from_weight, Balances, ExtBuilder, Runtime, System, CALL}; use sr_primitives::traits::SignedExtension; use support::{ assert_err, assert_noop, assert_ok, - traits::{ - Currency, ExistenceRequirement::AllowDeath, LockIdentifier, LockableCurrency, ReservableCurrency, - WithdrawReason, WithdrawReasons, - }, + traits::{Currency, ExistenceRequirement::AllowDeath, LockableCurrency, ReservableCurrency}, }; use system::RawOrigin; use transaction_payment::ChargeTransactionPayment; +use darwinia_support::{LockIdentifier, WithdrawReason, WithdrawReasons}; + +use super::*; +use mock::{info_from_weight, Balances, ExtBuilder, Runtime, System, CALL}; + const ID_1: LockIdentifier = *b"1 "; const ID_2: LockIdentifier = *b"2 "; const ID_3: LockIdentifier = *b"3 "; diff --git a/srml/kton/src/lib.rs b/srml/kton/src/lib.rs index 4c5a6f10a..485e636f1 100644 --- a/srml/kton/src/lib.rs +++ b/srml/kton/src/lib.rs @@ -16,15 +16,12 @@ use sr_primitives::{ use srml_support::{ decl_event, decl_module, decl_storage, dispatch::Result, - traits::{ - Currency, ExistenceRequirement, Imbalance, OnUnbalanced, SignedImbalance, UpdateBalanceOutcome, WithdrawReason, - WithdrawReasons, - }, + traits::{Currency, ExistenceRequirement, Imbalance, OnUnbalanced, SignedImbalance, UpdateBalanceOutcome}, Parameter, StorageMap, StorageValue, }; use system::ensure_signed; -use darwinia_support::{BalanceLock, LockIdentifier, LockableCurrency, WithdrawLock}; +use darwinia_support::{BalanceLock, LockIdentifier, LockableCurrency, WithdrawLock, WithdrawReason, WithdrawReasons}; use imbalance::{NegativeImbalance, PositiveImbalance}; #[cfg(test)] diff --git a/srml/kton/src/tests.rs b/srml/kton/src/tests.rs index 346c7a5f5..6d2d85e99 100644 --- a/srml/kton/src/tests.rs +++ b/srml/kton/src/tests.rs @@ -1,7 +1,6 @@ -use srml_support::{ - assert_err, assert_noop, assert_ok, - traits::{Currency, LockIdentifier, WithdrawReason, WithdrawReasons}, -}; +use srml_support::{assert_err, assert_noop, assert_ok, traits::Currency}; + +use darwinia_support::{LockIdentifier, WithdrawReason, WithdrawReasons}; use super::*; use crate::mock::*; diff --git a/srml/staking/src/lib.rs b/srml/staking/src/lib.rs index 5caa9474c..6a78bc79a 100644 --- a/srml/staking/src/lib.rs +++ b/srml/staking/src/lib.rs @@ -38,11 +38,13 @@ use sr_staking_primitives::{ }; use srml_support::{ decl_event, decl_module, decl_storage, ensure, - traits::{Currency, Get, Imbalance, OnFreeBalanceZero, OnUnbalanced, Time, WithdrawReason, WithdrawReasons}, + traits::{Currency, Get, Imbalance, OnFreeBalanceZero, OnUnbalanced, Time}, }; use system::{ensure_root, ensure_signed}; -use darwinia_support::{LockIdentifier, LockableCurrency, NormalLock, StakingLock, TimeStamp, WithdrawLock}; +use darwinia_support::{ + LockIdentifier, LockableCurrency, NormalLock, StakingLock, TimeStamp, WithdrawLock, WithdrawReason, WithdrawReasons, +}; use phragmen::{build_support_map, elect, equalize, ExtendedBalance, PhragmenStakedAssignment}; use core::convert::TryInto; diff --git a/srml/staking/src/tests.rs b/srml/staking/src/tests.rs index aef213669..3c93a2b09 100644 --- a/srml/staking/src/tests.rs +++ b/srml/staking/src/tests.rs @@ -1,11 +1,8 @@ -use srml_support::{ - assert_err, assert_ok, - traits::{Currency, WithdrawReason, WithdrawReasons}, -}; +use srml_support::{assert_err, assert_ok, traits::Currency}; use super::*; use crate::mock::*; -use darwinia_support::{BalanceLock, NormalLock, StakingLock, WithdrawLock}; +use darwinia_support::{BalanceLock, NormalLock, StakingLock, WithdrawLock, WithdrawReason, WithdrawReasons}; // gen_paired_account!(a(1), b(2), m(12)); // will create stash `a` and controller `b` diff --git a/srml/support/src/lib.rs b/srml/support/src/lib.rs index be50cb984..cbc153ab3 100644 --- a/srml/support/src/lib.rs +++ b/srml/support/src/lib.rs @@ -1,13 +1,11 @@ #![recursion_limit = "128"] #![cfg_attr(not(feature = "std"), no_std)] +pub use srml_support::traits::{LockIdentifier, WithdrawReason, WithdrawReasons}; + pub use structs::*; pub use traits::*; -/// An identifier for a lock. Used for disambiguating different locks so that -/// they can be individually replaced or removed. -pub type LockIdentifier = [u8; 8]; - pub type TimeStamp = u64; mod structs { @@ -17,9 +15,8 @@ mod structs { traits::{SaturatedConversion, SimpleArithmetic}, RuntimeDebug, }; - use srml_support::traits::WithdrawReasons; - use super::{LockIdentifier, TimeStamp}; + use super::{LockIdentifier, TimeStamp, WithdrawReasons}; #[derive(Clone, PartialEq, Encode, Decode, RuntimeDebug)] pub struct BalanceLock { @@ -97,9 +94,9 @@ mod structs { } mod traits { - use srml_support::traits::{Currency, WithdrawReasons}; + use srml_support::traits::Currency; - use super::{LockIdentifier, WithdrawLock}; + use super::{LockIdentifier, WithdrawLock, WithdrawReasons}; pub trait OnMinted { fn on_minted(value: Balance);