git.delta.rocks / unique-network / refs/commits / da5e7f48f1a3

difftreelog

feat(rmrk) add equippable extrinsic

Daniel Shiposha2022-06-20parent: #960c108.patch.diff
in: master

4 files changed

modifiedpallets/proxy-rmrk-core/src/lib.rsdiffbeforeafterboth
1298 collection.save()1298 collection.save()
1299 }1299 }
13001300
1301 fn check_collection_owner(1301 pub fn check_collection_owner(
1302 collection: &NonfungibleHandle<T>,1302 collection: &NonfungibleHandle<T>,
1303 account: &T::CrossAccountId,1303 account: &T::CrossAccountId,
1304 ) -> DispatchResult {1304 ) -> DispatchResult {
1363 collection_id: CollectionId,1363 collection_id: CollectionId,
1364 ) -> Result<misc::CollectionType, DispatchError> {1364 ) -> Result<misc::CollectionType, DispatchError> {
1365 Self::get_collection_property_decoded(collection_id, CollectionType)1365 Self::get_collection_property_decoded(collection_id, CollectionType)
1366 .map_err(|_| <Error<T>>::CorruptedCollectionType.into())1366 .map_err(|err| if err != <Error<T>>::CollectionUnknown.into() {
1367 <Error<T>>::CorruptedCollectionType.into()
1368 } else {
1369 err
1370 })
1367 }1371 }
13681372
1369 pub fn ensure_collection_type(1373 pub fn ensure_collection_type(
modifiedpallets/proxy-rmrk-equip/src/lib.rsdiffbeforeafterboth
23use pallet_common::{Pallet as PalletCommon, Error as CommonError};23use pallet_common::{Pallet as PalletCommon, Error as CommonError};
24use pallet_rmrk_core::{24use pallet_rmrk_core::{
25 Pallet as PalletCore,25 Pallet as PalletCore,
26 Error as CoreError,
26 misc::{self, *},27 misc::{self, *},
27 property::RmrkProperty::*,28 property::RmrkProperty::*,
28};29};
70 issuer: T::AccountId,71 issuer: T::AccountId,
71 base_id: RmrkBaseId,72 base_id: RmrkBaseId,
72 },73 },
74 EquippablesUpdated {
75 base_id: RmrkBaseId,
76 slot_id: RmrkSlotId,
77 },
73 }78 }
7479
75 #[pallet::error]80 #[pallet::error]
79 NoAvailablePartId,84 NoAvailablePartId,
80 BaseDoesntExist,85 BaseDoesntExist,
81 NeedsDefaultThemeFirst,86 NeedsDefaultThemeFirst,
87 PartDoesntExist,
88 NoEquippableOnFixedPart,
82 }89 }
8390
84 #[pallet::call]91 #[pallet::call]
182189
183 let collection_id: CollectionId = base_id.into();190 let collection_id: CollectionId = base_id.into();
184191
185 let collection = <PalletCore<T>>::get_typed_nft_collection(192 let collection = Self::get_base(collection_id)?;
186 collection_id,
187 misc::CollectionType::Base,
188 )
189 .map_err(|_| <Error<T>>::BaseDoesntExist)?;
190 collection.check_is_external()?;
191193
192 if theme.name.as_slice() == b"default" {194 if theme.name.as_slice() == b"default" {
193 <BaseHasDefaultTheme<T>>::insert(collection_id, true);195 <BaseHasDefaultTheme<T>>::insert(collection_id, true);
223 Ok(())225 Ok(())
224 }226 }
227
228 #[transactional]
229 #[pallet::weight(<SelfWeightOf<T>>::equippable())]
230 pub fn equippable(
231 origin: OriginFor<T>,
232 base_id: RmrkBaseId,
233 slot_id: RmrkSlotId,
234 equippables: RmrkEquippableList,
235 ) -> DispatchResult {
236 let sender = ensure_signed(origin)?;
237
238 let base_collection_id = base_id.into();
239 let collection = Self::get_base(base_collection_id)?;
240
241 <PalletCore<T>>::check_collection_owner(&collection, &T::CrossAccountId::from_sub(sender))
242 .map_err(|err| if err == <CoreError<T>>::NoPermission.into() {
243 <Error<T>>::PermissionError.into()
244 } else {
245 err
246 })?;
247
248 let part_id = Self::internal_part_id(base_collection_id, slot_id)
249 .ok_or(<Error<T>>::PartDoesntExist)?;
250
251 let nft_type = <PalletCore<T>>::get_nft_type(base_collection_id, part_id)
252 .map_err(|_| <Error<T>>::PartDoesntExist)?;
253
254 match nft_type {
255 NftType::Regular | NftType::Theme => return Err(<Error<T>>::PermissionError.into()),
256 NftType::FixedPart => return Err(<Error<T>>::NoEquippableOnFixedPart.into()),
257 NftType::SlotPart => {
258 <PalletNft<T>>::set_scoped_token_property(
259 base_collection_id,
260 part_id,
261 PropertyScope::Rmrk,
262 <PalletCore<T>>::rmrk_property(EquippableList, &equippables)?,
263 )?;
264 }
265 }
266
267 Self::deposit_event(Event::EquippablesUpdated {
268 base_id,
269 slot_id,
270 });
271
272 Ok(())
273 }
225 }274 }
226}275}
227276
269 Ok(token_id)318 Ok(token_id)
270 }319 }
320
321 fn get_base(base_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {
322 let collection = <PalletCore<T>>::get_typed_nft_collection(base_id, misc::CollectionType::Base)
323 .map_err(|err| if err == <CoreError<T>>::CollectionUnknown.into() {
324 <Error<T>>::BaseDoesntExist.into()
325 } else {
326 err
327 })?;
328 collection.check_is_external()?;
329
330 Ok(collection)
331 }
271}332}
272333
modifiedpallets/proxy-rmrk-equip/src/weights.rsdiffbeforeafterboth
3//! Autogenerated weights for pallet_proxy_rmrk_equip3//! Autogenerated weights for pallet_proxy_rmrk_equip
4//!4//!
5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev5//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 4.0.0-dev
6//! DATE: 2022-06-16, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`6//! DATE: 2022-06-20, STEPS: `50`, REPEAT: 80, LOW RANGE: `[]`, HIGH RANGE: `[]`
7//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 10247//! EXECUTION: None, WASM-EXECUTION: Compiled, CHAIN: None, DB CACHE: 1024
88
9// Executed Command:9// Executed Command:
35pub trait WeightInfo {35pub trait WeightInfo {
36 fn create_base(b: u32, ) -> Weight;36 fn create_base(b: u32, ) -> Weight;
37 fn theme_add(b: u32, ) -> Weight;37 fn theme_add(b: u32, ) -> Weight;
38 fn equippable() -> Weight;
38}39}
3940
40/// Weights for pallet_proxy_rmrk_equip using the Substrate node and recommended hardware.41/// Weights for pallet_proxy_rmrk_equip using the Substrate node and recommended hardware.
53 // Storage: Nonfungible Owned (r:0 w:1)54 // Storage: Nonfungible Owned (r:0 w:1)
54 // Storage: RmrkEquip InernalPartId (r:0 w:1)55 // Storage: RmrkEquip InernalPartId (r:0 w:1)
55 fn create_base(b: u32, ) -> Weight {56 fn create_base(b: u32, ) -> Weight {
56 (43_216_000 as Weight)57 (44_632_000 as Weight)
57 // Standard Error: 10_00058 // Standard Error: 10_000
58 .saturating_add((16_253_000 as Weight).saturating_mul(b as Weight))59 .saturating_add((16_912_000 as Weight).saturating_mul(b as Weight))
59 .saturating_add(T::DbWeight::get().reads(6 as Weight))60 .saturating_add(T::DbWeight::get().reads(6 as Weight))
60 .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))61 .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
61 .saturating_add(T::DbWeight::get().writes(9 as Weight))62 .saturating_add(T::DbWeight::get().writes(8 as Weight))
62 .saturating_add(T::DbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))63 .saturating_add(T::DbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))
63 }64 }
64 // Storage: Common CollectionProperties (r:1 w:0)65 // Storage: Common CollectionProperties (r:1 w:0)
65 // Storage: Common CollectionById (r:1 w:0)66 // Storage: Common CollectionById (r:1 w:0)
70 // Storage: Nonfungible TokenData (r:0 w:1)71 // Storage: Nonfungible TokenData (r:0 w:1)
71 // Storage: Nonfungible Owned (r:0 w:1)72 // Storage: Nonfungible Owned (r:0 w:1)
72 fn theme_add(b: u32, ) -> Weight {73 fn theme_add(b: u32, ) -> Weight {
73 (39_467_000 as Weight)74 (39_525_000 as Weight)
74 // Standard Error: 15_00075 // Standard Error: 12_000
75 .saturating_add((2_332_000 as Weight).saturating_mul(b as Weight))76 .saturating_add((2_494_000 as Weight).saturating_mul(b as Weight))
76 .saturating_add(T::DbWeight::get().reads(6 as Weight))77 .saturating_add(T::DbWeight::get().reads(6 as Weight))
77 .saturating_add(T::DbWeight::get().writes(5 as Weight))78 .saturating_add(T::DbWeight::get().writes(5 as Weight))
78 }79 }
80 // Storage: Common CollectionProperties (r:1 w:0)
81 // Storage: Common CollectionById (r:1 w:0)
82 // Storage: RmrkEquip InernalPartId (r:1 w:0)
83 // Storage: Nonfungible TokenProperties (r:1 w:1)
84 fn equippable() -> Weight {
85 (27_371_000 as Weight)
86 .saturating_add(T::DbWeight::get().reads(4 as Weight))
87 .saturating_add(T::DbWeight::get().writes(1 as Weight))
88 }
79}89}
8090
81// For backwards compatibility and tests91// For backwards compatibility and tests
93 // Storage: Nonfungible Owned (r:0 w:1)103 // Storage: Nonfungible Owned (r:0 w:1)
94 // Storage: RmrkEquip InernalPartId (r:0 w:1)104 // Storage: RmrkEquip InernalPartId (r:0 w:1)
95 fn create_base(b: u32, ) -> Weight {105 fn create_base(b: u32, ) -> Weight {
96 (43_216_000 as Weight)106 (44_632_000 as Weight)
97 // Standard Error: 10_000107 // Standard Error: 10_000
98 .saturating_add((16_253_000 as Weight).saturating_mul(b as Weight))108 .saturating_add((16_912_000 as Weight).saturating_mul(b as Weight))
99 .saturating_add(RocksDbWeight::get().reads(6 as Weight))109 .saturating_add(RocksDbWeight::get().reads(6 as Weight))
100 .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))110 .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
101 .saturating_add(RocksDbWeight::get().writes(9 as Weight))111 .saturating_add(RocksDbWeight::get().writes(8 as Weight))
102 .saturating_add(RocksDbWeight::get().writes((3 as Weight).saturating_mul(b as Weight)))112 .saturating_add(RocksDbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))
103 }113 }
104 // Storage: Common CollectionProperties (r:1 w:0)114 // Storage: Common CollectionProperties (r:1 w:0)
105 // Storage: Common CollectionById (r:1 w:0)115 // Storage: Common CollectionById (r:1 w:0)
110 // Storage: Nonfungible TokenData (r:0 w:1)120 // Storage: Nonfungible TokenData (r:0 w:1)
111 // Storage: Nonfungible Owned (r:0 w:1)121 // Storage: Nonfungible Owned (r:0 w:1)
112 fn theme_add(b: u32, ) -> Weight {122 fn theme_add(b: u32, ) -> Weight {
113 (39_467_000 as Weight)123 (39_525_000 as Weight)
114 // Standard Error: 15_000124 // Standard Error: 12_000
115 .saturating_add((2_332_000 as Weight).saturating_mul(b as Weight))125 .saturating_add((2_494_000 as Weight).saturating_mul(b as Weight))
116 .saturating_add(RocksDbWeight::get().reads(6 as Weight))126 .saturating_add(RocksDbWeight::get().reads(6 as Weight))
117 .saturating_add(RocksDbWeight::get().writes(5 as Weight))127 .saturating_add(RocksDbWeight::get().writes(5 as Weight))
118 }128 }
129 // Storage: Common CollectionProperties (r:1 w:0)
130 // Storage: Common CollectionById (r:1 w:0)
131 // Storage: RmrkEquip InernalPartId (r:1 w:0)
132 // Storage: Nonfungible TokenProperties (r:1 w:1)
133 fn equippable() -> Weight {
134 (27_371_000 as Weight)
135 .saturating_add(RocksDbWeight::get().reads(4 as Weight))
136 .saturating_add(RocksDbWeight::get().writes(1 as Weight))
137 }
119}138}
120139
modifiedprimitives/data-structs/src/lib.rsdiffbeforeafterboth
39// RMRK39// RMRK
40use rmrk_traits::{40use rmrk_traits::{
41 CollectionInfo, NftInfo, ResourceInfo, PropertyInfo, BaseInfo, PartType, Theme, ThemeProperty,41 CollectionInfo, NftInfo, ResourceInfo, PropertyInfo, BaseInfo, PartType, Theme, ThemeProperty,
42 ResourceTypes, BasicResource, ComposableResource, SlotResource,42 ResourceTypes, BasicResource, ComposableResource, SlotResource, EquippableList,
43};43};
44pub use rmrk_traits::{44pub use rmrk_traits::{
45 primitives::{45 primitives::{
46 CollectionId as RmrkCollectionId, NftId as RmrkNftId, BaseId as RmrkBaseId,46 CollectionId as RmrkCollectionId, NftId as RmrkNftId, BaseId as RmrkBaseId,
47 PartId as RmrkPartId, ResourceId as RmrkResourceId,47 SlotId as RmrkSlotId, PartId as RmrkPartId, ResourceId as RmrkResourceId,
48 },48 },
49 NftChild as RmrkNftChild, AccountIdOrCollectionNftTuple as RmrkAccountIdOrCollectionNftTuple,49 NftChild as RmrkNftChild, AccountIdOrCollectionNftTuple as RmrkAccountIdOrCollectionNftTuple,
50 FixedPart as RmrkFixedPart, SlotPart as RmrkSlotPart, EquippableList as RmrkEquippableList,50 FixedPart as RmrkFixedPart, SlotPart as RmrkSlotPart,
51};51};
5252
53mod bounded;53mod bounded;
987pub type RmrkResourceInfo = ResourceInfo<RmrkString, RmrkBoundedParts>;987pub type RmrkResourceInfo = ResourceInfo<RmrkString, RmrkBoundedParts>;
988pub type RmrkPropertyInfo = PropertyInfo<RmrkKeyString, RmrkValueString>;988pub type RmrkPropertyInfo = PropertyInfo<RmrkKeyString, RmrkValueString>;
989pub type RmrkBaseInfo<AccountId> = BaseInfo<AccountId, RmrkString>;989pub type RmrkBaseInfo<AccountId> = BaseInfo<AccountId, RmrkString>;
990pub type RmrkPartType =990pub type BoundedEquippableCollectionIds = BoundedVec<RmrkCollectionId, RmrkMaxCollectionsEquippablePerPart>;
991 PartType<RmrkString, BoundedVec<RmrkCollectionId, RmrkMaxCollectionsEquippablePerPart>>;991pub type RmrkPartType = PartType<RmrkString, BoundedEquippableCollectionIds>;
992pub type RmrkEquippableList = EquippableList<BoundedEquippableCollectionIds>;
992pub type RmrkThemeProperty = ThemeProperty<RmrkString>;993pub type RmrkThemeProperty = ThemeProperty<RmrkString>;
993pub type RmrkTheme = Theme<RmrkString, Vec<RmrkThemeProperty>>;994pub type RmrkTheme = Theme<RmrkString, Vec<RmrkThemeProperty>>;
994pub type RmrkBoundedTheme = Theme<RmrkString, BoundedVec<RmrkThemeProperty, MaxPropertiesPerTheme>>;995pub type RmrkBoundedTheme = Theme<RmrkString, BoundedVec<RmrkThemeProperty, MaxPropertiesPerTheme>>;