Skip to content

Commit

Permalink
Improve explanation content
Browse files Browse the repository at this point in the history
  • Loading branch information
lealobanov committed Dec 8, 2024
1 parent 5bed50a commit 121180b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
1 change: 0 additions & 1 deletion cadence/contracts/Recipe.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,4 @@ access(all) contract Recipe {
}

// Rest of TopShot contract below
}
11 changes: 4 additions & 7 deletions explanations/contract.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
In the TopShot contract when you are creating a Play that will be included in sets as a moment you first have to start your contract off by creating a dictionary that stores all of the plays you create. Also you would create a variable called nextPlayID to make sure you aren't overlapping on ID's.
In the TopShot contract, creating a Play to be included in sets as a Moment starts with setting up a dictionary, playDatas, to store all Plays. You also define a nextPlayID variable to ensure each Play gets a unique ID without overlaps.

Then you would create a structure that would be stored in the playDatas dictionary. Here, all that is needed for the Play struct is to input a parameter for metadata which is an object containing strings.
A Play struct is then created, which stores a unique ID and a metadata object containing descriptive key-value pairs about the Play. This struct will be stored in the playDatas dictionary, ensuring organized and efficient data management.

Once these are established, you would have an admin resource that would hold the ability to create a new play. For more information on Admin resources check out the Admin resource example.

Here you would call the createPlay function that takes in a metadata argument. You would then create the new play by passing in the metadata. You would also take the newPlay's ID so that you can use it to assign the struct to the dictionary.

Then you would increment the ID so that it can't be used again, emit a PlayCreated event, and store the newPlay in the dictionary.
Next, an Admin resource is introduced to control the creation of new Plays securely. The createPlay function within this resource takes metadata as input, generates a new Play using the metadata, and assigns it a unique ID from nextPlayID. After storing the Play in the playDatas dictionary, the function increments nextPlayID to avoid reuse, emits a PlayCreated event to log the creation, and returns the new Play's ID.

This streamlined process ensures that Plays are uniquely identified, securely created, and properly logged, forming the foundation for Moments that reference them.
4 changes: 2 additions & 2 deletions explanations/transaction.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
To create a play, you first need to get a reference to the admin resource from the AuthAccount.
To create a Play in the TopShot contract, you first need to obtain a reference to the Admin resource. This is done by borrowing it from the signer's storage using the authorized account's storage.borrow method and specifying the path where the Admin resource is stored. If the resource is not found, the transaction will panic to prevent further execution.

Once you receive that reference you can then create a play that gets stored in the playDatas dictionary.
Once you have the Admin resource reference, you can use it to create Plays. In this transaction, the createPlay function is called twice with different metadata for each Play. Each Play is stored in the playDatas dictionary, ensuring it is properly recorded in the contract. This approach ensures secure access to the Admin resource and allows Plays to be created efficiently and logged for future reference.

0 comments on commit 121180b

Please sign in to comment.