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

added getInvetory retriever method fixes #30 #32

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
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
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
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
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
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
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() {}

}
}