From 22add2469f1bc6b7315dc85b664c2aeab72ad39e Mon Sep 17 00:00:00 2001 From: sudipghimire533 Date: Tue, 17 Jan 2023 21:20:08 +0100 Subject: [PATCH 1/2] Add cfg attribute to runtime-benchmark Helper in pallet_equip --- runtime/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index aa4f83f6..b0291bdc 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -407,6 +407,7 @@ impl pallet_rmrk_equip::Config for Runtime { type MaxPropertiesPerTheme = MaxPropertiesPerTheme; type MaxCollectionsEquippablePerPart = MaxCollectionsEquippablePerPart; type WeightInfo = pallet_rmrk_equip::weights::SubstrateWeight; + #[cfg(feature = "runtime-benchmarks")] type Helper = RmrkBenchmark; } From b5306d44ce551bc1f4fb8a96d5fd433ea34205cc Mon Sep 17 00:00:00 2001 From: sudipghimire533 Date: Tue, 17 Jan 2023 22:18:24 +0100 Subject: [PATCH 2/2] Complete usage of `ProducerOrigin` in pallet_rmrk_core::Config --- pallets/rmrk-core/src/functions.rs | 6 +++++- pallets/rmrk-core/src/lib.rs | 17 ++++++++++------- pallets/rmrk-core/src/mock.rs | 4 ++-- pallets/rmrk-equip/src/mock.rs | 4 ++-- pallets/rmrk-market/src/mock.rs | 3 ++- runtime/src/lib.rs | 2 +- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/pallets/rmrk-core/src/functions.rs b/pallets/rmrk-core/src/functions.rs index 74174ccd..9afa5998 100644 --- a/pallets/rmrk-core/src/functions.rs +++ b/pallets/rmrk-core/src/functions.rs @@ -46,7 +46,11 @@ impl priority_index += 1; } Self::deposit_event(Event::PrioritySet { collection_id, nft_id }); - Ok(Some(::WeightInfo::set_priority(priority_index, T::NestingBudget::get())).into()) + Ok(Some(::WeightInfo::set_priority( + priority_index, + T::NestingBudget::get(), + )) + .into()) } } diff --git a/pallets/rmrk-core/src/lib.rs b/pallets/rmrk-core/src/lib.rs index 2d303ff7..11d69b08 100644 --- a/pallets/rmrk-core/src/lib.rs +++ b/pallets/rmrk-core/src/lib.rs @@ -9,10 +9,13 @@ use frame_support::{ dispatch::{DispatchResult, DispatchResultWithPostInfo}, ensure, - traits::tokens::{nonfungibles::*, Locker}, + traits::{ + tokens::{nonfungibles::*, Locker}, + EnsureOrigin, IsType, + }, transactional, BoundedVec, }; -use frame_system::ensure_signed; +use frame_system::{ensure_signed, RawOrigin}; use sp_runtime::{traits::StaticLookup, DispatchError, Permill}; use sp_std::convert::TryInto; @@ -122,7 +125,7 @@ pub mod pallet { pub trait Config: frame_system::Config + pallet_uniques::Config { /// Because this pallet emits events, it depends on the runtime's definition of an event. type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type ProtocolOrigin: EnsureOrigin; + type ProtocolOrigin: EnsureOrigin; /// The maximum resource symbol length #[pallet::constant] @@ -443,7 +446,7 @@ pub mod pallet { transferable: bool, resources: Option>, ) -> DispatchResult { - let sender = ensure_signed(origin)?; + let sender = T::ProtocolOrigin::ensure_origin(origin)?; if let Some(collection_issuer) = pallet_uniques::Pallet::::collection_owner(collection_id) { @@ -483,7 +486,7 @@ pub mod pallet { /// - `recipient`: Receiver of the royalty /// - `royalty`: Permillage reward from each trade for the Recipient /// - `metadata`: Arbitrary data about an nft, e.g. IPFS hash - #[pallet::call_index(1)] + #[pallet::call_index(1)] #[pallet::weight(::WeightInfo::mint_nft_directly_to_nft(T::NestingBudget::get()))] #[transactional] pub fn mint_nft_directly_to_nft( @@ -497,7 +500,7 @@ pub mod pallet { transferable: bool, resources: Option>, ) -> DispatchResult { - let sender = ensure_signed(origin.clone())?; + let sender = T::ProtocolOrigin::ensure_origin(origin.clone())?; // Collection must exist and sender must be issuer of collection if let Some(collection_issuer) = @@ -535,7 +538,7 @@ pub mod pallet { max: Option, symbol: BoundedCollectionSymbolOf, ) -> DispatchResult { - let sender = ensure_signed(origin)?; + let sender = T::ProtocolOrigin::ensure_origin(origin)?; Self::collection_create(sender, collection_id, metadata, max, symbol)?; diff --git a/pallets/rmrk-core/src/mock.rs b/pallets/rmrk-core/src/mock.rs index 967acc72..85c9a9a5 100644 --- a/pallets/rmrk-core/src/mock.rs +++ b/pallets/rmrk-core/src/mock.rs @@ -9,7 +9,7 @@ use frame_support::{ parameter_types, traits::{AsEnsureOriginWithArg, ConstU32, Everything}, }; -use frame_system::EnsureRoot; +use frame_system::{EnsureRoot, EnsureSigned}; use sp_core::{crypto::AccountId32, H256}; use sp_runtime::{ testing::Header, @@ -60,7 +60,7 @@ use pallet_rmrk_core::RmrkBenchmark; impl pallet_rmrk_core::Config for Test { // type Currency = Balances; type RuntimeEvent = RuntimeEvent; - type ProtocolOrigin = EnsureRoot; + type ProtocolOrigin = EnsureSigned; type ResourceSymbolLimit = ResourceSymbolLimit; type PartsLimit = PartsLimit; type MaxPriorities = MaxPriorities; diff --git a/pallets/rmrk-equip/src/mock.rs b/pallets/rmrk-equip/src/mock.rs index cac6cee5..9222608f 100644 --- a/pallets/rmrk-equip/src/mock.rs +++ b/pallets/rmrk-equip/src/mock.rs @@ -8,7 +8,7 @@ use frame_support::{ traits::{AsEnsureOriginWithArg, ConstU32, Everything}, weights::Weight, }; -use frame_system::EnsureRoot; +use frame_system::{EnsureRoot, EnsureSigned}; use sp_core::{crypto::AccountId32, H256}; use sp_runtime::{ testing::Header, @@ -71,7 +71,7 @@ use pallet_rmrk_core::RmrkBenchmark; impl pallet_rmrk_core::Config for Test { type RuntimeEvent = RuntimeEvent; - type ProtocolOrigin = EnsureRoot; + type ProtocolOrigin = EnsureSigned; type ResourceSymbolLimit = ResourceSymbolLimit; type PartsLimit = PartsLimit; type MaxPriorities = MaxPriorities; diff --git a/pallets/rmrk-market/src/mock.rs b/pallets/rmrk-market/src/mock.rs index faee4fcd..22f47673 100644 --- a/pallets/rmrk-market/src/mock.rs +++ b/pallets/rmrk-market/src/mock.rs @@ -106,10 +106,11 @@ parameter_types! { #[cfg(feature = "runtime-benchmarks")] use pallet_rmrk_core::RmrkBenchmark; +use system::EnsureSigned; impl pallet_rmrk_core::Config for Test { type RuntimeEvent = RuntimeEvent; - type ProtocolOrigin = EnsureRoot; + type ProtocolOrigin = EnsureSigned; type ResourceSymbolLimit = ResourceSymbolLimit; type PartsLimit = PartsLimit; type MaxPriorities = MaxPriorities; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index b0291bdc..66c64719 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -362,7 +362,7 @@ use pallet_rmrk_core::RmrkBenchmark; impl pallet_rmrk_core::Config for Runtime { type RuntimeEvent = RuntimeEvent; - type ProtocolOrigin = frame_system::EnsureRoot; + type ProtocolOrigin = frame_system::EnsureSigned; type ResourceSymbolLimit = ResourceSymbolLimit; type PartsLimit = PartsLimit; type MaxPriorities = MaxPriorities;