git.delta.rocks / unique-network / refs/commits / 4186437dc1bc

difftreelog

feat add rmrk proxy create_base

Daniel Shiposha2022-05-25parent: #e8a3a23.patch.diff
in: master

12 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5513,6 +5513,7 @@
  "pallet-randomness-collective-flip",
  "pallet-refungible",
  "pallet-rmrk-core",
+ "pallet-rmrk-equip",
  "pallet-structure",
  "pallet-sudo",
  "pallet-template-transaction-payment",
@@ -6533,6 +6534,25 @@
 ]
 
 [[package]]
+name = "pallet-rmrk-equip"
+version = "0.1.0"
+dependencies = [
+ "frame-benchmarking",
+ "frame-support",
+ "frame-system",
+ "pallet-common",
+ "pallet-evm",
+ "pallet-nonfungible",
+ "pallet-rmrk-core",
+ "parity-scale-codec 3.1.2",
+ "scale-info",
+ "sp-core",
+ "sp-runtime",
+ "sp-std",
+ "up-data-structs",
+]
+
+[[package]]
 name = "pallet-scheduler"
 version = "4.0.0-dev"
 source = "git+https://github.com/paritytech/substrate?branch=polkadot-v0.9.21#563f4820d8f36d256ada7ea3fef46b2e94c4cd5a"
modifiedpallets/proxy-rmrk-core/Cargo.tomldiffbeforeafterboth
--- a/pallets/proxy-rmrk-core/Cargo.toml
+++ b/pallets/proxy-rmrk-core/Cargo.toml
@@ -18,10 +18,7 @@
 sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
 pallet-common = { default-features = false, path = '../common' }
 pallet-nonfungible = { default-features = false, path = "../../pallets/nonfungible" }
-# pallet-structure = { default-features = false, path = '../structure' }
 up-data-structs = { default-features = false, path = '../../primitives/data-structs' }
-# evm-coder = { default-features = false, path = '../../crates/evm-coder' }
-# pallet-evm-coder-substrate = { default-features = false, path = '../evm-coder-substrate' }
 pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.21-logs" }
 frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
 scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }
@@ -37,9 +34,6 @@
     "pallet-common/std",
     "pallet-nonfungible/std",
     "pallet-evm/std",
