difftreelog
fix(rmrk) rewrite existing parts if dups exist
in: master
3 files changed
pallets/proxy-rmrk-equip/src/benchmarking.rsdiffbeforeafterboth21 vec![0; S::get() as usize].try_into().expect("size == S")21 vec![0; S::get() as usize].try_into().expect("size == S")22}22}232324fn create_max_part() -> RmrkPartType {24fn create_max_part(id: RmrkSlotId) -> RmrkPartType {25 RmrkPartType::SlotPart(RmrkSlotPart {25 RmrkPartType::SlotPart(RmrkSlotPart {26 id: 42,26 id,27 equippable: RmrkEquippableList::Custom(create_u32_array()),27 equippable: RmrkEquippableList::Custom(create_u32_array()),28 src: create_data(),28 src: create_data(),29 z: 1,29 z: 1,30 })30 })31}31}323233fn create_parts_array<S: Get<u32>>(num: u32) -> BoundedVec<RmrkPartType, S> {33fn create_parts_array<S: Get<u32>>(num: u32) -> BoundedVec<RmrkPartType, S> {34 vec![create_max_part(); num as usize]34 let mut parts: BoundedVec<RmrkPartType, S> = vec![].try_into().expect("0 <= S");35 .try_into()3536 .expect("num <= S")36 for i in 0..num {37 parts.try_push(create_max_part(i)).expect("num <= S");38 }3940 parts37}41}384239fn create_max_theme_property() -> RmrkThemeProperty {43fn create_max_theme_property() -> RmrkThemeProperty {91 let theme = create_max_theme(create_data(), b);95 let theme = create_max_theme(create_data(), b);92 }: _(RawOrigin::Signed(caller), base_id, theme)96 }: _(RawOrigin::Signed(caller), base_id, theme)9798 equippable {99 let caller = account("caller", 0, SEED);100 <T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());101102 let base_id = 1;103 let slot_id = 42;104105 let base_type = create_data();106 let symbol = create_data();107 let parts = vec! {108 RmrkPartType::SlotPart(RmrkSlotPart {109 id: slot_id,110 equippable: RmrkEquippableList::All,111 src: create_data(),112 z: 1,113 })114 }.try_into().expect("1 <= RmrkPartsLimit");115116 <Pallet<T>>::create_base(RawOrigin::Signed(caller.clone()).into(), base_type, symbol, parts)?;117118 let equippables = RmrkEquippableList::Custom(create_u32_array());119 }: _(RawOrigin::Signed(caller), base_id, slot_id, equippables)93}120}94121pallets/proxy-rmrk-equip/src/lib.rsdiffbeforeafterboth141 let collection = <PalletCore<T>>::get_nft_collection(collection_id)?;141 let collection = <PalletCore<T>>::get_nft_collection(collection_id)?;142142143 for part in parts {143 for part in parts {144 let part_id = part.id();145 let part_token_id = Self::create_part(&cross_sender, &collection, part)?;144 Self::create_part(&cross_sender, &collection, part)?;146147 <InernalPartId<T>>::insert(collection_id, part_id, part_token_id);148149 <PalletNft<T>>::set_scoped_token_property(150 collection_id,151 part_token_id,152 PropertyScope::Rmrk,153 <PalletCore<T>>::rmrk_property(ExternalPartId, &part_id)?,154 )?;155 }145 }156146157 Self::deposit_event(Event::BaseCreated {147 Self::deposit_event(Event::BaseCreated {279 sender: &T::CrossAccountId,269 sender: &T::CrossAccountId,280 collection: &NonfungibleHandle<T>,270 collection: &NonfungibleHandle<T>,281 part: RmrkPartType,271 part: RmrkPartType,282 ) -> Result<TokenId, DispatchError> {272 ) -> DispatchResult {283 let owner = sender;273 let owner = sender;284274275 let part_id = part.id();285 let src = part.src();276 let src = part.src();286 let z_index = part.z_index();277 let z_index = part.z_index();287278290 RmrkPartType::SlotPart(_) => NftType::SlotPart,281 RmrkPartType::SlotPart(_) => NftType::SlotPart,291 };282 };292283293 let token_id = <PalletCore<T>>::create_nft(284 let token_id = match Self::internal_part_id(collection.id, part_id) {285 Some(token_id) => token_id,286 None => {287 let token_id = <PalletCore<T>>::create_nft(288 sender,289 owner,290 collection,291 [].into_iter(),292 )293 .map_err(|err| match err {294 DispatchError::Arithmetic(_) => <Error<T>>::NoAvailablePartId.into(),295 err => err,296 })?;297298 <InernalPartId<T>>::insert(collection.id, part_id, token_id);299300 <PalletNft<T>>::set_scoped_token_property(301 collection.id,302 token_id,303 PropertyScope::Rmrk,304 <PalletCore<T>>::rmrk_property(ExternalPartId, &part_id)?,305 )?;306307 token_id308 }309 };310311 <PalletNft<T>>::set_scoped_token_properties(294 sender,312 collection.id,295 owner,313 token_id,296 collection,314 PropertyScope::Rmrk,297 [315 [298 <PalletCore<T>>::rmrk_property(TokenType, &nft_type)?,316 <PalletCore<T>>::rmrk_property(TokenType, &nft_type)?,299 <PalletCore<T>>::rmrk_property(Src, &src)?,317 <PalletCore<T>>::rmrk_property(Src, &src)?,300 <PalletCore<T>>::rmrk_property(ZIndex, &z_index)?,318 <PalletCore<T>>::rmrk_property(ZIndex, &z_index)?,301 ]319 ]302 .into_iter(),320 .into_iter()303 )304 .map_err(|err| match err {305 DispatchError::Arithmetic(_) => <Error<T>>::NoAvailablePartId.into(),306 err => err,307 })?;321 )?;308322309 if let RmrkPartType::SlotPart(part) = part {323 if let RmrkPartType::SlotPart(part) = part {310 <PalletNft<T>>::set_scoped_token_property(324 <PalletNft<T>>::set_scoped_token_property(315 )?;329 )?;316 }330 }317331318 Ok(token_id)332 Ok(())319 }333 }320334321 fn get_base(base_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {335 fn get_base(base_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {pallets/proxy-rmrk-equip/src/weights.rsdiffbeforeafterboth47 // Storage: Common CollectionPropertyPermissions (r:0 w:1)47 // Storage: Common CollectionPropertyPermissions (r:0 w:1)48 // Storage: Common CollectionProperties (r:0 w:1)48 // Storage: Common CollectionProperties (r:0 w:1)49 // Storage: Common CollectionById (r:0 w:1)49 // Storage: Common CollectionById (r:0 w:1)50 // Storage: RmrkEquip InernalPartId (r:1 w:1)50 // Storage: Nonfungible TokensMinted (r:1 w:1)51 // Storage: Nonfungible TokensMinted (r:1 w:1)51 // Storage: Nonfungible AccountBalance (r:1 w:1)52 // Storage: Nonfungible AccountBalance (r:1 w:1)52 // Storage: Nonfungible TokenProperties (r:1 w:1)53 // Storage: Nonfungible TokenProperties (r:1 w:1)53 // Storage: Nonfungible TokenData (r:0 w:1)54 // Storage: Nonfungible TokenData (r:0 w:1)54 // Storage: Nonfungible Owned (r:0 w:1)55 // Storage: Nonfungible Owned (r:0 w:1)55 // Storage: RmrkEquip InernalPartId (r:0 w:1)56 fn create_base(b: u32, ) -> Weight {56 fn create_base(b: u32, ) -> Weight {57 (44_632_000 as Weight)57 (44_927_000 as Weight)58 // Standard Error: 10_00058 // Standard Error: 9_00059 .saturating_add((16_912_000 as Weight).saturating_mul(b as Weight))59 .saturating_add((18_896_000 as Weight).saturating_mul(b as Weight))60 .saturating_add(T::DbWeight::get().reads(6 as Weight))60 .saturating_add(T::DbWeight::get().reads(6 as Weight))61 .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))61 .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(b as Weight)))62 .saturating_add(T::DbWeight::get().writes(8 as Weight))62 .saturating_add(T::DbWeight::get().writes(8 as Weight))63 .saturating_add(T::DbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))63 .saturating_add(T::DbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))64 }64 }71 // Storage: Nonfungible TokenData (r:0 w:1)71 // Storage: Nonfungible TokenData (r:0 w:1)72 // Storage: Nonfungible Owned (r:0 w:1)72 // Storage: Nonfungible Owned (r:0 w:1)73 fn theme_add(b: u32, ) -> Weight {73 fn theme_add(b: u32, ) -> Weight {74 (39_525_000 as Weight)74 (39_120_000 as Weight)75 // Standard Error: 12_00075 // Standard Error: 11_00076 .saturating_add((2_494_000 as Weight).saturating_mul(b as Weight))76 .saturating_add((2_367_000 as Weight).saturating_mul(b as Weight))77 .saturating_add(T::DbWeight::get().reads(6 as Weight))77 .saturating_add(T::DbWeight::get().reads(6 as Weight))78 .saturating_add(T::DbWeight::get().writes(5 as Weight))78 .saturating_add(T::DbWeight::get().writes(5 as Weight))79 }79 }82 // Storage: RmrkEquip InernalPartId (r:1 w:0)82 // Storage: RmrkEquip InernalPartId (r:1 w:0)83 // Storage: Nonfungible TokenProperties (r:1 w:1)83 // Storage: Nonfungible TokenProperties (r:1 w:1)84 fn equippable() -> Weight {84 fn equippable() -> Weight {85 (27_371_000 as Weight)85 (27_172_000 as Weight)86 .saturating_add(T::DbWeight::get().reads(4 as Weight))86 .saturating_add(T::DbWeight::get().reads(4 as Weight))87 .saturating_add(T::DbWeight::get().writes(1 as Weight))87 .saturating_add(T::DbWeight::get().writes(1 as Weight))88 }88 }96 // Storage: Common CollectionPropertyPermissions (r:0 w:1)96 // Storage: Common CollectionPropertyPermissions (r:0 w:1)97 // Storage: Common CollectionProperties (r:0 w:1)97 // Storage: Common CollectionProperties (r:0 w:1)98 // Storage: Common CollectionById (r:0 w:1)98 // Storage: Common CollectionById (r:0 w:1)99 // Storage: RmrkEquip InernalPartId (r:1 w:1)99 // Storage: Nonfungible TokensMinted (r:1 w:1)100 // Storage: Nonfungible TokensMinted (r:1 w:1)100 // Storage: Nonfungible AccountBalance (r:1 w:1)101 // Storage: Nonfungible AccountBalance (r:1 w:1)101 // Storage: Nonfungible TokenProperties (r:1 w:1)102 // Storage: Nonfungible TokenProperties (r:1 w:1)102 // Storage: Nonfungible TokenData (r:0 w:1)103 // Storage: Nonfungible TokenData (r:0 w:1)103 // Storage: Nonfungible Owned (r:0 w:1)104 // Storage: Nonfungible Owned (r:0 w:1)104 // Storage: RmrkEquip InernalPartId (r:0 w:1)105 fn create_base(b: u32, ) -> Weight {105 fn create_base(b: u32, ) -> Weight {106 (44_632_000 as Weight)106 (44_927_000 as Weight)107 // Standard Error: 10_000107 // Standard Error: 9_000108 .saturating_add((16_912_000 as Weight).saturating_mul(b as Weight))108 .saturating_add((18_896_000 as Weight).saturating_mul(b as Weight))109 .saturating_add(RocksDbWeight::get().reads(6 as Weight))109 .saturating_add(RocksDbWeight::get().reads(6 as Weight))110 .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))110 .saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(b as Weight)))111 .saturating_add(RocksDbWeight::get().writes(8 as Weight))111 .saturating_add(RocksDbWeight::get().writes(8 as Weight))112 .saturating_add(RocksDbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))112 .saturating_add(RocksDbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))113 }113 }120 // Storage: Nonfungible TokenData (r:0 w:1)120 // Storage: Nonfungible TokenData (r:0 w:1)121 // Storage: Nonfungible Owned (r:0 w:1)121 // Storage: Nonfungible Owned (r:0 w:1)122 fn theme_add(b: u32, ) -> Weight {122 fn theme_add(b: u32, ) -> Weight {123 (39_525_000 as Weight)123 (39_120_000 as Weight)124 // Standard Error: 12_000124 // Standard Error: 11_000125 .saturating_add((2_494_000 as Weight).saturating_mul(b as Weight))125 .saturating_add((2_367_000 as Weight).saturating_mul(b as Weight))126 .saturating_add(RocksDbWeight::get().reads(6 as Weight))126 .saturating_add(RocksDbWeight::get().reads(6 as Weight))127 .saturating_add(RocksDbWeight::get().writes(5 as Weight))127 .saturating_add(RocksDbWeight::get().writes(5 as Weight))128 }128 }131 // Storage: RmrkEquip InernalPartId (r:1 w:0)131 // Storage: RmrkEquip InernalPartId (r:1 w:0)132 // Storage: Nonfungible TokenProperties (r:1 w:1)132 // Storage: Nonfungible TokenProperties (r:1 w:1)133 fn equippable() -> Weight {133 fn equippable() -> Weight {134 (27_371_000 as Weight)134 (27_172_000 as Weight)135 .saturating_add(RocksDbWeight::get().reads(4 as Weight))135 .saturating_add(RocksDbWeight::get().reads(4 as Weight))136 .saturating_add(RocksDbWeight::get().writes(1 as Weight))136 .saturating_add(RocksDbWeight::get().writes(1 as Weight))137 }137 }