rmrk-substrate icon indicating copy to clipboard operation
rmrk-substrate copied to clipboard

Adding Metadata to Base

Open Szegoo opened this issue 2 years ago • 5 comments

Inside the RMRK specifications, it is defined that the base should also have the ability to store metadata. This is specified inside here.

Szegoo avatar Jan 23 '23 19:01 Szegoo

@ilionic I would like to get your confirmation before I start working on this to make sure that this is indeed something that should be added to the RMRK pallets.

Szegoo avatar Jan 23 '23 19:01 Szegoo

@Szegoo yes that's correct - Base ( to be renamed to Catalog ) should have metadata ( as well as parts )

ilionic avatar Jan 23 '23 21:01 ilionic

Ok, since we are going to store metadata for multiple entities(Nfts, Collections, Bases, Parts) we might want to do something like the following so that we avoid code duplication.

// define an enum that will have all of the mentioned entities that will store metadata
enum Entity<T: Config> {
        /// The entity is a collection
        Collection(T::CollectionId),
	/// The entity is a collection nft
	Nft(T::CollectionId, T::ItemId),
	/// The entity is a base
	Base(BaseId), 
        /// The entity is a Part
        Part(PartId),
}

// --snip--
#[pallet::call_index(9)]
#[pallet::weight(<T as pallet::Config>::WeightInfo::set_property())]
#[transactional]
pub fn set_property(
	origin: OriginFor<T>,
	entity: Entity<T>,
	key: KeyLimitOf<T>,
	value: ValueLimitOf<T>,
) -> DispatchResult {
        let sender = ensure_signed(origin)?;

	Self::property_set(sender, collection_id, maybe_nft_id, key.clone(), value.clone())?;

	Self::deposit_event(Event::PropertySet { collection_id, maybe_nft_id, key, value });
	Ok(())
}
// --snip--

And then inside functions.rs we implement custom logic for every type.

@ilionic @HashWarlock Do you think this makes sense?

Szegoo avatar Jan 24 '23 21:01 Szegoo

Which parts would create duplicated code? I would think that we can still keep the parameters, and have an internal function that sets the metadata based on the Entity we would pass to the function.

HashWarlock avatar Jan 24 '23 22:01 HashWarlock

Which parts would create duplicated code? I would think that we can still keep the parameters, and have an internal function that sets the metadata based on the Entity we would pass to the function.

If I understand you correctly you are suggesting that we have separate extrinsics for setting the metadata for each of these Entities but have each of them call the same function inside functions.rs. That is possible but we would need to have a separate extrinsic for each of these(which I assume isn't bad). So we can probably do that if you want to.

But I do think that we need to introduce an Entity enum to the code. This will even help us with the Event type since we don't have to make separate event variants for each of these entities(otherwise we would need to define NftPropertySet, CollectionPropertySet, and so on). Instead of doing this, we can just create a single event variant that will be universal

PropertySet {
	entity: Entity<T>,
	key: KeyLimitOf<T>,
	value: ValueLimitOf<T>,
},

Szegoo avatar Jan 24 '23 22:01 Szegoo