From 42072360aa818c09e260828b87d31756c33b909f Mon Sep 17 00:00:00 2001 From: Giovanni Sanchez <108043524+sisyphusSmiling@users.noreply.github.com> Date: Mon, 30 Sep 2024 15:52:56 -0600 Subject: [PATCH] update deprecated Cadence --- cadence/scripts/check_for_links.cdc | 6 +++--- cadence/scripts/get_examplenft_type.cdc | 9 +-------- cadence/transactions/add_to_nft_catalog.cdc | 5 ++++- cadence/transactions/update_nft_catalog_entry.cdc | 6 ++++-- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/cadence/scripts/check_for_links.cdc b/cadence/scripts/check_for_links.cdc index 397acb8..d996266 100644 --- a/cadence/scripts/check_for_links.cdc +++ b/cadence/scripts/check_for_links.cdc @@ -1,4 +1,4 @@ -import "MetadataViews" +import "ViewResolver" /* Script to check for the implementation of all recommended MetadataViews. @@ -6,7 +6,7 @@ import "MetadataViews" access(all) fun main(ownerAddress: Address, collectionPublicPath: String): {String: Bool} { let owner = getAccount(ownerAddress) return { - "MetadataViews": owner.getCapability<&AnyResource{MetadataViews.ResolverCollection}>(PublicPath(identifier: collectionPublicPath)!).check(), - "AnyResource": owner.getCapability<&AnyResource>(PublicPath(identifier: collectionPublicPath)!).check() + "MetadataViews": owner.capabilities.get<&{ViewResolver.ResolverCollection}>(PublicPath(identifier: collectionPublicPath)!).check(), + "AnyResource": owner.capabilities.get<&AnyResource>(PublicPath(identifier: collectionPublicPath)!).check() } } \ No newline at end of file diff --git a/cadence/scripts/get_examplenft_type.cdc b/cadence/scripts/get_examplenft_type.cdc index fe05f43..c5aaffa 100644 --- a/cadence/scripts/get_examplenft_type.cdc +++ b/cadence/scripts/get_examplenft_type.cdc @@ -2,12 +2,5 @@ import "NonFungibleToken" import "ExampleNFT" access(all) fun main(): String { - let x = ReferenceType(entitlements: ["A.f8d6e0586b0a20c7.NonFungibleToken.Withdraw"], type: CompositeType(Type<@ExampleNFT.Collection>().identifier)!) - let y = ReferenceType(entitlements: [], type: CompositeType(Type<@ExampleNFT.Collection>().identifier)!) - //let y = CompositeType("A.f8d6e0586b0a20c7.ExampleNFT.Collection") - //return y!.identifier - //return x!.identifier - return Type<&ExampleNFT.NFT>().identifier - - + return Type<@ExampleNFT.NFT>().identifier } \ No newline at end of file diff --git a/cadence/transactions/add_to_nft_catalog.cdc b/cadence/transactions/add_to_nft_catalog.cdc index 58b4880..2b0ad17 100644 --- a/cadence/transactions/add_to_nft_catalog.cdc +++ b/cadence/transactions/add_to_nft_catalog.cdc @@ -13,8 +13,11 @@ transaction( publicPathIdentifier: String ) { let adminProxyRef : auth(NFTCatalogAdmin.CatalogActions) &NFTCatalogAdmin.AdminProxy + let nftType: Type prepare(acct: auth(BorrowValue) &Account) { + self.nftType = CompositeType(nftTypeIdentifer) + ?? panic("Could not construct NFT type from identifier ".concat(nftTypeIdentifer)) self.adminProxyRef = acct.storage.borrow(from: NFTCatalogAdmin.AdminProxyStoragePath)! } @@ -38,7 +41,7 @@ transaction( let catalogData = NFTCatalog.NFTCatalogMetadata( contractName: contractName, contractAddress: contractAddress, - nftType: CompositeType(nftTypeIdentifer)!, + nftType: self.nftType, collectionData: collectionData, collectionDisplay : collectionDisplay ) diff --git a/cadence/transactions/update_nft_catalog_entry.cdc b/cadence/transactions/update_nft_catalog_entry.cdc index fd2f0ef..4bf2c05 100644 --- a/cadence/transactions/update_nft_catalog_entry.cdc +++ b/cadence/transactions/update_nft_catalog_entry.cdc @@ -1,3 +1,4 @@ +import "ViewResolver" import "MetadataViews" import "NFTCatalog" import "NFTCatalogAdmin" @@ -13,18 +14,19 @@ transaction( let adminProxyRef : auth(NFTCatalogAdmin.CatalogActions) &NFTCatalogAdmin.AdminProxy prepare(acct: auth(BorrowValue) &Account) { - self.adminProxyRef = acct.borrow(from : NFTCatalogAdmin.AdminProxyStoragePath)! + self.adminProxyRef = acct.storage.borrow(from : NFTCatalogAdmin.AdminProxyStoragePath)! } execute { let nftAccount = getAccount(addressWithNFT) let pubPath = PublicPath(identifier: publicPathIdentifier)! - let collectionCap = nftAccount.getCapability<&AnyResource{MetadataViews.ResolverCollection}>(pubPath) + let collectionCap = nftAccount.capabilities.get<&{ViewResolver.ResolverCollection}>(pubPath) assert(collectionCap.check(), message: "MetadataViews Collection is not set up properly, ensure the Capability was created/linked correctly.") let collectionRef = collectionCap.borrow()! assert(collectionRef.getIDs().length > 0, message: "No NFTs exist in this collection, ensure the provided account has at least 1 NFTs.") let testNftId = collectionRef.getIDs()[0] let nftResolver = collectionRef.borrowViewResolver(id: testNftId) + ?? panic("Could not borrow NFT with id ".concat(testNftId.toString())) let metadataCollectionData = nftResolver.resolveView(Type())! as! MetadataViews.NFTCollectionData