flow-hydraulics / flow-pds

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

Recommendation: Include NFT Collection Public Interface Methods in Type-Specific Public Interface #55

Closed rheaplex closed 2 years ago

rheaplex commented 2 years ago

This makes it easier to use the public functions via a single interface.

e.g.:

https://github.com/dapperlabs/nba-smart-contracts/blob/master/contracts/TopShot.cdc#L525

https://github.com/onflow/kitty-items/blob/master/cadence/contracts/KittyItems.cdc#L46

For PackNFT, this would be:

    pub resource interface PackNFTCollectionPublic {
        pub fun deposit(token: @NonFungibleToken.NFT)
        pub fun getIDs(): [UInt64]
        pub fun borrowNFT(id: UInt64): &NonFungibleToken.NFT
        pub fun borrowPackNFT(id: UInt64): &PackNFT.NFT? {
            // If the result isn't nil, the id of the returned reference
            // should be the same as the argument to the function
            post {
                (result == nil) || (result?.id == id):
                    "Cannot borrow PackNFT reference: The ID of the returned reference is incorrect"
            }
        }
    }