From e0d7f934b6a18833b1f30c2f7997de16c09fe439 Mon Sep 17 00:00:00 2001 From: Janez Podhostnik Date: Fri, 10 Mar 2023 13:46:44 +0100 Subject: [PATCH] remove get catalog --- README.md | 171 +++++++++--------- cadence/contracts/FlowToken.cdc | 3 +- cadence/contracts/NFTCatalog.cdc | 12 +- cadence/contracts/NFTRetrieval.cdc | 32 +--- .../contracts/TransactionGenerationUtils.cdc | 6 +- .../get_all_nfts_and_views_in_account.cdc | 20 +- cadence/scripts/get_all_nfts_in_account.cdc | 18 +- .../scripts/get_nft_and_views_in_account.cdc | 83 ++++----- cadence/scripts/get_nft_catalog.cdc | 20 +- cadence/scripts/get_nft_catalog_count.cdc | 9 +- cadence/scripts/get_nft_ids_in_account.cdc | 10 +- cadence/scripts/get_nft_in_account.cdc | 68 ++++--- cadence/scripts/get_nfts_count_in_account.cdc | 10 +- cadence/scripts/get_nfts_in_account.cdc | 97 +++++----- .../scripts/get_nfts_in_account_from_ids.cdc | 96 +++++----- flow.json | 77 -------- ui/test.cdc | 10 +- 17 files changed, 325 insertions(+), 417 deletions(-) diff --git a/README.md b/README.md index 3b48d78..e259acc 100644 --- a/README.md +++ b/README.md @@ -196,8 +196,8 @@ import NFTCatalog from 0x49a7cda3a1eecc29 Due to the large size of the response, only the first 10 entries are returned. */ pub fun main(): {String: NFTCatalog.NFTCatalogMetadata} { - let catalog = NFTCatalog.getCatalog() - let keys = catalog.keys.slice(from: 0, upTo: 10) + let catalog = NFTCatalog.getCatalog() // < -- cannot use this. But I don't know how to fix this example to be equivalent + let keys = catalog.keys.slice(from: 0, upTo: 10) // <-- cannot deterministically slice keys, their order is undefined. let collections: {String: NFTCatalog.NFTCatalogMetadata} = {} for key in keys { @@ -214,12 +214,13 @@ pub fun main(): {String: NFTCatalog.NFTCatalogMetadata} { import NFTCatalog from 0x49a7cda3a1eecc29 pub fun main(): [String] { - let catalog: {String: NFTCatalog.NFTCatalogMetadata} = NFTCatalog.getCatalog() let catalogNames: [String] = [] - for collectionIdentifier in catalog.keys { - catalogNames.append(catalog[collectionIdentifier]!.collectionDisplay.name) - } + NFTCatalog.forEachCatalogKey(fun (key: String):Bool { + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: key) + catalogNames.append(value.collectionDisplay.name) + return true + }) return catalogNames } @@ -233,12 +234,11 @@ import NFTCatalog from 0x49a7cda3a1eecc29 import NFTRetrieval from 0x49a7cda3a1eecc29 pub fun main(ownerAddress: Address): {String: Number} { - let catalog = NFTCatalog.getCatalog() let account = getAuthAccount(ownerAddress) let items: {String: Number} = {} - for key in catalog.keys { - let value = catalog[key]! + NFTCatalog.forEachCatalogKey(fun (key: String):Bool { + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: key) let keyHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(key.utf8)) let tempPathStr = "catalog".concat(keyHash) let tempPublicPath = PublicPath(identifier: tempPathStr)! @@ -251,7 +251,7 @@ pub fun main(ownerAddress: Address): {String: Number} { let collectionCap = account.getCapability<&AnyResource{MetadataViews.ResolverCollection}>(tempPublicPath) if !collectionCap.check() { - continue + return true } let count = NFTRetrieval.getNFTCountFromCap(collectionIdentifier: key, collectionCap: collectionCap) @@ -259,7 +259,8 @@ pub fun main(ownerAddress: Address): {String: Number} { if count > 0 { items[key] = count } - } + return true + }) return items } @@ -336,13 +337,12 @@ pub struct NFT { } pub fun main(ownerAddress: Address): {String: [NFT]} { - let catalog = NFTCatalog.getCatalog() let account = getAuthAccount(ownerAddress) let items: [NFTRetrieval.BaseNFTViewsV1] = [] let data: {String: [NFT]} = {} - for key in catalog.keys { - let value = catalog[key]! + NFTCatalog.forEachCatalogKey(fun (key: String):Bool { + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: key) let keyHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(key.utf8)) let tempPathStr = "catalog".concat(keyHash) let tempPublicPath = PublicPath(identifier: tempPathStr)! @@ -355,7 +355,7 @@ pub fun main(ownerAddress: Address): {String: [NFT]} { let collectionCap = account.getCapability<&AnyResource{MetadataViews.ResolverCollection}>(tempPublicPath) if !collectionCap.check() { - continue + return true } let views = NFTRetrieval.getNFTViewsFromCap(collectionIdentifier: key, collectionCap: collectionCap) @@ -397,7 +397,8 @@ pub fun main(ownerAddress: Address): {String: [NFT]} { } data[key] = items - } + return true + }) return data } @@ -441,13 +442,12 @@ import NFTCatalog from 0x49a7cda3a1eecc29 import NFTRetrieval from 0x49a7cda3a1eecc29 pub fun main(ownerAddress: Address) : {String : [UInt64]} { - let catalog = NFTCatalog.getCatalog() let account = getAuthAccount(ownerAddress) let items : {String : [UInt64]} = {} - for key in catalog.keys { - let value = catalog[key]! + NFTCatalog.forEachCatalogKey(fun (key: String):Bool { + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: key) let tempPathStr = "catalogIDs".concat(key) let tempPublicPath = PublicPath(identifier: tempPathStr)! account.link<&{MetadataViews.ResolverCollection}>( @@ -457,7 +457,7 @@ pub fun main(ownerAddress: Address) : {String : [UInt64]} { let collectionCap = account.getCapability<&AnyResource{MetadataViews.ResolverCollection}>(tempPublicPath) if !collectionCap.check() { - continue + return true } let ids = NFTRetrieval.getNFTIDsFromCap(collectionIdentifier : key, collectionCap : collectionCap) @@ -465,7 +465,8 @@ pub fun main(ownerAddress: Address) : {String : [UInt64]} { if ids.length > 0 { items[key] = ids } - } + return true + }) return items } @@ -531,68 +532,71 @@ pub struct NFT { } pub fun main(ownerAddress: Address, collections: {String: [UInt64]}): {String: [NFT]} { - let catalog = NFTCatalog.getCatalog() let account = getAuthAccount(ownerAddress) let data: {String: [NFT]} = {} for collectionIdentifier in collections.keys { - if catalog.containsKey(collectionIdentifier) { - let value = catalog[collectionIdentifier]! - let keyHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(collectionIdentifier.utf8)) - let tempPathStr = "catalog".concat(keyHash) - let tempPublicPath = PublicPath(identifier: tempPathStr)! - - account.link<&{MetadataViews.ResolverCollection}>( - tempPublicPath, - target: value.collectionData.storagePath - ) + let catalogEntry = NFTCatalog.getCatalogEntry(collectionIdentifier: collectionIdentifier) + if catalogEntry == nil { + continue + } - let collectionCap = account.getCapability<&AnyResource{MetadataViews.ResolverCollection}>(tempPublicPath) + let value = catalogEntry! + let keyHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(collectionIdentifier.utf8)) + let tempPathStr = "catalog".concat(keyHash) + let tempPublicPath = PublicPath(identifier: tempPathStr)! - if !collectionCap.check() { - return data - } + account.link<&{MetadataViews.ResolverCollection}>( + tempPublicPath, + target: value.collectionData.storagePath + ) - let views = NFTRetrieval.getNFTViewsFromIDs(collectionIdentifier: collectionIdentifier, ids: collections[collectionIdentifier]!, collectionCap : collectionCap) - - let items: [NFT] = [] - - for view in views { - let displayView = view.display - let externalURLView = view.externalURL - let collectionDataView = view.collectionData - let collectionDisplayView = view.collectionDisplay - let royaltyView = view.royalties - - if (displayView == nil || externalURLView == nil || collectionDataView == nil || collectionDisplayView == nil || royaltyView == nil) { - // Bad NFT. Skipping.... - continue - } - - items.append( - NFT( - id: view.id, - name: displayView!.name, - description: displayView!.description, - thumbnail: displayView!.thumbnail.uri(), - externalURL: externalURLView!.url, - storagePath: collectionDataView!.storagePath, - publicPath: collectionDataView!.publicPath, - privatePath: collectionDataView!.providerPath, - publicLinkedType: collectionDataView!.publicLinkedType, - privateLinkedType: collectionDataView!.providerLinkedType, - collectionName: collectionDisplayView!.name, - collectionDescription: collectionDisplayView!.description, - collectionSquareImage: collectionDisplayView!.squareImage.file.uri(), - collectionBannerImage: collectionDisplayView!.bannerImage.file.uri(), - royalties: royaltyView!.getRoyalties() - ) - ) + let collectionCap = account.getCapability<&AnyResource{MetadataViews.ResolverCollection}>(tempPublicPath) + + if !collectionCap.check() { + return data + } + + let views = NFTRetrieval.getNFTViewsFromIDs(collectionIdentifier: collectionIdentifier, ids: collections[collectionIdentifier]!, collectionCap : collectionCap) + + let items: [NFT] = [] + + for view in views { + let displayView = view.display + let externalURLView = view.externalURL + let collectionDataView = view.collectionData + let collectionDisplayView = view.collectionDisplay + let royaltyView = view.royalties + + if (displayView == nil || externalURLView == nil || collectionDataView == nil || collectionDisplayView == nil || royaltyView == nil) { + // Bad NFT. Skipping.... + continue } - data[collectionIdentifier] = items + items.append( + NFT( + id: view.id, + name: displayView!.name, + description: displayView!.description, + thumbnail: displayView!.thumbnail.uri(), + externalURL: externalURLView!.url, + storagePath: collectionDataView!.storagePath, + publicPath: collectionDataView!.publicPath, + privatePath: collectionDataView!.providerPath, + publicLinkedType: collectionDataView!.publicLinkedType, + privateLinkedType: collectionDataView!.providerLinkedType, + collectionName: collectionDisplayView!.name, + collectionDescription: collectionDisplayView!.description, + collectionSquareImage: collectionDisplayView!.squareImage.file.uri(), + collectionBannerImage: collectionDisplayView!.bannerImage.file.uri(), + royalties: royaltyView!.getRoyalties() + ) + ) } + + data[collectionIdentifier] = items } + return data } @@ -630,13 +634,12 @@ pub struct NFTCollectionData { } pub fun main(ownerAddress: Address): {String: {String: AnyStruct}} { - let catalog = NFTCatalog.getCatalog() let account = getAuthAccount(ownerAddress) let items: [MetadataViews.NFTView] = [] let data: {String: {String: AnyStruct}} = {} - for key in catalog.keys { - let value = catalog[key]! + NFTCatalog.forEachCatalogKey(fun (key: String):Bool { + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: key) let keyHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(key.utf8)) let tempPathStr = "catalog".concat(keyHash) let tempPublicPath = PublicPath(identifier: tempPathStr)! @@ -649,13 +652,13 @@ pub fun main(ownerAddress: Address): {String: {String: AnyStruct}} { let collectionCap = account.getCapability<&AnyResource{MetadataViews.ResolverCollection}>(tempPublicPath) if !collectionCap.check() { - continue + return true } var views = NFTRetrieval.getAllMetadataViewsFromCap(collectionIdentifier: key, collectionCap: collectionCap) if views.keys.length == 0 { - continue + return true } // Cadence doesn't support function return types, lets manually get rid of it @@ -671,7 +674,9 @@ pub fun main(ownerAddress: Address): {String: {String: AnyStruct}} { views.insert(key: Type().identifier, collectionDataView) data[key] = views - } + + return true + }) return data } @@ -728,13 +733,9 @@ pub struct NFTCollection { } pub fun main(collectionIdentifier : String) : NFTCollection? { - let catalog = NFTCatalog.getCatalog() - - assert(catalog.containsKey(collectionIdentifier), message: "Invalid Collection") - - let contractView = catalog[collectionIdentifier]! - let collectionDataView = catalog[collectionIdentifier]!.collectionData - let collectionDisplayView = catalog[collectionIdentifier]!.collectionDisplay + let contractView = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: collectionIdentifier) + let collectionDataView = contractView.collectionData + let collectionDisplayView = contractView.collectionDisplay return NFTCollection( contractName: contractView.contractName, diff --git a/cadence/contracts/FlowToken.cdc b/cadence/contracts/FlowToken.cdc index 91ba60f..01fac94 100644 --- a/cadence/contracts/FlowToken.cdc +++ b/cadence/contracts/FlowToken.cdc @@ -197,4 +197,5 @@ pub contract FlowToken: FungibleToken { // Emit an event that shows that the contract was initialized emit TokensInitialized(initialSupply: self.totalSupply) } -} \ No newline at end of file +} + \ No newline at end of file diff --git a/cadence/contracts/NFTCatalog.cdc b/cadence/contracts/NFTCatalog.cdc index b9cecbd..a19d104 100644 --- a/cadence/contracts/NFTCatalog.cdc +++ b/cadence/contracts/NFTCatalog.cdc @@ -160,14 +160,22 @@ pub contract NFTCatalog { } } - pub fun getCatalog() : {String : NFTCatalogMetadata} { - return self.catalog + pub fun forEachCatalogKey(_ function: ((String): Bool)) { + self.catalog.forEachKey(function) } + pub fun getCatalogEntry(collectionIdentifier : String) : NFTCatalogMetadata? { return self.catalog[collectionIdentifier] } + pub fun mustGetCatalogEntry(collectionIdentifier : String) : NFTCatalogMetadata { + pre{ + self.catalog[collectionIdentifier] != nil : "Invalid collection identifier" + } + return self.catalog[collectionIdentifier]! + } + pub fun getCollectionsForType(nftTypeIdentifier: String) : {String : Bool}? { return self.catalogTypeData[nftTypeIdentifier] } diff --git a/cadence/contracts/NFTRetrieval.cdc b/cadence/contracts/NFTRetrieval.cdc index c25f199..dcf0388 100644 --- a/cadence/contracts/NFTRetrieval.cdc +++ b/cadence/contracts/NFTRetrieval.cdc @@ -25,11 +25,7 @@ pub contract NFTRetrieval { } pub fun getNFTIDsFromCap(collectionIdentifier: String, collectionCap : Capability<&AnyResource{MetadataViews.ResolverCollection}>) : [UInt64] { - pre { - NFTCatalog.getCatalog()[collectionIdentifier] != nil : "Invalid collection identifier" - } - let catalog = NFTCatalog.getCatalog() - let value = catalog[collectionIdentifier]! + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: collectionIdentifier) // Check if we have multiple collections for the NFT type... let hasMultipleCollections = self.hasMultipleCollections(nftTypeIdentifier : value.nftType.identifier) @@ -55,11 +51,8 @@ pub contract NFTRetrieval { } pub fun getNFTCountFromCap(collectionIdentifier: String, collectionCap : Capability<&AnyResource{MetadataViews.ResolverCollection}>) : UInt64 { - pre { - NFTCatalog.getCatalog()[collectionIdentifier] != nil : "Invalid collection identifier" - } - let catalog = NFTCatalog.getCatalog() - let value = catalog[collectionIdentifier]! + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: collectionIdentifier) + // Check if we have multiple collections for the NFT type... let hasMultipleCollections = self.hasMultipleCollections(nftTypeIdentifier : value.nftType.identifier) @@ -82,12 +75,8 @@ pub contract NFTRetrieval { } pub fun getAllMetadataViewsFromCap(collectionIdentifier: String, collectionCap : Capability<&AnyResource{MetadataViews.ResolverCollection}>) : {String: AnyStruct} { - pre { - NFTCatalog.getCatalog()[collectionIdentifier] != nil : "Invalid collection identifier" - } - let catalog = NFTCatalog.getCatalog() + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: collectionIdentifier) let items : {String: AnyStruct} = {} - let value = catalog[collectionIdentifier]! // Check if we have multiple collections for the NFT type... let hasMultipleCollections = self.hasMultipleCollections(nftTypeIdentifier : value.nftType.identifier) @@ -112,12 +101,8 @@ pub contract NFTRetrieval { } pub fun getNFTViewsFromCap(collectionIdentifier: String, collectionCap : Capability<&AnyResource{MetadataViews.ResolverCollection}>) : [MetadataViews.NFTView] { - pre { - NFTCatalog.getCatalog()[collectionIdentifier] != nil : "Invalid collection identifier" - } - let catalog = NFTCatalog.getCatalog() + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: collectionIdentifier) let items : [MetadataViews.NFTView] = [] - let value = catalog[collectionIdentifier]! // Check if we have multiple collections for the NFT type... let hasMultipleCollections = self.hasMultipleCollections(nftTypeIdentifier : value.nftType.identifier) @@ -140,13 +125,8 @@ pub contract NFTRetrieval { } pub fun getNFTViewsFromIDs(collectionIdentifier : String, ids: [UInt64], collectionCap : Capability<&AnyResource{MetadataViews.ResolverCollection}>) : [MetadataViews.NFTView] { - pre { - NFTCatalog.getCatalog()[collectionIdentifier] != nil : "Invalid collection identifier" - } - - let catalog = NFTCatalog.getCatalog() + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: collectionIdentifier) let items : [MetadataViews.NFTView] = [] - let value = catalog[collectionIdentifier]! // Check if we have multiple collections for the NFT type... let hasMultipleCollections = self.hasMultipleCollections(nftTypeIdentifier : value.nftType.identifier) diff --git a/cadence/contracts/TransactionGenerationUtils.cdc b/cadence/contracts/TransactionGenerationUtils.cdc index 0304541..b326457 100644 --- a/cadence/contracts/TransactionGenerationUtils.cdc +++ b/cadence/contracts/TransactionGenerationUtils.cdc @@ -170,11 +170,11 @@ pub contract TransactionGenerationUtils { } pub fun getNftSchema(collectionIdentifier: String): NFTSchema? { - let catalog = NFTCatalog.getCatalog() - if catalog[collectionIdentifier] == nil { + let catalogEntry = NFTCatalog.getCatalogEntry(collectionIdentifier: collectionIdentifier) + if catalogEntry== nil { return nil } - let catalogData = catalog[collectionIdentifier]! + let catalogData = catalogEntry! let publicLinkedType: Type = catalogData.collectionData.publicLinkedType let privateLinkedType: Type = catalogData.collectionData.privateLinkedType diff --git a/cadence/scripts/get_all_nfts_and_views_in_account.cdc b/cadence/scripts/get_all_nfts_and_views_in_account.cdc index f99a25b..176055f 100644 --- a/cadence/scripts/get_all_nfts_and_views_in_account.cdc +++ b/cadence/scripts/get_all_nfts_and_views_in_account.cdc @@ -25,14 +25,14 @@ pub struct NFTCollectionData { } pub fun main(ownerAddress: Address): {String: {String: AnyStruct}} { - let catalog = NFTCatalog.getCatalog() let account = getAuthAccount(ownerAddress) let items: [MetadataViews.NFTView] = [] let data: {String: {String: AnyStruct}} = {} - for key in catalog.keys { - let value = catalog[key]! - let keyHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(key.utf8)) + NFTCatalog.forEachCatalogKey(fun (collectionIdentifier: String):Bool { + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: collectionIdentifier) + + let keyHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(collectionIdentifier.utf8)) let tempPathStr = "catalog".concat(keyHash) let tempPublicPath = PublicPath(identifier: tempPathStr)! @@ -44,13 +44,13 @@ pub fun main(ownerAddress: Address): {String: {String: AnyStruct}} { let collectionCap = account.getCapability<&AnyResource{MetadataViews.ResolverCollection}>(tempPublicPath) if !collectionCap.check() { - continue + return true } - var views = NFTRetrieval.getAllMetadataViewsFromCap(collectionIdentifier: key, collectionCap: collectionCap) + var views = NFTRetrieval.getAllMetadataViewsFromCap(collectionIdentifier: collectionIdentifier, collectionCap: collectionCap) if views.keys.length == 0 { - continue + return true } // Cadence doesn't support function return types, lets manually get rid of it @@ -64,8 +64,10 @@ pub fun main(ownerAddress: Address): {String: {String: AnyStruct}} { ) views.insert(key: Type().identifier, collectionDataView) - data[key] = views - } + data[collectionIdentifier] = views + + return true + }) return data } diff --git a/cadence/scripts/get_all_nfts_in_account.cdc b/cadence/scripts/get_all_nfts_in_account.cdc index 89f0d5a..e286296 100644 --- a/cadence/scripts/get_all_nfts_in_account.cdc +++ b/cadence/scripts/get_all_nfts_in_account.cdc @@ -58,14 +58,13 @@ pub struct NFT { } pub fun main(ownerAddress: Address): {String: [NFT]} { - let catalog = NFTCatalog.getCatalog() let account = getAuthAccount(ownerAddress) let items: [MetadataViews.NFTView] = [] let data: {String: [NFT]} = {} - for key in catalog.keys { - let value = catalog[key]! - let keyHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(key.utf8)) + NFTCatalog.forEachCatalogKey(fun (collectionIdentifier: String):Bool { + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: collectionIdentifier) + let keyHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(collectionIdentifier.utf8)) let tempPathStr = "catalog".concat(keyHash) let tempPublicPath = PublicPath(identifier: tempPathStr)! @@ -77,10 +76,10 @@ pub fun main(ownerAddress: Address): {String: [NFT]} { let collectionCap = account.getCapability<&AnyResource{MetadataViews.ResolverCollection}>(tempPublicPath) if !collectionCap.check() { - continue + return true } - let views = NFTRetrieval.getNFTViewsFromCap(collectionIdentifier: key, collectionCap: collectionCap) + let views = NFTRetrieval.getNFTViewsFromCap(collectionIdentifier: collectionIdentifier, collectionCap: collectionCap) let items: [NFT] = [] for view in views { @@ -92,7 +91,7 @@ pub fun main(ownerAddress: Address): {String: [NFT]} { if (displayView == nil || externalURLView == nil || collectionDataView == nil || collectionDisplayView == nil || royaltyView == nil) { // Bad NFT. Skipping.... - continue + return true } items.append( @@ -117,8 +116,9 @@ pub fun main(ownerAddress: Address): {String: [NFT]} { ) } - data[key] = items - } + data[collectionIdentifier] = items + return true + }) return data } diff --git a/cadence/scripts/get_nft_and_views_in_account.cdc b/cadence/scripts/get_nft_and_views_in_account.cdc index 237f404..86ff712 100644 --- a/cadence/scripts/get_nft_and_views_in_account.cdc +++ b/cadence/scripts/get_nft_and_views_in_account.cdc @@ -83,13 +83,8 @@ pub struct NFT { } pub fun getAllMetadataViewsFromCap(tokenID: UInt64, collectionIdentifier: String, collectionCap: Capability<&AnyResource{MetadataViews.ResolverCollection}>): {String: AnyStruct} { - pre { - NFTCatalog.getCatalog()[collectionIdentifier] != nil : "Invalid collection identifier" - } - - let catalog = NFTCatalog.getCatalog() let items: {String: AnyStruct} = {} - let value = catalog[collectionIdentifier]! + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: collectionIdentifier) // Check if we have multiple collections for the NFT type... let hasMultipleCollections = false @@ -109,20 +104,15 @@ pub struct NFT { } } } - } return items } pub fun main(ownerAddress: Address, collectionIdentifier: String, tokenID: UInt64) : NFT? { - let catalog = NFTCatalog.getCatalog() - - assert(catalog.containsKey(collectionIdentifier), message: "Invalid Collection") - let account = getAuthAccount(ownerAddress) - let value = catalog[collectionIdentifier]! + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: collectionIdentifier) let identifierHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(collectionIdentifier.utf8)) let tempPathStr = "catalog".concat(identifierHash) let tempPublicPath = PublicPath(identifier: tempPathStr)! @@ -137,7 +127,7 @@ pub fun main(ownerAddress: Address, collectionIdentifier: String, tokenID: UInt6 let allViews = getAllMetadataViewsFromCap(tokenID: tokenID, collectionIdentifier: collectionIdentifier, collectionCap: collectionCap) let nftCollectionDisplayView = allViews[Type().identifier] as! MetadataViews.NFTCollectionData? - let collectionDataView = NFTCollectionData( + let colDataView = NFTCollectionData( storagePath: nftCollectionDisplayView!.storagePath, publicPath: nftCollectionDisplayView!.publicPath, privatePath: nftCollectionDisplayView!.providerPath, @@ -145,44 +135,43 @@ pub fun main(ownerAddress: Address, collectionIdentifier: String, tokenID: UInt6 privateLinkedType: nftCollectionDisplayView!.providerLinkedType, ) - allViews.insert(key: Type().identifier, collectionDataView) + allViews.insert(key: Type().identifier, colDataView) - let views = NFTRetrieval.getNFTViewsFromCap(collectionIdentifier: collectionIdentifier, collectionCap: collectionCap) + let views = NFTRetrieval.getNFTViewsFromIDs(collectionIdentifier: collectionIdentifier, ids: [tokenID], collectionCap: collectionCap) - for view in views { - if view.id == tokenID { - let displayView = view.display - let externalURLView = view.externalURL - let collectionDataView = view.collectionData - let collectionDisplayView = view.collectionDisplay - let royaltyView = view.royalties + if views.length == 0 { + panic("Invalid Token ID") + } - if (displayView == nil || externalURLView == nil || collectionDataView == nil || collectionDisplayView == nil || royaltyView == nil) { - // Bad NFT. Skipping.... - return nil - } + let view = views[0] + let displayView = view.display + let externalURLView = view.externalURL + let collectionDataView = view.collectionData + let collectionDisplayView = view.collectionDisplay + let royaltyView = view.royalties - return NFT( - id: view.id, - name: displayView!.name, - description: displayView!.description, - thumbnail: displayView!.thumbnail.uri(), - externalURL: externalURLView!.url, - storagePath: collectionDataView!.storagePath, - publicPath: collectionDataView!.publicPath, - privatePath: collectionDataView!.providerPath, - publicLinkedType: collectionDataView!.publicLinkedType, - privateLinkedType: collectionDataView!.providerLinkedType, - collectionName: collectionDisplayView!.name, - collectionDescription: collectionDisplayView!.description, - collectionSquareImage: collectionDisplayView!.squareImage.file.uri(), - collectionBannerImage: collectionDisplayView!.bannerImage.file.uri(), - collectionExternalURL: collectionDisplayView!.externalURL.url, - allViews: allViews, - royalties: royaltyView!.getRoyalties() - ) - } + if (displayView == nil || externalURLView == nil || collectionDataView == nil || collectionDisplayView == nil || royaltyView == nil) { + // Bad NFT. + return nil } - panic("Invalid Token ID") + return NFT( + id: view.id, + name: displayView!.name, + description: displayView!.description, + thumbnail: displayView!.thumbnail.uri(), + externalURL: externalURLView!.url, + storagePath: collectionDataView!.storagePath, + publicPath: collectionDataView!.publicPath, + privatePath: collectionDataView!.providerPath, + publicLinkedType: collectionDataView!.publicLinkedType, + privateLinkedType: collectionDataView!.providerLinkedType, + collectionName: collectionDisplayView!.name, + collectionDescription: collectionDisplayView!.description, + collectionSquareImage: collectionDisplayView!.squareImage.file.uri(), + collectionBannerImage: collectionDisplayView!.bannerImage.file.uri(), + collectionExternalURL: collectionDisplayView!.externalURL.url, + allViews: allViews, + royalties: royaltyView!.getRoyalties() + ) } diff --git a/cadence/scripts/get_nft_catalog.cdc b/cadence/scripts/get_nft_catalog.cdc index d7755c2..6f45001 100644 --- a/cadence/scripts/get_nft_catalog.cdc +++ b/cadence/scripts/get_nft_catalog.cdc @@ -1,17 +1,17 @@ import NFTCatalog from "../contracts/NFTCatalog.cdc" pub fun main(batch : [UInt64]?): {String : NFTCatalog.NFTCatalogMetadata} { - if batch == nil { - return NFTCatalog.getCatalog() - } - let catalog = NFTCatalog.getCatalog() - let catalogIDs = catalog.keys var data : {String : NFTCatalog.NFTCatalogMetadata} = {} - var i = batch![0] - while i < batch![1] { - data.insert(key: catalogIDs[i], catalog[catalogIDs[i]]!) - i = i + 1 - } + // if batch == nil { + // return NFTCatalog.getCatalog() + // } + // let catalog = NFTCatalog.getCatalog() + // let catalogIDs = catalog.keys // <- key order is not guaranteed how does this work? + // var i = batch![0] + // while i < batch![1] { + // data.insert(key: catalogIDs[i], catalog[catalogIDs[i]]!) + // i = i + 1 + // } return data } \ No newline at end of file diff --git a/cadence/scripts/get_nft_catalog_count.cdc b/cadence/scripts/get_nft_catalog_count.cdc index 996a34c..fbd3547 100644 --- a/cadence/scripts/get_nft_catalog_count.cdc +++ b/cadence/scripts/get_nft_catalog_count.cdc @@ -1,7 +1,10 @@ import NFTCatalog from "../contracts/NFTCatalog.cdc" pub fun main(): Int { - let catalog = NFTCatalog.getCatalog() - let catalogIDs = catalog.keys - return catalogIDs.length + var count: Int = 0 + let catalog = NFTCatalog.forEachCatalogKey(fun (key: String): Bool { + count = count + 1 + return true + }) + return count } \ No newline at end of file diff --git a/cadence/scripts/get_nft_ids_in_account.cdc b/cadence/scripts/get_nft_ids_in_account.cdc index 88fe46d..227d789 100644 --- a/cadence/scripts/get_nft_ids_in_account.cdc +++ b/cadence/scripts/get_nft_ids_in_account.cdc @@ -3,12 +3,11 @@ import NFTCatalog from "../contracts/NFTCatalog.cdc" import NFTRetrieval from "../contracts/NFTRetrieval.cdc" pub fun main(ownerAddress: Address): {String: [UInt64]} { - let catalog = NFTCatalog.getCatalog() let account = getAuthAccount(ownerAddress) let items: {String: [UInt64]} = {} - for key in catalog.keys { - let value = catalog[key]! + NFTCatalog.forEachCatalogKey(fun (key: String):Bool { + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: key) let keyHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(key.utf8)) let tempPathStr = "catalogIDs".concat(keyHash) let tempPublicPath = PublicPath(identifier: tempPathStr)! @@ -21,7 +20,7 @@ pub fun main(ownerAddress: Address): {String: [UInt64]} { let collectionCap = account.getCapability<&AnyResource{MetadataViews.ResolverCollection}>(tempPublicPath) if !collectionCap.check() { - continue + return true } let ids = NFTRetrieval.getNFTIDsFromCap(collectionIdentifier: key, collectionCap: collectionCap) @@ -29,7 +28,8 @@ pub fun main(ownerAddress: Address): {String: [UInt64]} { if ids.length > 0 { items[key] = ids } - } + return true + }) return items } diff --git a/cadence/scripts/get_nft_in_account.cdc b/cadence/scripts/get_nft_in_account.cdc index 86c3149..5c041db 100644 --- a/cadence/scripts/get_nft_in_account.cdc +++ b/cadence/scripts/get_nft_in_account.cdc @@ -58,13 +58,9 @@ pub struct NFT { } pub fun main(ownerAddress: Address, collectionIdentifier: String, tokenID: UInt64): NFT? { - let catalog = NFTCatalog.getCatalog() - - assert(catalog.containsKey(collectionIdentifier), message: "Invalid Collection") - let account = getAuthAccount(ownerAddress) - let value = catalog[collectionIdentifier]! + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: collectionIdentifier)! let identifierHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(collectionIdentifier.utf8)) let tempPathStr = "catalog".concat(identifierHash) let tempPublicPath = PublicPath(identifier: tempPathStr)! @@ -79,39 +75,39 @@ pub fun main(ownerAddress: Address, collectionIdentifier: String, tokenID: UInt6 let views = NFTRetrieval.getNFTViewsFromIDs(collectionIdentifier : collectionIdentifier, ids: [tokenID], collectionCap : collectionCap) - for view in views { - if view.id == tokenID { - let displayView = view.display - let externalURLView = view.externalURL - let collectionDataView = view.collectionData - let collectionDisplayView = view.collectionDisplay - let royaltyView = view.royalties + if views.length == 0 { + panic("Invalid Token ID") + } - if (displayView == nil || externalURLView == nil || collectionDataView == nil || collectionDisplayView == nil || royaltyView == nil) { - // Bad NFT. Skipping.... - return nil - } + let view = views[0] - return NFT( - id: view.id, - name: displayView!.name, - description: displayView!.description, - thumbnail: displayView!.thumbnail.uri(), - externalURL: externalURLView!.url, - storagePath: collectionDataView!.storagePath, - publicPath: collectionDataView!.publicPath, - privatePath: collectionDataView!.providerPath, - publicLinkedType: collectionDataView!.publicLinkedType, - privateLinkedType: collectionDataView!.providerLinkedType, - collectionName: collectionDisplayView!.name, - collectionDescription: collectionDisplayView!.description, - collectionSquareImage: collectionDisplayView!.squareImage.file.uri(), - collectionBannerImage: collectionDisplayView!.bannerImage.file.uri(), - collectionExternalURL: collectionDisplayView!.externalURL.url, - royalties: royaltyView!.getRoyalties() - ) - } + let displayView = view.display + let externalURLView = view.externalURL + let collectionDataView = view.collectionData + let collectionDisplayView = view.collectionDisplay + let royaltyView = view.royalties + + if (displayView == nil || externalURLView == nil || collectionDataView == nil || collectionDisplayView == nil || royaltyView == nil) { + // Bad NFT. Skipping.... + return nil } - panic("Invalid Token ID") + return NFT( + id: view.id, + name: displayView!.name, + description: displayView!.description, + thumbnail: displayView!.thumbnail.uri(), + externalURL: externalURLView!.url, + storagePath: collectionDataView!.storagePath, + publicPath: collectionDataView!.publicPath, + privatePath: collectionDataView!.providerPath, + publicLinkedType: collectionDataView!.publicLinkedType, + privateLinkedType: collectionDataView!.providerLinkedType, + collectionName: collectionDisplayView!.name, + collectionDescription: collectionDisplayView!.description, + collectionSquareImage: collectionDisplayView!.squareImage.file.uri(), + collectionBannerImage: collectionDisplayView!.bannerImage.file.uri(), + collectionExternalURL: collectionDisplayView!.externalURL.url, + royalties: royaltyView!.getRoyalties() + ) } diff --git a/cadence/scripts/get_nfts_count_in_account.cdc b/cadence/scripts/get_nfts_count_in_account.cdc index 7e7a3bb..7a2776e 100644 --- a/cadence/scripts/get_nfts_count_in_account.cdc +++ b/cadence/scripts/get_nfts_count_in_account.cdc @@ -3,12 +3,11 @@ import NFTCatalog from "../contracts/NFTCatalog.cdc" import NFTRetrieval from "../contracts/NFTRetrieval.cdc" pub fun main(ownerAddress: Address): {String: Number} { - let catalog = NFTCatalog.getCatalog() let account = getAuthAccount(ownerAddress) let items: {String: Number} = {} - for key in catalog.keys { - let value = catalog[key]! + NFTCatalog.forEachCatalogKey(fun (key: String): Bool { + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: key) let keyHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(key.utf8)) let tempPathStr = "catalog".concat(keyHash) let tempPublicPath = PublicPath(identifier: tempPathStr)! @@ -21,7 +20,7 @@ pub fun main(ownerAddress: Address): {String: Number} { let collectionCap = account.getCapability<&AnyResource{MetadataViews.ResolverCollection}>(tempPublicPath) if !collectionCap.check() { - continue + return true } let count = NFTRetrieval.getNFTCountFromCap(collectionIdentifier: key, collectionCap: collectionCap) @@ -29,7 +28,8 @@ pub fun main(ownerAddress: Address): {String: Number} { if count != 0 { items[key] = count } - } + return true + }) return items } diff --git a/cadence/scripts/get_nfts_in_account.cdc b/cadence/scripts/get_nfts_in_account.cdc index 51e0cfb..68e7ee5 100644 --- a/cadence/scripts/get_nfts_in_account.cdc +++ b/cadence/scripts/get_nfts_in_account.cdc @@ -58,67 +58,70 @@ pub struct NFT { } pub fun main(ownerAddress: Address, collectionIdentifiers: [String]): {String: [NFT]} { - let catalog = NFTCatalog.getCatalog() let account = getAuthAccount(ownerAddress) let data: {String: [NFT]} = {} for collectionIdentifier in collectionIdentifiers { - if catalog.containsKey(collectionIdentifier) { - let value = catalog[collectionIdentifier]! - let identifierHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(collectionIdentifier.utf8)) - let tempPathStr = "catalog".concat(identifierHash) - let tempPublicPath = PublicPath(identifier: tempPathStr)! + let catalogEntry = NFTCatalog.getCatalogEntry(collectionIdentifier: collectionIdentifier) + if catalogEntry == nil { + continue + } - account.link<&{MetadataViews.ResolverCollection}>( - tempPublicPath, - target: value.collectionData.storagePath - ) + let value = catalogEntry! + let identifierHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(collectionIdentifier.utf8)) + let tempPathStr = "catalog".concat(identifierHash) + let tempPublicPath = PublicPath(identifier: tempPathStr)! - let collectionCap = account.getCapability<&AnyResource{MetadataViews.ResolverCollection}>(tempPublicPath) + account.link<&{MetadataViews.ResolverCollection}>( + tempPublicPath, + target: value.collectionData.storagePath + ) - if !collectionCap.check() { - continue - } + let collectionCap = account.getCapability<&AnyResource{MetadataViews.ResolverCollection}>(tempPublicPath) - let views = NFTRetrieval.getNFTViewsFromCap(collectionIdentifier: collectionIdentifier, collectionCap: collectionCap) + if !collectionCap.check() { + continue + } - let items: [NFT] = [] - for view in views { - let displayView = view.display - let externalURLView = view.externalURL - let collectionDataView = view.collectionData - let collectionDisplayView = view.collectionDisplay - let royaltyView = view.royalties + let views = NFTRetrieval.getNFTViewsFromCap(collectionIdentifier: collectionIdentifier, collectionCap: collectionCap) - if (displayView == nil || externalURLView == nil || collectionDataView == nil || collectionDisplayView == nil || royaltyView == nil) { - // Bad NFT. Skipping.... - continue - } + let items: [NFT] = [] + for view in views { + let displayView = view.display + let externalURLView = view.externalURL + let collectionDataView = view.collectionData + let collectionDisplayView = view.collectionDisplay + let royaltyView = view.royalties - items.append( - NFT( - id: view.id, - name: displayView!.name, - description: displayView!.description, - thumbnail: displayView!.thumbnail.uri(), - externalURL: externalURLView!.url, - storagePath: collectionDataView!.storagePath, - publicPath: collectionDataView!.publicPath, - privatePath: collectionDataView!.providerPath, - publicLinkedType: collectionDataView!.publicLinkedType, - privateLinkedType: collectionDataView!.providerLinkedType, - collectionName: collectionDisplayView!.name, - collectionDescription: collectionDisplayView!.description, - collectionSquareImage: collectionDisplayView!.squareImage.file.uri(), - collectionBannerImage: collectionDisplayView!.bannerImage.file.uri(), - collectionExternalURL: collectionDisplayView!.externalURL.url, - royalties: royaltyView!.getRoyalties() - ) - ) + if (displayView == nil || externalURLView == nil || collectionDataView == nil || collectionDisplayView == nil || royaltyView == nil) { + // Bad NFT. Skipping.... + continue } - data[collectionIdentifier] = items + items.append( + NFT( + id: view.id, + name: displayView!.name, + description: displayView!.description, + thumbnail: displayView!.thumbnail.uri(), + externalURL: externalURLView!.url, + storagePath: collectionDataView!.storagePath, + publicPath: collectionDataView!.publicPath, + privatePath: collectionDataView!.providerPath, + publicLinkedType: collectionDataView!.publicLinkedType, + privateLinkedType: collectionDataView!.providerLinkedType, + collectionName: collectionDisplayView!.name, + collectionDescription: collectionDisplayView!.description, + collectionSquareImage: collectionDisplayView!.squareImage.file.uri(), + collectionBannerImage: collectionDisplayView!.bannerImage.file.uri(), + collectionExternalURL: collectionDisplayView!.externalURL.url, + royalties: royaltyView!.getRoyalties() + ) + ) } + + data[collectionIdentifier] = items + } return data diff --git a/cadence/scripts/get_nfts_in_account_from_ids.cdc b/cadence/scripts/get_nfts_in_account_from_ids.cdc index 1ebd9f5..8635cde 100644 --- a/cadence/scripts/get_nfts_in_account_from_ids.cdc +++ b/cadence/scripts/get_nfts_in_account_from_ids.cdc @@ -59,67 +59,69 @@ pub struct NFT { pub fun main(ownerAddress: Address, collections: {String: [UInt64]}): {String: [NFT]} { let data: {String: [NFT]} = {} - let catalog = NFTCatalog.getCatalog() let account = getAuthAccount(ownerAddress) for collectionIdentifier in collections.keys { - if catalog.containsKey(collectionIdentifier) { - let value = catalog[collectionIdentifier]! - let identifierHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(collectionIdentifier.utf8)) - let tempPathStr = "catalog".concat(identifierHash) - let tempPublicPath = PublicPath(identifier: tempPathStr)! + let catalogEntry = NFTCatalog.getCatalogEntry(collectionIdentifier: collectionIdentifier) + if catalogEntry == nil { + continue + } - account.link<&{MetadataViews.ResolverCollection}>( - tempPublicPath, - target: value.collectionData.storagePath - ) + let value = catalogEntry! + let identifierHash = String.encodeHex(HashAlgorithm.SHA3_256.hash(collectionIdentifier.utf8)) + let tempPathStr = "catalog".concat(identifierHash) + let tempPublicPath = PublicPath(identifier: tempPathStr)! - let collectionCap = account.getCapability<&AnyResource{MetadataViews.ResolverCollection}>(tempPublicPath) + account.link<&{MetadataViews.ResolverCollection}>( + tempPublicPath, + target: value.collectionData.storagePath + ) - if !collectionCap.check() { - return data - } + let collectionCap = account.getCapability<&AnyResource{MetadataViews.ResolverCollection}>(tempPublicPath) - let views = NFTRetrieval.getNFTViewsFromIDs(collectionIdentifier: collectionIdentifier, ids: collections[collectionIdentifier]!, collectionCap: collectionCap) + if !collectionCap.check() { + return data + } - let items: [NFT] = [] + let views = NFTRetrieval.getNFTViewsFromIDs(collectionIdentifier: collectionIdentifier, ids: collections[collectionIdentifier]!, collectionCap: collectionCap) - for view in views { - let displayView = view.display - let externalURLView = view.externalURL - let collectionDataView = view.collectionData - let collectionDisplayView = view.collectionDisplay - let royaltyView = view.royalties + let items: [NFT] = [] - if (displayView == nil || externalURLView == nil || collectionDataView == nil || collectionDisplayView == nil || royaltyView == nil) { - // Bad NFT. Skipping.... - continue - } + for view in views { + let displayView = view.display + let externalURLView = view.externalURL + let collectionDataView = view.collectionData + let collectionDisplayView = view.collectionDisplay + let royaltyView = view.royalties - items.append( - NFT( - id: view.id, - name: displayView!.name, - description: displayView!.description, - thumbnail: displayView!.thumbnail.uri(), - externalURL: externalURLView!.url, - storagePath: collectionDataView!.storagePath, - publicPath: collectionDataView!.publicPath, - privatePath: collectionDataView!.providerPath, - publicLinkedType: collectionDataView!.publicLinkedType, - privateLinkedType: collectionDataView!.providerLinkedType, - collectionName: collectionDisplayView!.name, - collectionDescription: collectionDisplayView!.description, - collectionSquareImage: collectionDisplayView!.squareImage.file.uri(), - collectionBannerImage: collectionDisplayView!.bannerImage.file.uri(), - collectionExternalURL: collectionDisplayView!.externalURL.url, - royalties: royaltyView!.getRoyalties() - ) - ) + if (displayView == nil || externalURLView == nil || collectionDataView == nil || collectionDisplayView == nil || royaltyView == nil) { + // Bad NFT. Skipping.... + continue } - data[collectionIdentifier] = items + items.append( + NFT( + id: view.id, + name: displayView!.name, + description: displayView!.description, + thumbnail: displayView!.thumbnail.uri(), + externalURL: externalURLView!.url, + storagePath: collectionDataView!.storagePath, + publicPath: collectionDataView!.publicPath, + privatePath: collectionDataView!.providerPath, + publicLinkedType: collectionDataView!.publicLinkedType, + privateLinkedType: collectionDataView!.providerLinkedType, + collectionName: collectionDisplayView!.name, + collectionDescription: collectionDisplayView!.description, + collectionSquareImage: collectionDisplayView!.squareImage.file.uri(), + collectionBannerImage: collectionDisplayView!.bannerImage.file.uri(), + collectionExternalURL: collectionDisplayView!.externalURL.url, + royalties: royaltyView!.getRoyalties() + ) + ) } + + data[collectionIdentifier] = items } return data diff --git a/flow.json b/flow.json index 3d3d867..c5e3147 100644 --- a/flow.json +++ b/flow.json @@ -84,55 +84,6 @@ "emulator-account": { "address": "0xf8d6e0586b0a20c7", "key": "ff735bbeae75401fbd8cd05c0b5f154038642bc226103eddc987c7e35bacb96d" - }, - "catalog-testnet-account": { - "address": "0x324c34e1c517e4db", - "key": "$CATALOG_TESTNET_ACCOUNT_PRIVATE_KEY" - }, - "transaction-generation-testnet-account": { - "address": "0x44051d81c4720882", - "key": "$CATALOG_TESTNET_ACCOUNT_PRIVATE_KEY" - }, - "examplenft-testnet-account": { - "address": "0xa60cf32e8369f919", - "key": "ff735bbeae75401fbd8cd05c0b5f154038642bc226103eddc987c7e35bacb96d" - }, - "examplenft-testnet-holder-account": { - "address": "0x5f151d59c7128d8e", - "key": "ff735bbeae75401fbd8cd05c0b5f154038642bc226103eddc987c7e35bacb96d" - }, - "mainnet-nft-catalog-account": { - "address": "0x49a7cda3a1eecc29", - "key": { - "type": "google-kms", - "index": 0, - "signatureAlgorithm": "ECDSA_P256", - "hashAlgorithm": "SHA2_256", - "resourceID": "projects/dl-flow-admin/locations/global/keyRings/nft-metadata/cryptoKeys/nft-catalog/cryptoKeyVersions/1" - }, - "chain": "flow-mainnet" - }, - "mainnet-transaction-generation-account": { - "address": "0xe52522745adf5c34", - "key": { - "type": "google-kms", - "index": 0, - "signatureAlgorithm": "ECDSA_P256", - "hashAlgorithm": "SHA2_256", - "resourceID": "projects/dl-flow-admin/locations/global/keyRings/nft-metadata/cryptoKeys/nft-catalog-admin/cryptoKeyVersions/1" - }, - "chain": "flow-mainnet" - }, - "mainnet-nft-catalog-admin-account": { - "address": "0xf589fc579a72e43d", - "key": { - "type": "google-kms", - "index": 0, - "signatureAlgorithm": "ECDSA_P256", - "hashAlgorithm": "SHA2_256", - "resourceID": "projects/dl-flow-admin/locations/global/keyRings/nft-metadata/cryptoKeys/nft-catalog-admin/cryptoKeyVersions/1" - }, - "chain": "flow-mainnet" } }, "deployments": { @@ -155,34 +106,6 @@ "TransactionTemplates", "TransactionGeneration" ] - }, - "testnet": { - "catalog-testnet-account": [ - "NFTCatalog", - "NFTCatalogAdmin", - "NFTRetrieval" - ], - "transaction-generation-testnet-account": [ - "ArrayUtils", - "StringUtils", - "TransactionGenerationUtils", - "TransactionTemplates", - "TransactionGeneration" - ] - }, - "mainnet": { - "mainnet-nft-catalog-account": [ - "NFTCatalog", - "NFTCatalogAdmin", - "NFTRetrieval" - ], - "mainnet-transaction-generation-account": [ - "ArrayUtils", - "StringUtils", - "TransactionGenerationUtils", - "TransactionTemplates", - "TransactionGeneration" - ] } } } diff --git a/ui/test.cdc b/ui/test.cdc index 9b00d1c..c8eaa5c 100644 --- a/ui/test.cdc +++ b/ui/test.cdc @@ -54,13 +54,12 @@ pub struct NFT { } pub fun main(ownerAddress: Address) : { String : [NFT] } { - let catalog = NFTCatalog.getCatalog() let account = getAuthAccount(ownerAddress) let data : {String : [NFT] } = {} - for key in catalog.keys { - let value = catalog[key]! + NFTCatalog.forEachCatalogKey(fun (key: String): Bool { + let value = NFTCatalog.mustGetCatalogEntry(collectionIdentifier: key) let tempPathStr = "catalog".concat(key) let tempPublicPath = PublicPath(identifier: tempPathStr)! account.link<&{MetadataViews.ResolverCollection}>( @@ -80,7 +79,7 @@ pub fun main(ownerAddress: Address) : { String : [NFT] } { let royaltyView = view.royalties if (displayView == nil || externalURLView == nil || collectionDataView == nil || collectionDisplayView == nil || royaltyView == nil) { // Bad NFT. Skipping.... - continue + return true } items.append( @@ -104,6 +103,7 @@ pub fun main(ownerAddress: Address) : { String : [NFT] } { ) } data[key] = items - } + return true + }) return data } \ No newline at end of file