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 NBA contracts & txs to Cadence 1.0 #248
base: master
Are you sure you want to change the base?
Conversation
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.
Only had a chance to look through FastBreakV1
, but leaving initial comments (some nits)
contracts/FastBreakV1.cdc
Outdated
@@ -179,7 +183,7 @@ pub contract FastBreakV1: NonFungibleToken { | |||
|
|||
/// Get a Fast Break Run by Id | |||
/// | |||
pub fun getFastBreakRun(id: String): FastBreakV1.FastBreakRun? { | |||
view access(all) fun getFastBreakRun(id: String): FastBreakV1.FastBreakRun? { |
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 don't think there's an issue with the ordering here, but recommending the following format for consistency with core contracts and language docs
view access(all) fun getFastBreakRun(id: String): FastBreakV1.FastBreakRun? { | |
access(all) view fun getFastBreakRun(id: String): FastBreakV1.FastBreakRun? { |
contracts/FastBreakV1.cdc
Outdated
@@ -232,7 +236,7 @@ pub contract FastBreakV1: NonFungibleToken { | |||
|
|||
/// Get a account's active Fast Break Submission | |||
/// | |||
pub fun getFastBreakSubmissionByPlayerId(playerId: UInt64): FastBreakV1.FastBreakSubmission? { | |||
view access(all) fun getFastBreakSubmissionByPlayerId(playerId: UInt64): FastBreakV1.FastBreakSubmission? { |
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.
Same as above, and throughout the rest of the contract
view access(all) fun getFastBreakSubmissionByPlayerId(playerId: UInt64): FastBreakV1.FastBreakSubmission? { | |
access(all) view fun getFastBreakSubmissionByPlayerId(playerId: UInt64): FastBreakV1.FastBreakSubmission? { |
@@ -382,11 +386,11 @@ pub contract FastBreakV1: NonFungibleToken { | |||
/// Resource for playing Fast Break | |||
/// The Fast Break Player plays the game & mints game tokens | |||
/// | |||
pub resource Player: FastBreakPlayer, NonFungibleToken.INFT { | |||
access(all) resource Player: FastBreakPlayer { |
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.
Did you mean to remove INFT
conformance here or should FastBreakPlayer
implement INFT
?
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.
We're updating the standard to remove INFT
, so that shouldn't be here, but NonFungibleToken.NFT
should be here
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.
@bshahid331 This needs to implement NonFungibleToken.NFT
contracts/FastBreakV1.cdc
Outdated
pub fun borrowNFT(id: UInt64): &NonFungibleToken.NFT | ||
pub fun borrowNFTSafe(id: UInt64): &NonFungibleToken.NFT? | ||
pub fun borrowFastBreakNFT(id: UInt64): &FastBreakV1.NFT? { | ||
access(all) resource interface FastBreakNFTCollectionPublic { |
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.
Since interfaces can inherent interfaces, you could have this interface implement NFT.CollectionPublic and include additional methods specific for FastBreak
contracts/FastBreakV1.cdc
Outdated
access(all) fun getIDs(): [UInt64] | ||
access(all) fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? |
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 believe you'll want these to be view
methods or they'll conflict with NFT.CollectionPublic methods. I'd also consider removing borrowNFTSafe
below since borrowNFT
now returns an optional
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 start! I only reviewed the contracts and left comments on them. You'll need to find someone on the studio team to review the rest of the code
access(all) contract Market { | ||
|
||
access(all) entitlement Create | ||
access(all) entitlement Withdraw |
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 would probably recommend removing Withdraw
here and just using NonFungibleToken.Withdraw
instead
contracts/TopShot.cdc
Outdated
|
||
pub contract TopShot: NonFungibleToken { | ||
access(all) contract TopShot: NonFungibleToken, ViewResolver { |
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.
There is no need to add ViewResolver
here since it is already inherited with NonFungibleToken
.
contracts/TopShot.cdc
Outdated
// The network the contract is deployed on | ||
pub fun Network() : String { return ${NETWORK} } | ||
view access(all) fun Network() : String { return ${NETWORK} } |
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 is just a style thing, but the common place for putting view
in a function declaration is after the access specification, so access(all) view fun Network...
contracts/TopShot.cdc
Outdated
@@ -369,7 +372,7 @@ pub contract TopShot: NonFungibleToken { | |||
// | |||
// Returns: The NFT that was minted | |||
// | |||
pub fun mintMoment(playID: UInt32): @NFT { | |||
access(NFTMinter) fun mintMoment(playID: UInt32): @NFT { |
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'm a little confused why you have a minter entitlement but don't have entitlements for any of the other methods? This never has a public capability, right? So why the need for a single entitlement here?
@@ -399,7 +402,7 @@ pub contract TopShot: NonFungibleToken { | |||
// | |||
// Returns: Collection object that contains all the Moments that were minted | |||
// | |||
pub fun batchMintMoment(playID: UInt32, quantity: UInt64): @Collection { | |||
access(all) fun batchMintMoment(playID: UInt32, quantity: UInt64): @Collection { |
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.
If you're including the NFTMinter
entitlement, it should be here too, right?
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.
NFTMinter
entitlement?
@@ -382,11 +386,11 @@ pub contract FastBreakV1: NonFungibleToken { | |||
/// Resource for playing Fast Break | |||
/// The Fast Break Player plays the game & mints game tokens | |||
/// | |||
pub resource Player: FastBreakPlayer, NonFungibleToken.INFT { | |||
access(all) resource Player: FastBreakPlayer { |
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.
We're updating the standard to remove INFT
, so that shouldn't be here, but NonFungibleToken.NFT
should be here
contracts/FastBreakV1.cdc
Outdated
access(all) resource Collection: | ||
NonFungibleToken.Provider, | ||
NonFungibleToken.Receiver, | ||
NonFungibleToken.CollectionPublic, | ||
NonFungibleToken.Collection, |
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 only needs to be NonFungibleToken.Collection
contracts/FastBreakV1.cdc
Outdated
view access(all) fun borrowNFTSafe(id: UInt64): &{NonFungibleToken.NFT}? { | ||
return &self.ownedNFTs[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.
This can be removed
contracts/FastBreakV1.cdc
Outdated
view access(all) fun getContractViews(resourceType: Type?): [Type] { | ||
return [] | ||
} | ||
|
||
view access(all) fun resolveContractView(resourceType: Type?, viewType: 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.
I would think that there would be some views that this contract would implement. You should figure out which ones can be included so Top Shot can set a good example
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.
Followed up on a few of my comments that were never addressed and left a few more. The changes will require the contracts to be re-staged on testnet after you address them. Let me know before you want to re-stage so I can verify that everything has been addressed
/// Contract events | ||
/// | ||
pub event ContractInitialized() | ||
access(all) event ContractInitialized() |
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 can be removed
access(all) event Withdraw(id: UInt64, from: Address?) | ||
|
||
pub event Deposit(id: UInt64, to: Address?) | ||
access(all) event Deposit(id: UInt64, to: 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.
I'd recommend removing these because the default NonFungibleToken
events are much better
@@ -382,11 +386,11 @@ pub contract FastBreakV1: NonFungibleToken { | |||
/// Resource for playing Fast Break | |||
/// The Fast Break Player plays the game & mints game tokens | |||
/// | |||
pub resource Player: FastBreakPlayer, NonFungibleToken.INFT { | |||
access(all) resource Player: FastBreakPlayer { |
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.
@bshahid331 This needs to implement NonFungibleToken.NFT
contracts/FastBreakV1.cdc
Outdated
FastBreakNFTCollectionPublic | ||
{ | ||
|
||
pub var ownedNFTs: @{UInt64: NonFungibleToken.NFT} | ||
access(contract) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}} |
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.
Update to access(all)
access(all) view fun getLength(): Int { | ||
return self.ownedNFTs.keys.length |
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.
access(all) view fun getLength(): Int { | |
return self.ownedNFTs.keys.length | |
access(all) view fun getLength(): Int { | |
return self.ownedNFTs.length |
@@ -421,15 +422,15 @@ pub contract TopShot: NonFungibleToken { | |||
// | |||
// Returns: The NFT that was minted | |||
// | |||
pub fun mintMomentWithSubedition(playID: UInt32, subeditionID: UInt32): @NFT { | |||
access(all) fun mintMomentWithSubedition(playID: UInt32, subeditionID: UInt32): @NFT { |
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.
NFTMinter
entitlement?
@@ -463,7 +464,7 @@ pub contract TopShot: NonFungibleToken { | |||
// | |||
// Returns: Collection object that contains all the Moments that were minted | |||
// | |||
pub fun batchMintMomentWithSubedition(playID: UInt32, quantity: UInt64, subeditionID: UInt32): @Collection { | |||
access(all) fun batchMintMomentWithSubedition(playID: UInt32, quantity: UInt64, subeditionID: UInt32): @Collection { |
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.
NFTMinter
entitlement?
contracts/TopShot.cdc
Outdated
// Dictionary of Moment conforming tokens | ||
// NFT is a resource type with a UInt64 ID field | ||
pub var ownedNFTs: @{UInt64: NonFungibleToken.NFT} | ||
access(contract) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}} |
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.
access(contract) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}} | |
access(all) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}} |
This needs to be access(all)
now based on recent FLIPs and standard changes
contracts/TopShot.cdc
Outdated
@@ -1191,7 +1224,7 @@ pub contract TopShot: NonFungibleToken { | |||
|
|||
// lock takes a token id and a duration in seconds and locks | |||
// the moment for that duration | |||
pub fun lock(id: UInt64, duration: UFix64) { | |||
access(NonFungibleToken.Update | NonFungibleToken.Owner) fun lock(id: UInt64, duration: UFix64) { |
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.
Can you include this event emission here?
* cadence 1 upgrade * fix tests * token updated
No description provided.