flow-nft icon indicating copy to clipboard operation
flow-nft copied to clipboard

Adding support in MetadataViews to support viewing nested resources

Open benbackend opened this issue 2 years ago • 16 comments

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 :

  1. expose Flovatar Components from Flovatar NFT
  2. 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

benbackend avatar Jan 06 '23 12:01 benbackend

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 ?

bluesign avatar Jan 07 '23 21:01 bluesign

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.

bjartek avatar Jan 08 '23 14:01 bjartek

@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

joshuahannan avatar Jan 18 '23 21:01 joshuahannan

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)

alilloig avatar Jan 23 '23 15:01 alilloig

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.

bjartek avatar Feb 07 '23 17:02 bjartek

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?

justjoolz avatar Feb 10 '23 07:02 justjoolz

as long as you can get hold of an &{INFT} you can now get its views, since these methods are defaultly implemented.

bjartek avatar Feb 10 '23 07:02 bjartek

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.

bjartek avatar Feb 11 '23 09:02 bjartek

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

joshuahannan avatar Feb 13 '23 14:02 joshuahannan

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?

joshuahannan avatar Apr 05 '23 18:04 joshuahannan

I dont think we should close this as it is needed IMHO. But I think it should be handled along with NFTv2.

bjartek avatar Apr 13 '23 13:04 bjartek

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?

joshuahannan avatar Aug 23 '23 18:08 joshuahannan

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?

bjartek avatar Aug 24 '23 10:08 bjartek

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

joshuahannan avatar Aug 24 '23 18:08 joshuahannan

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.

joshuahannan avatar Dec 01 '23 18:12 joshuahannan

Good. I will have a demo/proposal ready by then.

bjartek avatar Dec 01 '23 18:12 bjartek

Addressed in the V2 standard with getAvailableSubNFTs

joshuahannan avatar May 07 '24 16:05 joshuahannan