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 9, 2024
1 parent 3d564a5 commit f0bb488
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
10 changes: 3 additions & 7 deletions explanations/contract.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
Simlarly to creating a Play, when you're creating a set you want to have dictionaries. The first dictionary would be one for SetData structures and the second dictionary would be for Set Resources. You'd also include a nextSetID that makes sure you don't overlap on sets.
The Set and SetData structures in the Recipe contract are designed to organize and manage collectibles efficiently. SetData is a lightweight struct that holds basic metadata for each Set, such as its unique ID, name, and series. This information is stored in a contract-wide dictionary (setDatas) to make it easily accessible for reading. On the other hand, the Set resource represents an actual group of plays (collectibles) and contains more detailed functionality. It manages a list of plays, tracks whether plays are retired, keeps a count of moments minted for each play, and ensures no further changes are made once the Set is locked.

Your SetData struct would contain information pertaining to the naming of the Set. That's the only parameter you would need to pass in the create a new struct. The SetData would take in nextSetID variable and the currentSeries variable to finishing creating the struct.
When creating a Set, the admin uses the createSet function to initialize a Set resource and its associated SetData. The Set resource also provides functions to add plays, retire them, lock the Set, and mint moments. Each function is carefully controlled with checks to ensure valid operations. For example, you can only add a play if it exists and the Set is unlocked. Similarly, minting a moment requires the play to be active and not retired. The lock function prevents any further modifications, ensuring the integrity of the Set.

You would also need to define a resource called Set. When this resource is being initialized it will need to have an ID defined, an array that can store plays you have created, a boolean variable that checks what plays have been retired from being created in the current set, a lock variable that determines if you can add more plays to the set, and a dictionary that maps how many moments have been minted per play.

When you initialize a set, you also take in a name parameter that gets passed into the SetData struct so that it can be added to the contracts storage in the SetData dictionary. Once that is created you have a set resource that you can put minting functions and whole bunch of other things in to deal with creating NFTS and adding Plays.

To create a set, you would have a function in your admin resource that would allow you to do so. You would call the createSet function and pass in a name for the set. You'd create a Set by calling the create function on a resource and pass in the parameters. You'd then increment your setID so that it's not used again. Then you'd get the ID of the newly created Set resource, emit an event that you created a set and then add the new Set resource to be mapped in the Sets dictionary.
Overall, this structure separates metadata from operational data, making the contract easier to maintain and scale. It ensures only authorized actions can occur, while keeping data accessible and operations straightforward for both developers and users.
6 changes: 4 additions & 2 deletions explanations/transaction.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
To create a set, you first need to get a reference to the admin resource from the AuthAccount.
To create a Set in the TopShot contract, the transaction first retrieves a reference to the Admin resource. This is done by borrowing the Admin resource from the signer's account storage using the specified storage path (/storage/TopShotAdmin). If the resource is not found, the transaction will terminate with an error.

Once you receive that reference you can then create a set that gets stored in the sets and setsData dictionary.
Once the reference to the Admin resource is obtained, the transaction calls the createSet function, providing the name for the new Set (in this case, "Rookies"). This function creates a new Set resource and automatically adds it to the sets dictionary for management, while also updating the corresponding SetData entry for metadata. After successfully creating the Set, the transaction logs a confirmation message.

This flow ensures that only authorized accounts with access to the Admin resource can create new Sets.

0 comments on commit f0bb488

Please sign in to comment.