diff --git a/cadence/contracts/NFTRetrieval.cdc b/cadence/contracts/NFTRetrieval.cdc index 4bdbf7d..b39536b 100644 --- a/cadence/contracts/NFTRetrieval.cdc +++ b/cadence/contracts/NFTRetrieval.cdc @@ -150,4 +150,4 @@ pub contract NFTRetrieval { init() {} -} \ No newline at end of file +} diff --git a/cadence/scripts/get_nft_collections_in_account.cdc b/cadence/scripts/get_nft_collections_in_account.cdc new file mode 100644 index 0000000..3ef8a32 --- /dev/null +++ b/cadence/scripts/get_nft_collections_in_account.cdc @@ -0,0 +1,26 @@ +import MetadataViews from "./MetadataViews.cdc" +import NFTCatalog from "./NFTCatalog.cdc" + + +pub fun main(ownerAddress: Address) : {String:[UInt64]} { + + let account = getAuthAccount(ownerAddress) + + let inventory : {String:[UInt64]}={} + let collections : {String:PublicPath} ={} + let types = NFTCatalog.getCatalogTypeData() + for nftType in types.keys { + + let typeData=types[nftType]! + let collectionKey=typeData.keys[0] + let catalogEntry = NFTCatalog.getCatalogEntry(collectionIdentifier:collectionKey)! + let tempPathStr = "catalog".concat(collectionKey) + let tempPublicPath = PublicPath(identifier: tempPathStr)! + account.link<&{MetadataViews.ResolverCollection}>(tempPublicPath, target: catalogEntry.collectionData.storagePath) + let cap= account.getCapability<&{MetadataViews.ResolverCollection}>(tempPublicPath) + if cap.check(){ + inventory[nftType] = cap.borrow()!.getIDs() + } + } + return inventory +}