flow-nft
flow-nft copied to clipboard
Adding support in MetadataViews to support viewing nested resources
Issue To Be Solved
MetadataViews should be implemented in almost all resources to tell what the resource is about. At the moment, resources that are nested has no generic way to expose their views. Projects do it in there own way which is not really useful or efficient.
The proposal here introduce a new function that treats every nesting resource as a "collection" of the nested resources. By implementing MetadataViews.ResolverCollection to the "collection" resource, we can easily get the nested resources and it's resolver(i.e. the views).
Suggest A Solution
Additions to MetadataViews.ResolverCollection interface
pub resource interface ResolverCollection {
pub fun borrowViewResolver(id: UInt64): &{Resolver}
pub fun getIDs(): [UInt64]
// Adding a new function with default implementation here to expose subCollection ResolverCollection
// If a resource contains any other resources that implements MetadataViews.Resolver, this should return the resolver of the nested resource
// return nil by default , which means that the resource does not contain nested resources / querying id does not exist.
pub fun borrowSubCollection(id: UInt64): &{ResolverCollection}? {
return nil
}
}
An proposed implementation can be seen here: https://github.com/crash13override/flovatar/pull/10 Taking Flovatar and FlovatarMarketplace as an example, trying to :
- expose Flovatar Components from Flovatar NFT
- expose Flovatar NFT from Flovatar SaleItem Collection
This supports looping quite well. If you would like to view on Flovatar Components equipped on a Flovatar that is listed : Flovatar SaleItem Collection -> Flovatar NFT -> Flovatar Components
all credits to @bjartek
little nit but why not borrowSubCollection() on Resolver ?
though still this seems a bit limiting, for example if flovatar had also something like Flovatar PowerUps beside Flovatar Components then it would be not possible to show them.
Maybe we can cover this with a MetadataViewSubMeta or something like this ?
borrowSubCollection on Resolver could also work here.
Not really sure how to overcome that limitation. We have hit that already since we have a use case where an NFT can hold two different types of subNFTs. However since they both/all use uuid for ids there is no conflict.
@Bamthelearner I think this is a good idea! Can you make a PR for this and integrate the other suggestions in this thread, along with some tests? Thank you! If you can't get to it now, we'll get to it at some point in the near future
I like it better as a method of Resolver, that way resources that aren't an actual collection could keep implementing that interface rather than ResolverCollection.
I agree that there's a need of exposing nested resources metadata, but I wonder if we should mind for this the new cadence attachments feature and came up with a solution that serves both scenarios (if that's possible)
I dont think using attachments here is the way to go. That feature is a little bit off still and this is just a method defaultly implemented.
Currently if an NFT is held in a contract field you can't access it's MetadataViews. This seems related, would this solve that too?
as long as you can get hold of an &{INFT} you can now get its views, since these methods are defaultly implemented.
Maybe this should be merged with the NFTv2 discussion? I am not sure. I just really want the ability to discover read nested structures of resources in a sane way.
I'm not sure either. I think we need to solve the uuid problem before we can have a universal way of doing this, so maybe that is part of the v2 standards
It has been a few months with no activity in this issue or PR. Anyone have any thoughts or able to update the PR based on the suggestions in it? Or should we close this?
I dont think we should close this as it is needed IMHO. But I think it should be handled along with NFTv2.
Any idea of how we might handle this in NFTv2? Should we think about adding it to the ViewResolver contract with uuid as the argument?
Sorry for lack of activity just been super busy diving into flow. Me and Luca from flovatar have been meaning to discuss something around composite nfts but we have never gotten to it. Maybe we should invite you and others that want to join for a more formal discussion?
no worries! We also haven't had much bandwidth to get to most of these metadata views requests. I could get a few people to join a call if y'all want to have it, but we're not really in a hurry right now
We're planning on discussing including this in the v2 token standards during the smart contract open house on tuesday dec 5th. The event is on the Flow public calendar and will be announced in discord.
Good. I will have a demo/proposal ready by then.
Addressed in the V2 standard with getAvailableSubNFTs