difftreelog
fix(rmrk) rewrite existing parts if dups exist
in: master
3 files changed
pallets/proxy-rmrk-equip/src/benchmarking.rsdiffbeforeafterboth1use sp_std::vec;23use frame_benchmarking::{benchmarks, account};4use frame_system::RawOrigin;5use frame_support::{6 traits::{Currency, Get},7 BoundedVec,8};910use up_data_structs::*;1112use super::*;1314const SEED: u32 = 1;1516fn create_data<S: Get<u32>>() -> BoundedVec<u8, S> {17 vec![b'A'; S::get() as usize].try_into().expect("size == S")18}1920fn create_u32_array<S: Get<u32>>() -> BoundedVec<u32, S> {21 vec![0; S::get() as usize].try_into().expect("size == S")22}2324fn create_max_part() -> RmrkPartType {25 RmrkPartType::SlotPart(RmrkSlotPart {26 id: 42,27 equippable: RmrkEquippableList::Custom(create_u32_array()),28 src: create_data(),29 z: 1,30 })31}3233fn create_parts_array<S: Get<u32>>(num: u32) -> BoundedVec<RmrkPartType, S> {34 vec![create_max_part(); num as usize]35 .try_into()36 .expect("num <= S")37}3839fn create_max_theme_property() -> RmrkThemeProperty {40 RmrkThemeProperty {41 key: create_data(),42 value: create_data(),43 }44}4546fn create_theme_properties_array<S: Get<u32>>(num: u32) -> BoundedVec<RmrkThemeProperty, S> {47 vec![create_max_theme_property(); num as usize]48 .try_into()49 .expect("num <= S")50}5152fn create_max_theme(name: RmrkString, props_num: u32) -> RmrkBoundedTheme {53 RmrkBoundedTheme {54 name,55 properties: create_theme_properties_array(props_num),56 inherit: false,57 }58}5960benchmarks! {61 create_base {62 let b in 0..RmrkPartsLimit::get();6364 let caller = account("caller", 0, SEED);65 <T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());6667 let base_type = create_data();68 let symbol = create_data();69 let parts = create_parts_array(b);70 }: _(RawOrigin::Signed(caller), base_type, symbol, parts)7172 theme_add {73 let b in 0..MaxPropertiesPerTheme::get();7475 let caller = account("caller", 0, SEED);76 <T as pallet_common::Config>::Currency::deposit_creating(&caller, T::CollectionCreationPrice::get());7778 let base_type = create_data();79 let symbol = create_data();80 let parts = create_parts_array(0);8182 <Pallet<T>>::create_base(RawOrigin::Signed(caller.clone()).into(), base_type, symbol, parts)?;83 let base_id = 1;848586 let default_theme_name = b"default".to_vec().try_into().expect("default is a valid name; qed");87 let default_theme = create_max_theme(default_theme_name, 0);8889 <Pallet<T>>::theme_add(RawOrigin::Signed(caller.clone()).into(), base_id, default_theme)?;9091 let theme = create_max_theme(create_data(), b);92 }: _(RawOrigin::Signed(caller), base_id, theme)93}pallets/proxy-rmrk-equip/src/lib.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-equip/src/lib.rs
+++ b/pallets/proxy-rmrk-equip/src/lib.rs
@@ -141,17 +141,7 @@
let collection = <PalletCore<T>>::get_nft_collection(collection_id)?;
for part in parts {
- let part_id = part.id();
- let part_token_id = Self::create_part(&cross_sender, &collection, part)?;
-
- <InernalPartId<T>>::insert(collection_id, part_id, part_token_id);
-
- <PalletNft<T>>::set_scoped_token_property(
- collection_id,
- part_token_id,
- PropertyScope::Rmrk,
- <PalletCore<T>>::rmrk_property(ExternalPartId, &part_id)?,
- )?;
+ Self::create_part(&cross_sender, &collection, part)?;
}
Self::deposit_event(Event::BaseCreated {
@@ -279,9 +269,10 @@
sender: &T::CrossAccountId,
collection: &NonfungibleHandle<T>,
part: RmrkPartType,
- ) -> Result<TokenId, DispatchError> {
+ ) -> DispatchResult {
let owner = sender;
+ let part_id = part.id();
let src = part.src();
let z_index = part.z_index();
@@ -290,32 +281,55 @@
RmrkPartType::SlotPart(_) => NftType::SlotPart,
};
- let token_id = <PalletCore<T>>::create_nft(
- sender,
- owner,
- collection,
+ let token_id = match Self::internal_part_id(collection.id, part_id) {
+ Some(token_id) => token_id,
+ None => {
+ let token_id = <PalletCore<T>>::create_nft(
+ sender,
+ owner,
+ collection,
+ [].into_iter(),
+ )
+ .map_err(|err| match err {
+ DispatchError::Arithmetic(_) => <Error<T>>::NoAvailablePartId.into(),
+ err => err,
+ })?;
+
+ <InernalPartId<T>>::insert(collection.id, part_id, token_id);
+
+ <PalletNft<T>>::set_scoped_token_property(
+ collection.id,
+ token_id,
+ PropertyScope::Rmrk,
+ <PalletCore<T>>::rmrk_property(ExternalPartId, &part_id)?,
+ )?;
+
+ token_id
+ }
+ };
+
+ <PalletNft<T>>::set_scoped_token_properties(
+ collection.id,
+ token_id,
+ PropertyScope::Rmrk,
[
<PalletCore<T>>::rmrk_property(TokenType, &nft_type)?,
<PalletCore<T>>::rmrk_property(Src, &src)?,
<PalletCore<T>>::rmrk_property(ZIndex, &z_index)?,
]
- .into_iter(),
- )
- .map_err(|err| match err {
- DispatchError::Arithmetic(_) => <Error<T>>::NoAvailablePartId.into(),
- err => err,
- })?;
+ .into_iter()
+ )?;
if let RmrkPartType::SlotPart(part) = part {
<PalletNft<T>>::set_scoped_token_property(
collection.id,
token_id,
PropertyScope::Rmrk,
- <PalletCore<T>>::rmrk_property(EquippableList, &part.equippable)?,
+ <PalletCore<T>>::rmrk_property(EquippableList, &part.equippable)?
)?;
}
- Ok(token_id)
+ Ok(())
}
fn get_base(base_id: CollectionId) -> Result<NonfungibleHandle<T>, DispatchError> {
pallets/proxy-rmrk-equip/src/weights.rsdiffbeforeafterboth--- a/pallets/proxy-rmrk-equip/src/weights.rs
+++ b/pallets/proxy-rmrk-equip/src/weights.rs
@@ -47,18 +47,18 @@
// Storage: Common CollectionPropertyPermissions (r:0 w:1)
// Storage: Common CollectionProperties (r:0 w:1)
// Storage: Common CollectionById (r:0 w:1)
+ // Storage: RmrkEquip InernalPartId (r:1 w:1)
// Storage: Nonfungible TokensMinted (r:1 w:1)
// Storage: Nonfungible AccountBalance (r:1 w:1)
// Storage: Nonfungible TokenProperties (r:1 w:1)
// Storage: Nonfungible TokenData (r:0 w:1)
// Storage: Nonfungible Owned (r:0 w:1)
- // Storage: RmrkEquip InernalPartId (r:0 w:1)
fn create_base(b: u32, ) -> Weight {
- (44_632_000 as Weight)
- // Standard Error: 10_000
- .saturating_add((16_912_000 as Weight).saturating_mul(b as Weight))
+ (44_927_000 as Weight)
+ // Standard Error: 9_000
+ .saturating_add((18_896_000 as Weight).saturating_mul(b as Weight))
.saturating_add(T::DbWeight::get().reads(6 as Weight))
- .saturating_add(T::DbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
+ .saturating_add(T::DbWeight::get().reads((2 as Weight).saturating_mul(b as Weight)))
.saturating_add(T::DbWeight::get().writes(8 as Weight))
.saturating_add(T::DbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))
}
@@ -71,9 +71,9 @@
// Storage: Nonfungible TokenData (r:0 w:1)
// Storage: Nonfungible Owned (r:0 w:1)
fn theme_add(b: u32, ) -> Weight {
- (39_525_000 as Weight)
- // Standard Error: 12_000
- .saturating_add((2_494_000 as Weight).saturating_mul(b as Weight))
+ (39_120_000 as Weight)
+ // Standard Error: 11_000
+ .saturating_add((2_367_000 as Weight).saturating_mul(b as Weight))
.saturating_add(T::DbWeight::get().reads(6 as Weight))
.saturating_add(T::DbWeight::get().writes(5 as Weight))
}
@@ -82,7 +82,7 @@
// Storage: RmrkEquip InernalPartId (r:1 w:0)
// Storage: Nonfungible TokenProperties (r:1 w:1)
fn equippable() -> Weight {
- (27_371_000 as Weight)
+ (27_172_000 as Weight)
.saturating_add(T::DbWeight::get().reads(4 as Weight))
.saturating_add(T::DbWeight::get().writes(1 as Weight))
}
@@ -96,18 +96,18 @@
// Storage: Common CollectionPropertyPermissions (r:0 w:1)
// Storage: Common CollectionProperties (r:0 w:1)
// Storage: Common CollectionById (r:0 w:1)
+ // Storage: RmrkEquip InernalPartId (r:1 w:1)
// Storage: Nonfungible TokensMinted (r:1 w:1)
// Storage: Nonfungible AccountBalance (r:1 w:1)
// Storage: Nonfungible TokenProperties (r:1 w:1)
// Storage: Nonfungible TokenData (r:0 w:1)
// Storage: Nonfungible Owned (r:0 w:1)
- // Storage: RmrkEquip InernalPartId (r:0 w:1)
fn create_base(b: u32, ) -> Weight {
- (44_632_000 as Weight)
- // Standard Error: 10_000
- .saturating_add((16_912_000 as Weight).saturating_mul(b as Weight))
+ (44_927_000 as Weight)
+ // Standard Error: 9_000
+ .saturating_add((18_896_000 as Weight).saturating_mul(b as Weight))
.saturating_add(RocksDbWeight::get().reads(6 as Weight))
- .saturating_add(RocksDbWeight::get().reads((1 as Weight).saturating_mul(b as Weight)))
+ .saturating_add(RocksDbWeight::get().reads((2 as Weight).saturating_mul(b as Weight)))
.saturating_add(RocksDbWeight::get().writes(8 as Weight))
.saturating_add(RocksDbWeight::get().writes((4 as Weight).saturating_mul(b as Weight)))
}
@@ -120,9 +120,9 @@
// Storage: Nonfungible TokenData (r:0 w:1)
// Storage: Nonfungible Owned (r:0 w:1)
fn theme_add(b: u32, ) -> Weight {
- (39_525_000 as Weight)
- // Standard Error: 12_000
- .saturating_add((2_494_000 as Weight).saturating_mul(b as Weight))
+ (39_120_000 as Weight)
+ // Standard Error: 11_000
+ .saturating_add((2_367_000 as Weight).saturating_mul(b as Weight))
.saturating_add(RocksDbWeight::get().reads(6 as Weight))
.saturating_add(RocksDbWeight::get().writes(5 as Weight))
}
@@ -131,7 +131,7 @@
// Storage: RmrkEquip InernalPartId (r:1 w:0)
// Storage: Nonfungible TokenProperties (r:1 w:1)
fn equippable() -> Weight {
- (27_371_000 as Weight)
+ (27_172_000 as Weight)
.saturating_add(RocksDbWeight::get().reads(4 as Weight))
.saturating_add(RocksDbWeight::get().writes(1 as Weight))
}