Skip to content

Commit

Permalink
Complete usage of ProducerOrigin in pallet_rmrk_core::Config
Browse files Browse the repository at this point in the history
  • Loading branch information
sudipghimire533 committed Jan 17, 2023
1 parent 22add24 commit b5306d4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
6 changes: 5 additions & 1 deletion pallets/rmrk-core/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ impl<T: Config>
priority_index += 1;
}
Self::deposit_event(Event::PrioritySet { collection_id, nft_id });
Ok(Some(<T as pallet::Config>::WeightInfo::set_priority(priority_index, T::NestingBudget::get())).into())
Ok(Some(<T as pallet::Config>::WeightInfo::set_priority(
priority_index,
T::NestingBudget::get(),
))
.into())
}
}

Expand Down
17 changes: 10 additions & 7 deletions pallets/rmrk-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
type ProtocolOrigin: EnsureOrigin<Self::RuntimeOrigin>;
type ProtocolOrigin: EnsureOrigin<Self::RuntimeOrigin, Success = Self::AccountId>;

/// The maximum resource symbol length
#[pallet::constant]
Expand Down Expand Up @@ -443,7 +446,7 @@ pub mod pallet {
transferable: bool,
resources: Option<BoundedResourceInfoTypeOf<T>>,
) -> DispatchResult {
let sender = ensure_signed(origin)?;
let sender = T::ProtocolOrigin::ensure_origin(origin)?;
if let Some(collection_issuer) =
pallet_uniques::Pallet::<T>::collection_owner(collection_id)
{
Expand Down Expand Up @@ -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(<T as pallet::Config>::WeightInfo::mint_nft_directly_to_nft(T::NestingBudget::get()))]
#[transactional]
pub fn mint_nft_directly_to_nft(
Expand All @@ -497,7 +500,7 @@ pub mod pallet {
transferable: bool,
resources: Option<BoundedResourceInfoTypeOf<T>>,
) -> 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) =
Expand Down Expand Up @@ -535,7 +538,7 @@ pub mod pallet {
max: Option<u32>,
symbol: BoundedCollectionSymbolOf<T>,
) -> DispatchResult {
let sender = ensure_signed(origin)?;
let sender = T::ProtocolOrigin::ensure_origin(origin)?;

Self::collection_create(sender, collection_id, metadata, max, symbol)?;

Expand Down
4 changes: 2 additions & 2 deletions pallets/rmrk-core/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<AccountId>;
type ProtocolOrigin = EnsureSigned<AccountId>;
type ResourceSymbolLimit = ResourceSymbolLimit;
type PartsLimit = PartsLimit;
type MaxPriorities = MaxPriorities;
Expand Down
4 changes: 2 additions & 2 deletions pallets/rmrk-equip/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -71,7 +71,7 @@ use pallet_rmrk_core::RmrkBenchmark;

impl pallet_rmrk_core::Config for Test {
type RuntimeEvent = RuntimeEvent;
type ProtocolOrigin = EnsureRoot<AccountId>;
type ProtocolOrigin = EnsureSigned<AccountId>;
type ResourceSymbolLimit = ResourceSymbolLimit;
type PartsLimit = PartsLimit;
type MaxPriorities = MaxPriorities;
Expand Down
3 changes: 2 additions & 1 deletion pallets/rmrk-market/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountId>;
type ProtocolOrigin = EnsureSigned<AccountId>;
type ResourceSymbolLimit = ResourceSymbolLimit;
type PartsLimit = PartsLimit;
type MaxPriorities = MaxPriorities;
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ use pallet_rmrk_core::RmrkBenchmark;

impl pallet_rmrk_core::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type ProtocolOrigin = frame_system::EnsureRoot<AccountId>;
type ProtocolOrigin = frame_system::EnsureSigned<AccountId>;
type ResourceSymbolLimit = ResourceSymbolLimit;
type PartsLimit = PartsLimit;
type MaxPriorities = MaxPriorities;
Expand Down

0 comments on commit b5306d4

Please sign in to comment.