flow-hydraulics / flow-pds

This repository is currently not maintained
4 stars 8 forks source link

Recommendation: Prefer Borrowing To Withdrawing and Depositing #56

Closed rheaplex closed 2 years ago

rheaplex commented 2 years ago

For example, rather than:

transaction(revealID: UInt64) {
    prepare(owner: AuthAccount) {
        // withdraw the token from collection
        let collectionRef = owner.borrow<&PackNFT.Collection>(from: PackNFT.collectionStoragePath)!
        let nft <- collectionRef.withdraw(withdrawID: revealID) as! @PackNFT.NFT
        // open
        nft.open()

        // store token back to collection
        collectionRef.deposit(token: <-nft) 
    }
}

this would be:

    prepare(owner: AuthAccount) {
        // Get the collection
        let collectionRef = owner.borrow<&PackNFT.Collection>(from: PackNFT.collectionStoragePath)!
        // Borrow the nft and open it
        collectionRef.borrowPackNFT(withdrawID: revealID)!.open()
    }