-
Notifications
You must be signed in to change notification settings - Fork 2
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
Update PDS & PackNFT contracts & txs to Cadence 1.0 #47
Conversation
pub case Opened | ||
} | ||
// Enums cannot be declared anymore in interfaces in Cadence 1.0 | ||
// access(all) enum Status: UInt8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Status
enum remain needed in PackNFT
contracts, but we remove it in IPackNFT
because concrete type declarations are not allowed in contract interfaces anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good to know. We can just remove it then
pds/contracts/PDS.cdc
Outdated
|
||
access(all) contract PDS{ | ||
/// Entitlement that grants the ability to create a distribution | ||
access(all) entitlement DistCreation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New entitlement to control access for distribution creation, replacing dist creator resource interface in pre-Cadence 1.0 contract
pds/contracts/PDS.cdc
Outdated
access(self) let withdrawCap: Capability<&{NonFungibleToken.Provider}> | ||
access(self) let operatorCap: Capability<&{IPackNFT.IOperator}> | ||
access(all) resource SharedCapabilities { | ||
access(self) let withdrawCap: Capability<auth(NonFungibleToken.Withdraw) &{NonFungibleToken.Provider}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withdrawCap
& operatorCap
must now allow access to authorized references to the NFT Provider
& PackNFT Operator
, respectively.
pre { | ||
cap.borrow() != nil: "Invalid capability" | ||
} | ||
self.cap = cap | ||
} | ||
|
||
pub fun create(sharedCap: @SharedCapabilities, title: String, metadata: {String: String}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create
is now a reserved keyword
pds/contracts/PackNFT.cdc
Outdated
|
||
pub fun reveal(openRequest: Bool){ | ||
access(NonFungibleToken.Update | NonFungibleToken.Owner) fun reveal(openRequest: Bool){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revealing and opening a pack NFT requires NonFungibleToken.Update
- or NonFungibleToken.Owner
-authorized reference
PackNFT.totalSupply = PackNFT.totalSupply - (1 as UInt64) | ||
/// Event emitted when a NFT is destroyed (replaces Burned event before Cadence 1.0 update) | ||
/// | ||
access(all) event ResourceDestroyed(id: UInt64 = self.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the custom destroy
function being removed from Cadence 1.0:
- NFT destruction should now be tracked by the special event with the reserved name
ResourceDestroyed
. TotalSupply
will not account for NFTs being destroyed anymore.- The corresponding PackNFT resource will have to be deployed in a separate call (e.g., in the same tx or function call where the NFT is being destroyed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only reviewed for Cadence best practices. Didn't really review the business logic, transactions, or tests. Mostly looks good! Just a few small comments
pds/contracts/PackNFT.cdc
Outdated
access(all) view fun getViews(): [Type] { | ||
return [] | ||
} | ||
|
||
/// Resolve this NFT's metadata views. | ||
/// | ||
access(all) view fun resolveView(_ view: Type): AnyStruct? { | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that this can't be represented by any views? I would think that at the minimum, you would at least want the NFTCollectionData
and NFTCollectionDisplay
views, but there might be even more that apply
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The views depend on each individual PackNFT instance. The AllDay version of the PackNFT contract updated in this PR defines the views. Added a comment in the vanilla PackNFT contract to make it clear that the views should be implemented 👍
|
||
access(contract) fun reveal(id: UInt64, nfts: [{IPackNFT.Collectible}], salt: String) | ||
access(contract) fun open(id: UInt64, nfts: [{IPackNFT.Collectible}]) | ||
init(commitHash: String, issuer: Address) | ||
view init(commitHash: String, issuer: Address) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this init
method read-only? this is a bit confusing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was confused too initially but the view
keyword means the method is read-only with respect to the state outside of the method itself 👍 (for more details: https://cadence-lang.org/docs/1.0/language/functions#view-functions)
pub case Opened | ||
} | ||
// Enums cannot be declared anymore in interfaces in Cadence 1.0 | ||
// access(all) enum Status: UInt8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good to know. We can just remove it then
version: version, | ||
) | ||
} else { | ||
log("has contract") | ||
owner.contracts.update__experimental(name: contractName, code: code.decodeHex()) | ||
owner.contracts.add(name: contractName, code: code.decodeHex()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be an update
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, fixed it - thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
Changes:
Operatable
for PackNFT operations.DistCreation
for distribution creation.State migration from existing pre-1.0 contract is currently blocked by onflow/cadence#3182.
Capabilities migration will require more attention.
For context on Cadence 1.0: