Skip to content

Commit

Permalink
Debugging contract
Browse files Browse the repository at this point in the history
  • Loading branch information
lealobanov committed Dec 11, 2024
1 parent 291b9c9 commit bb54ecf
Showing 1 changed file with 34 additions and 25 deletions.
59 changes: 34 additions & 25 deletions cadence/contracts/Recipe.cdc
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import "TopShot"
import "NonFungibleToken"

access(all) contract Recipe {
// This is a snippet extracting the relevant logic from the TopShot contract for demonstration purposes
// More TopShot Code Above
// Emitted when a Moment is minted from a Set
access(all) event MomentMinted(momentID: UInt64, playID: UInt32, setID: UInt32, serialNumber: UInt32, subeditionID: UInt32)

access(all)
resource Set {
access(contract) var retired: {UInt32: Bool}
access(all) let setID: UInt32
access(contract) var numberMintedPerPlay: {UInt32: UInt32}

init(name: String) {
self.setID = TopShot.nextSetID
self.numberMintedPerPlay = {}
self.retired = {}
}

// mintMoment mints a new Moment and returns the newly minted Moment
//
// Parameters: playID: The ID of the Play that the Moment references
Expand All @@ -15,8 +29,7 @@ access(all) contract Recipe {
//
// Returns: The NFT that was minted
//
access(all)
fun mintMoment(playID: UInt32): @NFT {
access(all) fun mintMoment(playID: UInt32): @NFT {
pre {
self.retired[playID] != nil: "Cannot mint the moment: This play doesn't exist."
!self.retired[playID]!: "Cannot mint the moment from this play: This play has been retired."
Expand All @@ -27,11 +40,10 @@ access(all) contract Recipe {
let numInPlay = self.numberMintedPerPlay[playID]!

// Mint the new moment
let newMoment: @NFT <- create NFT(
serialNumber: numInPlay + UInt32(1),
playID: playID,
setID: self.setID
)
let newMoment: @NFT <- create NFT(serialNumber: numInPlay + UInt32(1),
playID: playID,
setID: self.setID,
subeditionID: 0)

// Increment the count of Moments minted for this Play
self.numberMintedPerPlay[playID] = numInPlay + UInt32(1)
Expand All @@ -48,9 +60,8 @@ access(all) contract Recipe {
// Returns: Collection object that contains all the Moments that were minted
//
access(all)
fun batchMintMoment(playID: UInt32, quantity: UInt64): @Collection {
let newCollection <- create Collection()

fun batchMintMoment(playID: UInt32, quantity: UInt64): @TopShot.Collection {
let newCollection <- create TopShot.Collection()
var i: UInt64 = 0
while i < quantity {
newCollection.deposit(token: <-self.mintMoment(playID: playID))
Expand All @@ -65,23 +76,21 @@ access(all) contract Recipe {
struct MomentData {

// The ID of the Set that the Moment comes from
access(all)
let setID: UInt32
access(all) let setID: UInt32

// The ID of the Play that the Moment references
access(all)
let playID: UInt32
access(all) let playID: UInt32

// The place in the edition that this Moment was minted
// Otherwise know as the serial number
access(all)
let serialNumber: UInt32
access(all) let serialNumber: UInt32

init(setID: UInt32, playID: UInt32, serialNumber: UInt32) {
self.setID = setID
self.playID = playID
self.serialNumber = serialNumber
}

}

// The resource that represents the Moment NFTs
Expand All @@ -97,21 +106,21 @@ access(all) contract Recipe {
access(all)
let data: MomentData

init(serialNumber: UInt32, playID: UInt32, setID: UInt32) {
// Increment the global Moment IDs
TopShot.totalSupply = TopShot.totalSupply + UInt64(1)
access(all) var totalSupply: UInt64

init(serialNumber: UInt32, playID: UInt32, setID: UInt32, subeditionID: UInt32) {
// Increment the global Moment IDs
self.totalSupply = TopShot.totalSupply + UInt64(1)
self.id = TopShot.totalSupply

// Set the metadata struct
self.data = MomentData(setID: setID, playID: playID, serialNumber: serialNumber)

emit MomentMinted(
momentID: self.id,
playID: playID,
setID: self.data.setID,
serialNumber: self.data.serialNumber
)
emit MomentMinted(momentID: self.id,
playID: playID,
setID: self.data.setID,
serialNumber: self.data.serialNumber,
subeditionID: subeditionID)
}

}
Expand Down

0 comments on commit bb54ecf

Please sign in to comment.