Open Szegoo opened 1 year ago
@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 yes that's correct - Base ( to be renamed to Catalog ) should have metadata ( as well as parts )
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?
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.
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>,
},
Inside the RMRK specifications, it is defined that the base should also have the ability to store metadata. This is specified inside here.