From 1fdfda2231817127ed41780efc25ffb38852623b Mon Sep 17 00:00:00 2001 From: Fabio Kenji Date: Mon, 28 Mar 2022 11:23:57 -0700 Subject: [PATCH 1/2] Check and initialize collection --- .../packNFT/create_new_packNFT_collection.cdc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cadence-transactions/packNFT/create_new_packNFT_collection.cdc b/cadence-transactions/packNFT/create_new_packNFT_collection.cdc index c0a4853..c3ffb92 100644 --- a/cadence-transactions/packNFT/create_new_packNFT_collection.cdc +++ b/cadence-transactions/packNFT/create_new_packNFT_collection.cdc @@ -5,10 +5,10 @@ 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 + 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); From b9ae973ef39ace6bda2497b32e0506166f7d6c88 Mon Sep 17 00:00:00 2001 From: Fabio Kenji Date: Mon, 28 Mar 2022 14:14:10 -0700 Subject: [PATCH 2/2] Remove duplicated code --- .../packNFT/create_new_packNFT_collection.cdc | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/cadence-transactions/packNFT/create_new_packNFT_collection.cdc b/cadence-transactions/packNFT/create_new_packNFT_collection.cdc index c3ffb92..3301def 100644 --- a/cadence-transactions/packNFT/create_new_packNFT_collection.cdc +++ b/cadence-transactions/packNFT/create_new_packNFT_collection.cdc @@ -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 + // 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"); - } + } }