-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathget_nft_ids_in_account.cdc
32 lines (25 loc) · 1.16 KB
/
get_nft_ids_in_account.cdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import "MetadataViews"
import "NFTCatalog"
import "NFTRetrieval"
import "ViewResolver"
access(all) fun main(ownerAddress: Address): {String: [UInt64]} {
let account = getAuthAccount<auth(Storage,BorrowValue, IssueStorageCapabilityController, PublishCapability, SaveValue, UnpublishCapability) &Account>(ownerAddress)
let items: {String: [UInt64]} = {}
NFTCatalog.forEachCatalogKey(fun (key: String):Bool {
let value = NFTCatalog.getCatalogEntry(collectionIdentifier: key)!
let keyHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(key.utf8))
let tempPathStr = "catalogIDs".concat(keyHash)
let tempPublicPath = PublicPath(identifier: tempPathStr)!
let collectionCap = account.capabilities.storage.issue<&{ViewResolver.ResolverCollection}>(value.collectionData.storagePath)
account.capabilities.publish(collectionCap, at: tempPublicPath)
if !collectionCap.check() {
return true
}
let ids = NFTRetrieval.getNFTIDsFromCap(collectionIdentifier: key, collectionCap: collectionCap)
if ids.length > 0 {
items[key] = ids
}
return true
})
return items
}