Skip to content

Commit

Permalink
update deprecated Cadence
Browse files Browse the repository at this point in the history
  • Loading branch information
sisyphusSmiling committed Sep 30, 2024
1 parent a23fa01 commit 4207236
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
6 changes: 3 additions & 3 deletions cadence/scripts/check_for_links.cdc
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import "MetadataViews"
import "ViewResolver"

/*
Script to check for the implementation of all recommended 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()
}
}
9 changes: 1 addition & 8 deletions cadence/scripts/get_examplenft_type.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 4 additions & 1 deletion cadence/transactions/add_to_nft_catalog.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -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<auth(NFTCatalogAdmin.CatalogActions) &NFTCatalogAdmin.AdminProxy>(from: NFTCatalogAdmin.AdminProxyStoragePath)!
}

Expand All @@ -38,7 +41,7 @@ transaction(
let catalogData = NFTCatalog.NFTCatalogMetadata(
contractName: contractName,
contractAddress: contractAddress,
nftType: CompositeType(nftTypeIdentifer)!,
nftType: self.nftType,
collectionData: collectionData,
collectionDisplay : collectionDisplay
)
Expand Down
6 changes: 4 additions & 2 deletions cadence/transactions/update_nft_catalog_entry.cdc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import "ViewResolver"
import "MetadataViews"
import "NFTCatalog"
import "NFTCatalogAdmin"
Expand All @@ -13,18 +14,19 @@ transaction(
let adminProxyRef : auth(NFTCatalogAdmin.CatalogActions) &NFTCatalogAdmin.AdminProxy

prepare(acct: auth(BorrowValue) &Account) {
self.adminProxyRef = acct.borrow<auth(NFTCatalogAdmin.CatalogActions) &NFTCatalogAdmin.AdminProxy>(from : NFTCatalogAdmin.AdminProxyStoragePath)!
self.adminProxyRef = acct.storage.borrow<auth(NFTCatalogAdmin.CatalogActions) &NFTCatalogAdmin.AdminProxy>(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<MetadataViews.NFTCollectionData>())! as! MetadataViews.NFTCollectionData

Expand Down

0 comments on commit 4207236

Please sign in to comment.