Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion cadence/contracts/NFTRetrieval.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,24 @@ pub contract NFTRetrieval {
return false
}

pub fun getInventory(address:Address) : {String: [UInt64]} {
let inventory : {String:[UInt64]}={}
let account=getAccount(address)
let collections : {String:PublicPath} ={}
let types = NFTCatalog.getCatalogTypeData()
for nftType in types.keys {
let typeData=types[nftType]!
let collectionKey=typeData.keys[0]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 0 index here? Do we want to handle the case if one nft type has multiple collections like Mint Store?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the collections are stored in the same path, we just want the ids of them all. Paritioning these into subcollections will take up a lot of gas since you need to borrow each one.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

let catalogEntry = NFTCatalog.getCatalogEntry(collectionIdentifier:collectionKey)!
let path =catalogEntry.collectionData.publicPath
let cap= account.getCapability<&{MetadataViews.ResolverCollection}>(path)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be guaranteed to exist just a heads up

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will not be guaranteed to not exist? I check if the cap is linked on the next line.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The capability is linked

if cap.check(){
inventory[nftType] = cap.borrow()!.getIDs()
}
}
return inventory
}

init() {}

}
}