This document summarizes the public structs and entry functions defined in
gamedevcard.move and explains their parameters, behaviour and important
constraints. It focuses only on the functions and types used by the
frontend/backend integration.
Module: ays::game_dev_card
- Provides a simple profile object (
GameDevCardProfile) which holds a collection of games. Each game is a separate on-chain object (GameItem). - Uses a shared
DonkeySaddleobject as the namespace for dynamic fields (profile lookup by username).
-
DonkeySaddle(has key)- Fields:
id: UID - Purpose: A globally shared object used as the root for dynamic fields
(acts like a registry / name-index). Call
init_saddleonce to create and share it.
- Fields:
-
GameItem(has key, store)- Fields:
id: UID,game_name: String,game_link: String,description: String,image_url: String,platform: String - Purpose: Each game is represented by a distinct on-chain object. Because
GameItemhas thekeyability, it must be deleted explicitly (seeremove_game).
- Fields:
-
GameDevCardProfile(has key, store)- Fields:
id: UID,name: String,games: vector<ID> - Purpose: Profile object that stores user name and a vector of game IDs
(the object IDs for
GameItems). Note: only IDs are stored in the profile'sgamesvector (not embedded objects).
- Fields:
Creates a new DonkeySaddle object and calls transfer::share_object to
make it shareable. Call once during initialization.
- Creates a new
GameDevCardProfilewith the providednameand an emptygamesvector. - Validations:
namelength must be between 3 and 40 characters. Fails with codes1(too short) or2(too long).- Asserts that
df::exists_(&saddle.id, name) == false(error code99) so duplicate usernames are prevented.
- Behaviour:
- Adds the profile id into dynamic fields under the saddle with
df::add(&mut saddle.id, name, profile_id). - Transfers the created profile to the transaction sender.
- Adds the profile id into dynamic fields under the saddle with
add_game(mut profile: GameDevCardProfile, game_name: String, game_link: String, description: String, image_url: String, platform: String, ctx: &mut TxContext)
- Adds a new game to the provided
profile. - Validations (each throws with distinct error codes):
game_namelength [3,250] (codes 1/2)game_linklength [3,1000] (codes 3/4)descriptionlength [3,1000] (codes 5/6)image_urllength [10,1000] (codes 7/8)platformlength [1,250] (codes 9/10)
- Behaviour:
- Creates a
GameItemobject (object::new(ctx)) and obtains its inner UID viaobject::uid_to_inner(&new_game.id). - Pushes the new game's ID into
profile.games(avector<ID>). - Transfers the modified profile and the newly created
GameItemto the transaction sender. TheGameItembecomes a standalone on-chain object.
- Creates a
- Updates
profile.nametonew_name. - Validations:
new_namelength [3,40] (codes 100/101). - Behaviour: transfers the updated profile back to the sender.
update_game(mut profile: GameDevCardProfile, mut game_to_update: GameItem, game_name: String, game_link: String, description: String, image_url: String, platform: String, ctx: &mut TxContext)
- Updates fields of an existing
GameItemand ensures the game ID is present in theprofile.gamesvector. - Validations: similar length checks as
add_game(same error codes 1..10). - Checks that the
game_to_updateid exists inprofile.games; if not, assertion fails with code202. - Behaviour: updates the
GameItemfields and transfers both the profile and the updatedGameItemto the sender.
- Removes a
GameItemfrom a profile and deletes theGameItemobject. - Behaviour:
- Retrieves the target object's ID with
object::id(&game). - Deconstructs the
GameItemand callsobject::delete(id)to delete the on-chain object (required becauseGameItemhaskey). - Iterates
profile.gamesand swap-removes the matching ID. - Transfers the updated
profileback to the sender.
- Retrieves the target object's ID with
- Dynamic fields: the module uses
sui::dynamic_field(df) to map usernames (strings) to profile IDs. TheDonkeySaddleobject acts as the root for those dynamic fields.df::exists_(&saddle.id, name)checks for an existing username;df::add(&mut saddle.id, name, profile_id)registers a new mapping. - Object IDs vs UIDs:
GameDevCardProfile.gamesstoresIDvalues (object addresses). When creating aGameItem, the code obtains its inner UID withobject::uid_to_inner(&new_game.id)and stores that in the profile's vector. - Deletion: Because
GameItemhas thekeyability, it is deleted withobject::delete(id)instead of being dropped. The profile's vector is updated usingvector::swap_removeto remove the ID efficiently.
Initialize saddle (admin / one-time):
Script::init_saddle();Create profile (user transaction):
Script::create_game_dev_profile("alice".to_string(), &mut saddle_ref);Add a game to a profile:
Script::add_game(profile_obj, "My Game".to_string(), "https://...".to_string(), "A fun game".to_string(), "https://.../cover.png".to_string(), "web".to_string());Update a game's metadata (pass the GameItem object and profile):
Script::update_game(profile_obj, game_obj, "New Name".to_string(), ...);Remove a game (deletes the GameItem object):
Script::remove_game(profile_obj, game_obj);- The module embeds numeric error codes in assertions; when an assertion fails the transaction aborts with the provided numeric code. See each function's validation section above for codes and their meaning.
- Source:
gamedevcard.movein this repository.