From 42392836cfaf4c5fb94053dcae30f1238d5b43fa Mon Sep 17 00:00:00 2001 From: Jude Zhu Date: Thu, 28 Sep 2023 16:23:20 -0700 Subject: [PATCH] updated scripts --- .../scripts/users/is_account_all_set_up.cdc | 18 +++++++ ...setup_account.cdc => setup_collection.cdc} | 0 .../user/setup_up_all_collections.cdc | 47 +++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 transactions/scripts/users/is_account_all_set_up.cdc rename transactions/user/{setup_account.cdc => setup_collection.cdc} (100%) create mode 100644 transactions/user/setup_up_all_collections.cdc diff --git a/transactions/scripts/users/is_account_all_set_up.cdc b/transactions/scripts/users/is_account_all_set_up.cdc new file mode 100644 index 00000000..15110848 --- /dev/null +++ b/transactions/scripts/users/is_account_all_set_up.cdc @@ -0,0 +1,18 @@ +import TopShot from 0xTOPSHOTADDRESS +import NonFungibleToken from 0xNFTADDRESS +import PackNFT from 0xPACKNFTADDRESS +import MetadataViews from 0xMETADATAVIEWSADDRESS + +// Check to see if an account looks like it has been set up to hold Pinnacle NFTs and PackNFTs. +pub fun main(address: Address): Bool { + let account = getAccount(address) + return account.getCapability<&{ + NonFungibleToken.Receiver, + NonFungibleToken.CollectionPublic, + TopShot.MomentCollectionPublic, + MetadataViews.ResolverCollection + }>(/public/MomentCollection).check() && + account.getCapability<&{ + NonFungibleToken.CollectionPublic + }>(PackNFT.CollectionPublicPath).check() +} \ No newline at end of file diff --git a/transactions/user/setup_account.cdc b/transactions/user/setup_collection.cdc similarity index 100% rename from transactions/user/setup_account.cdc rename to transactions/user/setup_collection.cdc diff --git a/transactions/user/setup_up_all_collections.cdc b/transactions/user/setup_up_all_collections.cdc new file mode 100644 index 00000000..613373e0 --- /dev/null +++ b/transactions/user/setup_up_all_collections.cdc @@ -0,0 +1,47 @@ +import NonFungibleToken from 0xNFTADDRESS +import TopShot from 0xTOPSHOTADDRESS +import MetadataViews from 0xMETADATAVIEWSADDRESS + +// This transaction sets up an account to use Top Shot +// by storing an empty moment collection and creating +// a public capability for it + +transaction { + + prepare(acct: AuthAccount) { + + // First, check to see if a moment collection already exists + if acct.borrow<&TopShot.Collection>(from: /storage/MomentCollection) == nil { + // create a new TopShot Collection + let collection <- TopShot.createEmptyCollection() as! @TopShot.Collection + // Put the new Collection in storage + acct.save(<-collection, to: /storage/MomentCollection) + } + + if !acct.getCapability<&{ + NonFungibleToken.Receiver, + NonFungibleToken.CollectionPublic, + TopShot.MomentCollectionPublic, + MetadataViews.ResolverCollection + }>(/public/MomentCollection).check() { + acct.unlink(/public/MomentCollection) + // create a public capability for the collection + acct.link<&TopShot.Collection{NonFungibleToken.Receiver, NonFungibleToken.CollectionPublic, TopShot.MomentCollectionPublic, MetadataViews.ResolverCollection}>(/public/MomentCollection, target: /storage/MomentCollection) ?? panic("Could not link Topshot Collection Public Path"); + } + + // Create a PackNFT collection in the signer account if it doesn't already have one + if acct.borrow<&PackNFT.Collection>(from: PackNFT.CollectionStoragePath) == nil { + acct.save(<- PackNFT.createEmptyCollection(), to: PackNFT.CollectionStoragePath); + acct.link<&{NonFungibleToken.CollectionPublic}>(PackNFT.CollectionPublicPath, target: PackNFT.CollectionStoragePath) + } + + // Create collection public capability if it doesn't already exist + if !acct.getCapability<&{ + NonFungibleToken.CollectionPublic + }>(PackNFT.CollectionPublicPath).check() { + acct.unlink(PackNFT.CollectionPublicPath) + acct.link<&{NonFungibleToken.CollectionPublic}>(PackNFT.CollectionPublicPath, target: PackNFT.CollectionStoragePath) + ?? panic("Could not link Topshot PackNFT Collection Public Path"); + } + } +}