Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Metadata to Base #270

Open
Szegoo opened this issue Jan 23, 2023 · 5 comments · May be fixed by #273
Open

Adding Metadata to Base #270

Szegoo opened this issue Jan 23, 2023 · 5 comments · May be fixed by #273
Assignees

Comments

@Szegoo
Copy link
Contributor

Szegoo commented Jan 23, 2023

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

@Szegoo Szegoo self-assigned this Jan 23, 2023
@Szegoo
Copy link
Contributor Author

Szegoo commented Jan 23, 2023

@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.

@ilionic
Copy link
Contributor

ilionic commented Jan 23, 2023

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

@Szegoo
Copy link
Contributor Author

Szegoo commented Jan 24, 2023

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?

@HashWarlock
Copy link
Contributor

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.

@Szegoo
Copy link
Contributor Author

Szegoo commented Jan 24, 2023

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 Szegoo linked a pull request Feb 1, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants