From 1b8da47b39c141f8e07179a0f2d34e4c041cc9c0 Mon Sep 17 00:00:00 2001 From: yooml Date: Wed, 11 Oct 2023 17:02:52 +0800 Subject: [PATCH] Add ControlOrigin --- example/runtime/src/zenlink.rs | 1 + zenlink-protocol/src/lib.rs | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/example/runtime/src/zenlink.rs b/example/runtime/src/zenlink.rs index 99a4eef..57f9f0c 100644 --- a/example/runtime/src/zenlink.rs +++ b/example/runtime/src/zenlink.rs @@ -33,6 +33,7 @@ impl zenlink_protocol::Config for Runtime { type TargetChains = (); type SelfParaId = SelfParaId; type WeightInfo = (); + type ControlOrigin = EnsureRoot; } type MultiAssets = ZenlinkMultiAssets>; diff --git a/zenlink-protocol/src/lib.rs b/zenlink-protocol/src/lib.rs index c6bc3bf..4069344 100644 --- a/zenlink-protocol/src/lib.rs +++ b/zenlink-protocol/src/lib.rs @@ -80,6 +80,8 @@ pub mod pallet { pub trait Config: frame_system::Config { /// Because this pallet emits events, it depends on the runtime's definition of an event. type RuntimeEvent: From> + IsType<::RuntimeEvent>; + /// The only origin that can create pair. + type ControlOrigin: EnsureOrigin<::RuntimeOrigin>; /// The assets interface beyond native currency and other assets. type MultiAssetsHandler: MultiAssetsHandler; /// This pallet id. @@ -521,7 +523,7 @@ pub mod pallet { asset_0: T::AssetId, asset_1: T::AssetId, ) -> DispatchResult { - ensure_root(origin)?; + T::ControlOrigin::ensure_origin(origin)?; ensure!(asset_0.is_support() && asset_1.is_support(), Error::::UnsupportedAssetType); ensure!(asset_0 != asset_1, Error::::DeniedCreatePair);