Skip to content

Commit

Permalink
updated scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
judezhu committed Sep 28, 2023
1 parent 830c0dc commit 4239283
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
18 changes: 18 additions & 0 deletions transactions/scripts/users/is_account_all_set_up.cdc
Original file line number Diff line number Diff line change
@@ -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()
}
File renamed without changes.
47 changes: 47 additions & 0 deletions transactions/user/setup_up_all_collections.cdc
Original file line number Diff line number Diff line change
@@ -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");
}
}
}

0 comments on commit 4239283

Please sign in to comment.