Skip to content

Commit 38b0f06

Browse files
authored
let currency-adapater lock accept council (#1691)
Signed-off-by: Cheng JIANG <[email protected]>
1 parent 8b6976a commit 38b0f06

File tree

12 files changed

+21
-7
lines changed

12 files changed

+21
-7
lines changed

pallets/amm/src/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ impl pallet_currency_adapter::Config for Test {
191191
type Assets = Assets;
192192
type Balances = Balances;
193193
type GetNativeCurrencyId = NativeCurrencyId;
194+
type LockOrigin = EnsureRoot<AccountId>;
194195
}
195196

196197
// Build genesis storage according to the mock runtime.

pallets/bridge/src/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ impl pallet_currency_adapter::Config for Test {
155155
type Assets = Assets;
156156
type Balances = Balances;
157157
type GetNativeCurrencyId = NativeCurrencyId;
158+
type LockOrigin = EnsureRoot<AccountId>;
158159
}
159160

160161
parameter_types! {

pallets/currency-adapter/src/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ type AssetIdOf<T> =
4242
type BalanceOf<T> =
4343
<<T as Config>::Assets as Inspects<<T as frame_system::Config>::AccountId>>::Balance;
4444

45+
const CURRENCY_ADAPTER_ID: LockIdentifier = *b"cadapter";
46+
4547
#[frame_support::pallet]
4648
pub mod pallet {
4749
use super::*;
4850
use frame_support::traits::LockableCurrency;
49-
use frame_system::{ensure_root, pallet_prelude::OriginFor};
51+
use frame_system::pallet_prelude::OriginFor;
5052

5153
#[pallet::config]
5254
pub trait Config: frame_system::Config {
@@ -61,6 +63,9 @@ pub mod pallet {
6163

6264
#[pallet::constant]
6365
type GetNativeCurrencyId: Get<AssetIdOf<Self>>;
66+
67+
// Origin which can lock asset balance
68+
type LockOrigin: EnsureOrigin<<Self as frame_system::Config>::Origin>;
6469
}
6570

6671
#[pallet::pallet]
@@ -78,32 +83,30 @@ pub mod pallet {
7883
pub fn force_set_lock(
7984
origin: OriginFor<T>,
8085
asset: AssetIdOf<T>,
81-
id: LockIdentifier,
8286
who: T::AccountId,
8387
#[pallet::compact] amount: BalanceOf<T>,
8488
) -> DispatchResult {
85-
ensure_root(origin)?;
89+
T::LockOrigin::ensure_origin(origin)?;
8690
ensure!(
8791
asset == T::GetNativeCurrencyId::get(),
8892
Error::<T>::NotANativeToken
8993
);
90-
T::Balances::set_lock(id, &who, amount, WithdrawReasons::all());
94+
T::Balances::set_lock(CURRENCY_ADAPTER_ID, &who, amount, WithdrawReasons::all());
9195
Ok(())
9296
}
9397

9498
#[pallet::weight(10_000)]
9599
pub fn force_remove_lock(
96100
origin: OriginFor<T>,
97101
asset: AssetIdOf<T>,
98-
id: LockIdentifier,
99102
who: T::AccountId,
100103
) -> DispatchResult {
101-
ensure_root(origin)?;
104+
T::LockOrigin::ensure_origin(origin)?;
102105
ensure!(
103106
asset == T::GetNativeCurrencyId::get(),
104107
Error::<T>::NotANativeToken
105108
);
106-
T::Balances::remove_lock(id, &who);
109+
T::Balances::remove_lock(CURRENCY_ADAPTER_ID, &who);
107110
Ok(())
108111
}
109112
}

pallets/farming/src/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ impl pallet_currency_adapter::Config for Test {
159159
type Assets = Assets;
160160
type Balances = Balances;
161161
type GetNativeCurrencyId = NativeCurrencyId;
162+
type LockOrigin = EnsureRoot<AccountId>;
162163
}
163164

164165
// Build genesis storage according to the mock runtime.

pallets/loans/src/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ impl pallet_currency_adapter::Config for Test {
273273
type Assets = Assets;
274274
type Balances = Balances;
275275
type GetNativeCurrencyId = NativeCurrencyId;
276+
type LockOrigin = EnsureRoot<AccountId>;
276277
}
277278

278279
pub(crate) fn new_test_ext() -> sp_io::TestExternalities {

pallets/router/src/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ impl pallet_currency_adapter::Config for Runtime {
158158
type Assets = Assets;
159159
type Balances = Balances;
160160
type GetNativeCurrencyId = NativeCurrencyId;
161+
type LockOrigin = EnsureRoot<AccountId>;
161162
}
162163

163164
parameter_types! {

pallets/stableswap/src/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ impl pallet_currency_adapter::Config for Test {
190190
type Assets = Assets;
191191
type Balances = Balances;
192192
type GetNativeCurrencyId = NativeCurrencyId;
193+
type LockOrigin = EnsureRoot<AccountId>;
193194
}
194195

195196
construct_runtime!(

pallets/streaming/src/mock.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ impl pallet_currency_adapter::Config for Test {
140140
type Assets = Assets;
141141
type Balances = Balances;
142142
type GetNativeCurrencyId = NativeCurrencyId;
143+
type LockOrigin = EnsureRoot<AccountId>;
143144
}
144145

145146
parameter_types! {

runtime/heiko/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,7 @@ impl pallet_currency_adapter::Config for Runtime {
18881888
type Assets = Assets;
18891889
type Balances = Balances;
18901890
type GetNativeCurrencyId = NativeCurrencyId;
1891+
type LockOrigin = EnsureRootOrMoreThanHalfGeneralCouncil;
18911892
}
18921893

18931894
parameter_types! {

runtime/kerria/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,6 +1799,7 @@ impl pallet_currency_adapter::Config for Runtime {
17991799
type Assets = Assets;
18001800
type Balances = Balances;
18011801
type GetNativeCurrencyId = NativeCurrencyId;
1802+
type LockOrigin = EnsureRootOrMoreThanHalfGeneralCouncil;
18021803
}
18031804

18041805
parameter_types! {

0 commit comments

Comments
 (0)