Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix collection initialization #18

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions cadence-transactions/packNFT/create_new_packNFT_collection.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@ import NonFungibleToken from 0x{{.NonFungibleToken}}
transaction() {
prepare (issuer: AuthAccount) {

// Check if account already have a PackIssuer resource, if so destroy it
if issuer.borrow<&PackNFT.Collection>(from: PackNFT.CollectionStoragePath) != nil {
issuer.unlink(PackNFT.CollectionPublicPath)
let p <- issuer.load<@PackNFT.Collection>(from: PackNFT.CollectionStoragePath)
destroy p
// Only initialize account if doesn't have a PackNFT.Collection resource
if issuer.borrow<&PackNFT.Collection>(from: PackNFT.CollectionStoragePath) == nil {
issuer.save(<-PackNFT.createEmptyCollection(), to: PackNFT.CollectionStoragePath);
issuer.link<&{NonFungibleToken.CollectionPublic}>(PackNFT.CollectionPublicPath, target: PackNFT.CollectionStoragePath)
?? panic("Could not link PackNFT.Collection Pub Path");
}

issuer.save(<- PackNFT.createEmptyCollection(), to: PackNFT.CollectionStoragePath);

issuer.link<&{NonFungibleToken.CollectionPublic}>(PackNFT.CollectionPublicPath, target: PackNFT.CollectionStoragePath)
?? panic("Could not link Collection Pub Path");
}
}
}