-    # "pallet-structure/std",
-    # "evm-coder/std",
-    # "pallet-evm-coder-substrate/std",
     'frame-benchmarking/std',
 ]
 runtime-benchmarks = [
modifiedpallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-core/src/lib.rs
+++ b/pallets/proxy-rmrk-core/src/lib.rs
@@ -254,8 +254,8 @@
             });
 
             let nft_id = Self::create_nft(
-                sender,
-                cross_owner,
+                &sender,
+                &cross_owner,
                 collection_id.into(),
                 CollectionType::Regular,
                 NftType::Regular,
@@ -302,9 +302,9 @@
 }
 
 impl<T: Config> Pallet<T> {
-    fn create_nft(
-        sender: T::CrossAccountId,
-        owner: T::CrossAccountId,
+    pub fn create_nft(
+        sender: &T::CrossAccountId,
+        owner: &T::CrossAccountId,
         collection_id: CollectionId,
         collection_type: CollectionType,
         nft_type: NftType,
@@ -320,14 +320,14 @@
                 .try_into()
                 .map_err(|_| <Error<T>>::NftTypeEncodeError)?,
             properties: BoundedVec::default(),
-            owner,
+            owner: owner.clone(),
         };
 
         let budget = budget::Value::new(2);
 
         <PalletNft<T>>::create_item(
             &collection,
-            &sender,
+            sender,
             data,
             &budget,
         ).map_err(Self::map_common_err_to_proxy)?;
modifiedpallets/proxy-rmrk-core/src/property.rsdiffbeforeafterboth
--- a/pallets/proxy-rmrk-core/src/property.rs
+++ b/pallets/proxy-rmrk-core/src/property.rs
@@ -19,7 +19,7 @@
     Thumb,
     EquippedNft,
     BaseType,
-    // // RmrkPartId(/* Id type? */)
+    ExternalPartId,
     EquippableList,
     ZIndex,
     ThemeName,
@@ -62,8 +62,7 @@
             Self::Thumb => key!("thumb"),
             Self::EquippedNft => key!("equipped-nft"),
             Self::BaseType => key!("base-type"),
-            // RmrkResourceId(/* Id type? */)
-            // RmrkPartId(/* Id type? */)
+            Self::ExternalPartId => key!("ext-part-id"),
             Self::EquippableList => key!("equippable-list"),
             Self::ZIndex => key!("z-index"),
             Self::ThemeName => key!("theme-name"),
addedpallets/proxy-rmrk-equip/Cargo.tomldiffbeforeafterboth
--- /dev/null
+++ b/pallets/proxy-rmrk-equip/Cargo.toml
@@ -0,0 +1,45 @@
+[package]
+name = "pallet-rmrk-equip"
+version = "0.1.0"
+license = "GPLv3"
+edition = "2021"
+
+[dependencies.codec]
+default-features = false
+features = ['derive']
+package = 'parity-scale-codec'
+version = '3.1.2'
+
+[dependencies]
+frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+frame-system = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+sp-std = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+sp-core = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+pallet-common = { default-features = false, path = '../common' }
+pallet-nonfungible = { default-features = false, path = "../../pallets/nonfungible" }
+up-data-structs = { default-features = false, path = '../../primitives/data-structs' }
+pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier", branch = "unique-polkadot-v0.9.21-logs" }
+frame-benchmarking = { default-features = false, optional = true, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.21" }
+scale-info = { version = "2.0.1", default-features = false, features = ["derive"] }
+pallet-rmrk-core = { default-features = false, path = "../proxy-rmrk-core" }
+
+[features]
+default = ["std"]
+std = [
+    "frame-support/std",
+    "frame-system/std",
+    "sp-runtime/std",
+    "sp-std/std",
+    "up-data-structs/std",
+    "pallet-common/std",
+    "pallet-nonfungible/std",
+    "pallet-rmrk-core/std",
+    "pallet-evm/std",
+    'frame-benchmarking/std',
+]
+runtime-benchmarks = [
+    'frame-benchmarking',
+    'frame-support/runtime-benchmarks',
+    'frame-system/runtime-benchmarks',
+]
addedpallets/proxy-rmrk-equip/src/lib.rsdiffbeforeafterboth
after · pallets/proxy-rmrk-equip/src/lib.rs
1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![cfg_attr(not(feature = "std"), no_std)]1819use frame_support::{pallet_prelude::*, transactional, BoundedVec, dispatch::DispatchResult};20use frame_system::{pallet_prelude::*, ensure_signed};21use sp_runtime::DispatchError;22use up_data_structs::*;23use pallet_common::{Pallet as PalletCommon, Error as CommonError, CollectionHandle};24use pallet_rmrk_core::{Pallet as PalletCore, rmrk_property, misc::*};25use pallet_nonfungible::{Pallet as PalletNft};26use pallet_evm::account::CrossAccountId;2728pub use pallet::*;2930#[frame_support::pallet]31pub mod pallet {32    use super::*;3334	#[pallet::config]35	pub trait Config: frame_system::Config36                    + pallet_rmrk_core::Config {37		type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;38	}3940    #[pallet::storage]41	#[pallet::getter(fn internal_part_id)]42	pub type InernalPartId<T: Config> = StorageDoubleMap<43        _,44        Twox64Concat,45        CollectionId,46        Twox64Concat,47        RmrkPartId,48        TokenId49    >;5051    #[pallet::pallet]52	#[pallet::generate_store(pub(super) trait Store)]53	pub struct Pallet<T>(_);5455	#[pallet::event]56	#[pallet::generate_deposit(pub(super) fn deposit_event)]57	pub enum Event<T: Config> {58        BaseCreated {59			issuer: T::AccountId,60			base_id: RmrkBaseId,61		},62    }6364    #[pallet::error]65	pub enum Error<T> {66        NoAvailableBaseId,67    }6869    #[pallet::call]70	impl<T: Config> Pallet<T> {71        #[pallet::weight(10_000 + T::DbWeight::get().reads_writes(1,1))]72        #[transactional]73		pub fn create_base(74			origin: OriginFor<T>,75			base_type: RmrkString,76			symbol: RmrkString,77			parts: BoundedVec<RmrkPartType, RmrkPartsLimit>,78		) -> DispatchResult {79            let sender = ensure_signed(origin)?;80            let cross_sender = T::CrossAccountId::from_sub(sender.clone());8182            let data = CreateCollectionData {83                limits: None,84                token_prefix: symbol.into_inner()85                    .try_into()86                    .map_err(|_| <CommonError<T>>::CollectionTokenPrefixLimitExceeded)?,87                ..Default::default()88            };8990            let collection_id_res = <PalletNft<T>>::init_collection(sender.clone(), data);9192            if let Err(DispatchError::Arithmetic(_)) = &collection_id_res {93                return Err(<Error<T>>::NoAvailableBaseId.into());94            }9596            let collection_id = collection_id_res?;9798            let collection = <PalletCore<T>>::get_nft_collection(collection_id)?.into_inner();99100            <PalletCommon<T>>::set_scoped_collection_properties(101                &collection,102                PropertyScope::Rmrk,103                [104                    rmrk_property!(Config=T, CollectionType: CollectionType::Base)?,105                    rmrk_property!(Config=T, BaseType: base_type)?,106                ].into_iter()107            )?;108109            for part in parts {110                let part_id = part.id();111                let part_token_id = Self::create_part(112                    &cross_sender,113                    &collection,114                    part115                )?;116117                <InernalPartId<T>>::insert(collection_id, part_id, part_token_id);118119                <PalletNft<T>>::set_scoped_token_property(120                    &collection,121                    part_token_id,122                    PropertyScope::Rmrk,123                    rmrk_property!(Config=T, ExternalPartId: part_id)?124                )?;125            }126127            Self::deposit_event(Event::BaseCreated { issuer: sender, base_id: collection_id.0 });128129            Ok(())130        }131    }132}133134impl<T: Config> Pallet<T> {135    fn create_part(136        sender: &T::CrossAccountId,137        collection: &CollectionHandle<T>,138        part: RmrkPartType139    ) -> Result<TokenId, DispatchError> {140        let owner = sender;141142        let src = part.src();143        let z_index = part.z_index();144145        let nft_type = match part {146            RmrkPartType::FixedPart(_) => NftType::FixedPart,147            RmrkPartType::SlotPart(_) => NftType::SlotPart,148        };149150        let token_id = <PalletCore<T>>::create_nft(151            sender,152            owner,153            collection.id,154            CollectionType::Base,155            nft_type,156            [157                rmrk_property!(Config=T, Src: src)?,158                rmrk_property!(Config=T, ZIndex: z_index)?159            ].into_iter()160        )?;161162        if let RmrkPartType::SlotPart(part) = part {163            <PalletNft<T>>::set_scoped_token_property(164                collection,165                token_id,166                PropertyScope::Rmrk,167                rmrk_property!(Config=T, EquippableList: part.equippable)?168            )?;169        }170171        Ok(token_id)172    }173}
modifiedprimitives/data-structs/src/rmrk.rsdiffbeforeafterboth
--- a/primitives/data-structs/src/rmrk.rs
+++ b/primitives/data-structs/src/rmrk.rs
@@ -416,6 +416,29 @@
 	SlotPart(SlotPart<BoundedString, BoundedCollectionList>),
 }
 
+impl<BoundedString, BoundedCollectionList> PartType<BoundedString, BoundedCollectionList> {
+	pub fn id(&self) -> PartId {
+		match self {
+			Self::FixedPart(part) => part.id,
+			Self::SlotPart(part) => part.id
+		}
+	}
+
+	pub fn src(&self) -> &BoundedString {
+		match self {
+			Self::FixedPart(part) => &part.src,
+			Self::SlotPart(part) => &part.src
+		}
+	}
+
+	pub fn z_index(&self) -> ZIndex {
+		match self {
+			Self::FixedPart(part) => part.z,
+			Self::SlotPart(part) => part.z
+		}
+	}
+}
+
 #[cfg_attr(feature = "std", derive(Eq, Serialize))]
 #[derive(Encode, Decode, Debug, TypeInfo, Clone, PartialEq)]
 #[cfg_attr(
modifiedruntime/common/src/runtime_apis.rsdiffbeforeafterboth
--- a/runtime/common/src/runtime_apis.rs
+++ b/runtime/common/src/runtime_apis.rs
@@ -347,27 +347,27 @@
 
                 fn base_parts(base_id: RmrkBaseId) -> Result<Vec<RmrkPartType>, DispatchError> {
                     use frame_support::BoundedVec;
-                    use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, RmrkNft, RmrkDecode}};
+                    use pallet_proxy_rmrk_core::{RmrkProperty, misc::{CollectionType, NftType, RmrkNft, RmrkDecode}};
 
                     let collection_id = CollectionId(base_id);
                     if RmrkCore::ensure_collection_type(collection_id, CollectionType::Base).is_err() { return Ok(Vec::new()); }
 
-                    let parts = (dispatch_unique_runtime!(collection_id.collection_tokens()) as Result<Vec<TokenId>, DispatchError>)?
-                        .iter()
+                    let parts = (dispatch_unique_runtime!(collection_id.collection_tokens()))?
+                        .into_iter()
                         .filter_map(|token_id| {
-                            let nft_type = RmrkCore::get_nft_type(collection_id, *token_id).unwrap();
+                            let nft_type = RmrkCore::get_nft_type(collection_id, token_id).ok()?;
 
                             match nft_type {
-                                FixedPart => Some(RmrkPartType::FixedPart(RmrkFixedPart {
-                                    id: token_id.0,
-                                    src: RmrkCore::get_nft_property(collection_id, *token_id, RmrkProperty::Src).unwrap().decode_or_default(),
-                                    z: RmrkCore::get_nft_property(collection_id, *token_id, RmrkProperty::ZIndex).unwrap().decode_or_default(),
+                                NftType::FixedPart => Some(RmrkPartType::FixedPart(RmrkFixedPart {
+                                    id: RmrkCore::get_nft_property(collection_id, token_id, RmrkProperty::ExternalPartId).ok()?.decode_or_default(),
+                                    src: RmrkCore::get_nft_property(collection_id, token_id, RmrkProperty::Src).ok()?.decode_or_default(),
+                                    z: RmrkCore::get_nft_property(collection_id, token_id, RmrkProperty::ZIndex).ok()?.decode_or_default(),
                                 })),
-                                SlotPart => Some(RmrkPartType::SlotPart(RmrkSlotPart {
-                                    id: token_id.0,
-                                    src: RmrkCore::get_nft_property(collection_id, *token_id, RmrkProperty::Src).unwrap().decode_or_default(),
-                                    z: RmrkCore::get_nft_property(collection_id, *token_id, RmrkProperty::ZIndex).unwrap().decode_or_default(),
-                                    equippable: RmrkCore::get_nft_property(collection_id, *token_id, RmrkProperty::EquippableList).unwrap().decode_or_default(),
+                                NftType::SlotPart => Some(RmrkPartType::SlotPart(RmrkSlotPart {
+                                    id: RmrkCore::get_nft_property(collection_id, token_id, RmrkProperty::ExternalPartId).ok()?.decode_or_default(),
+                                    src: RmrkCore::get_nft_property(collection_id, token_id, RmrkProperty::Src).ok()?.decode_or_default(),
+                                    z: RmrkCore::get_nft_property(collection_id, token_id, RmrkProperty::ZIndex).ok()?.decode_or_default(),
+                                    equippable: RmrkCore::get_nft_property(collection_id, token_id, RmrkProperty::EquippableList).ok()?.decode_or_default(),
                                 })),
                                 _ => None
                             }
modifiedruntime/opal/Cargo.tomldiffbeforeafterboth
--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -91,6 +91,7 @@
     'pallet-refungible/std',
     'pallet-nonfungible/std',
     'pallet-proxy-rmrk-core/std',
+    'pallet-proxy-rmrk-equip/std',
     'pallet-unique/std',
     'pallet-unq-scheduler/std',
     'pallet-charge-transaction/std',
@@ -410,6 +411,7 @@
 pallet-refungible = { default-features = false, path = "../../pallets/refungible" }
 pallet-nonfungible = { default-features = false, path = "../../pallets/nonfungible" }
 pallet-proxy-rmrk-core = { default-features = false, path = "../../pallets/proxy-rmrk-core", package = "pallet-rmrk-core" }
+pallet-proxy-rmrk-equip = { default-features = false, path = "../../pallets/proxy-rmrk-equip", package = "pallet-rmrk-equip" }
 pallet-unq-scheduler = { path = '../../pallets/scheduler', default-features = false }
 # pallet-contract-helpers = { path = '../pallets/contract-helpers', default-features = false, version = '0.1.0' }
 pallet-charge-transaction = { git = "https://github.com/uniquenetwork/pallet-sponsoring", branch = "polkadot-v0.9.21", package = "pallet-template-transaction-payment", default-features = false, version = "3.0.0" }
modifiedruntime/opal/src/lib.rsdiffbeforeafterboth
--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -906,6 +906,10 @@
 	type Event = Event;
 }
 
+impl pallet_proxy_rmrk_equip::Config for Runtime {
+	type Event = Event;
+}
+
 impl pallet_unique::Config for Runtime {
 	type Event = Event;
 	type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;
@@ -1019,6 +1023,7 @@
 		Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,
 		Structure: pallet_structure::{Pallet, Call, Storage, Event<T>} = 70,
 		RmrkCore: pallet_proxy_rmrk_core::{Pallet, Call, Storage, Event<T>} = 71,
+		RmrkEquip: pallet_proxy_rmrk_equip::{Pallet, Call, Storage, Event<T>} = 72,
 
 		// Frontier
 		EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,
modifiedruntime/quartz/src/lib.rsdiffbeforeafterboth
--- a/runtime/quartz/src/lib.rs
+++ b/runtime/quartz/src/lib.rs
@@ -880,6 +880,14 @@
 	type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;
 }
 
+impl pallet_proxy_rmrk_core::Config for Runtime {
+	type Event = Event;
+}
+
+impl pallet_proxy_rmrk_equip::Config for Runtime {
+	type Event = Event;
+}
+
 impl pallet_unique::Config for Runtime {
 	type Event = Event;
 	type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;
@@ -992,6 +1000,7 @@
 		Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,
 		Structure: pallet_structure::{Pallet, Call, Storage, Event<T>} = 70,
 		RmrkCore: pallet_proxy_rmrk_core::{Pallet, Call, Storage, Event<T>} = 71,
+		RmrkEquip: pallet_proxy_rmrk_equip::{Pallet, Call, Storage, Event<T>} = 72,
 
 		// Frontier
 		EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,
modifiedruntime/unique/src/lib.rsdiffbeforeafterboth
--- a/runtime/unique/src/lib.rs
+++ b/runtime/unique/src/lib.rs
@@ -884,6 +884,14 @@
 	type WeightInfo = pallet_nonfungible::weights::SubstrateWeight<Self>;
 }
 
+impl pallet_proxy_rmrk_core::Config for Runtime {
+	type Event = Event;
+}
+
+impl pallet_proxy_rmrk_equip::Config for Runtime {
+	type Event = Event;
+}
+
 impl pallet_unique::Config for Runtime {
 	type Event = Event;
 	type WeightInfo = pallet_unique::weights::SubstrateWeight<Self>;
@@ -997,6 +1005,7 @@
 		Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,
 		Structure: pallet_structure::{Pallet, Call, Storage, Event<T>} = 70,
 		RmrkCore: pallet_proxy_rmrk_core::{Pallet, Call, Storage, Event<T>} = 71,
+		RmrkEquip: pallet_proxy_rmrk_equip::{Pallet, Call, Storage, Event<T>} = 72,
 
 		// Frontier
 		EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,