Skip to content
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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

bshahid331
Copy link

No description provided.

@bshahid331 bshahid331 requested a review from rrrkren March 13, 2024 17:19
@bshahid331 bshahid331 requested a review from a team as a code owner March 13, 2024 17:19
Copy link

@sisyphusSmiling sisyphusSmiling left a 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)

@@ -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? {

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

Suggested change
view access(all) fun getFastBreakRun(id: String): FastBreakV1.FastBreakRun? {
access(all) view fun getFastBreakRun(id: String): FastBreakV1.FastBreakRun? {

@@ -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? {

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

Suggested change
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 {

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?

Copy link
Collaborator

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

Copy link
Collaborator

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

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 {

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

Comment on lines 631 to 632
access(all) fun getIDs(): [UInt64]
access(all) fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}?

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

Copy link
Collaborator

@joshuahannan joshuahannan left a 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
Copy link
Collaborator

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


pub contract TopShot: NonFungibleToken {
access(all) contract TopShot: NonFungibleToken, ViewResolver {
Copy link
Collaborator

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.

// The network the contract is deployed on
pub fun Network() : String { return ${NETWORK} }
view access(all) fun Network() : String { return ${NETWORK} }
Copy link
Collaborator

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...

@@ -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 {
Copy link
Collaborator

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 {
Copy link
Collaborator

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?

Copy link
Collaborator

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 {
Copy link
Collaborator

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

Comment on lines 650 to 653
access(all) resource Collection:
NonFungibleToken.Provider,
NonFungibleToken.Receiver,
NonFungibleToken.CollectionPublic,
NonFungibleToken.Collection,
Copy link
Collaborator

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 Show resolved Hide resolved
Comment on lines 697 to 698
view access(all) fun borrowNFTSafe(id: UInt64): &{NonFungibleToken.NFT}? {
return &self.ownedNFTs[id]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed

Comment on lines 740 to 746
view access(all) fun getContractViews(resourceType: Type?): [Type] {
return []
}

view access(all) fun resolveContractView(resourceType: Type?, viewType: Type): AnyStruct? {
return nil
}
Copy link
Collaborator

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

Copy link
Collaborator

@joshuahannan joshuahannan left a 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

Comment on lines 26 to +28
/// Contract events
///
pub event ContractInitialized()
access(all) event ContractInitialized()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed

Comment on lines +30 to +32
access(all) event Withdraw(id: UInt64, from: Address?)

pub event Deposit(id: UInt64, to: Address?)
access(all) event Deposit(id: UInt64, to: Address?)
Copy link
Collaborator

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 {
Copy link
Collaborator

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

FastBreakNFTCollectionPublic
{

pub var ownedNFTs: @{UInt64: NonFungibleToken.NFT}
access(contract) var ownedNFTs: @{UInt64: {NonFungibleToken.NFT}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update to access(all)

Comment on lines +725 to +726
access(all) view fun getLength(): Int {
return self.ownedNFTs.keys.length
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 {
Copy link
Collaborator

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NFTMinter entitlement?

// 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}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

@@ -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) {
Copy link
Collaborator

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?

contracts/TopShot.cdc Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants