-
Notifications
You must be signed in to change notification settings - Fork 33
switch to auto-increment ResourceId #145
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
Conversation
HashWarlock
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good.
I think the
I think we can separate these into their own structs then have an enum for the ResourceType & then make the structs optionals in the ResourceInfo struct. I'll create an issue & try to create a diagram & code to explain what it would look like. |
|
@bmacer regarding the extracting Ids when doing I think you can do something like this: let resources_matching_base_iter =
pallet_rmrk_core::Resources::<T>::iter_prefix((item_collection_id, item_nft_id));
for (id, resource) in resources_matching_base_iter {
match resource.resource {
ResourceTypes::Slot(res) =>
if res.slot == slot_id && res.base == base_id {
found_base_slot_resource_on_nft = true;
to_equip_resource_id = id;
},
_ => (),
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since iteration over current unbounded Resources storage is suboptimal ( as pointed out by Shawn in the linked comment ) we should consider switching it to BoundedVec property of NFT / Base itself so it's safe.
this prevents need for some iteration
I added a commit 20235f9 that can address this, if it's viable. I added Storages for |
|
|
||
| #[derive(Encode, Decode, Eq, PartialEq, Clone, RuntimeDebug, TypeInfo, MaxEncodedLen)] | ||
| #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] | ||
| pub struct ResourceInfo<BoundedResource, BoundedString, BoundedParts> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we keep src, metadata, license & thumb in here? I was thinking ResourceInfo would have the ResourceType that we could match on then get the contents from the nested struct then handle logic from there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, much cleaner. I think that's an acceptable tradeoff having additional storage to avoid unbounded iterations but curious to hear more opinions.
|
|
||
| #[pallet::storage] | ||
| #[pallet::getter(fn slot_resources)] | ||
| /// Stores resource info |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably worth adding few extra docs comments about purpose of this storage ( from your other comment )
| NMapKey<Blake2_128Concat, NftId>, | ||
| NMapKey<Blake2_128Concat, ResourceId>, | ||
| NMapKey<Blake2_128Concat, BaseId>, | ||
| NMapKey<Blake2_128Concat, SlotId>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be safe using TwoX here instead?
| collection_id: CollectionId, | ||
| nft_id: NftId, | ||
| resource_id: BoundedResource, | ||
| resource: ResourceTypes<BoundedString, BoundedPart>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor thing, purely readability - how about renaming resource to more explicit ie resource_type
|
Merging to avoid conflicts. @HashWarlock feel free to extract extra comments to separate issue. @bmacer CC |
addresses #138
One issue that remains is that id is part of the
Resourcestruct. I don't think this is necessary generally. For example, Nft and Collection don't have their respective IDs as part of their struct. However, we need to extract the resource ID when doing an iter_prefix_values for the CollectionID, NftId inside thedo_equipfunction (we do this when checking for the existence of a BaseId+SlotId on the resources for a Slot Resource -- that is, ensuring that there exists a Slot Resource matching the BaseId and SlotId passed to the equip extrinsic).rmrk-substrate/pallets/rmrk-equip/src/functions.rs
Lines 255 to 268 in 218fe30
We could either figure out how to get the key value when iterating through with
iter_prefix_values(I asked the question in StackExchange here), or find a more graceful way of checking altogether.For now, holding the
idin the struct works.