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

Fix syntax and improve documentation in core modules #2981

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions crates/dojo/core/src/model/model.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,32 @@ use dojo::{
};

use super::{ModelDefinition, ModelDef, ModelIndex};
/// Trait `KeyParser` defines a trait for parsing keys from a given model.
///

/// A pointer to a model, which can be expressed by an entity id.
///
/// # Type Parameters
/// - `M`: The type of the model being pointed to
///
/// # Fields
/// - `id`: The unique identifier for the model instance
#[derive(Copy, Drop, Serde, Debug, PartialEq)]
pub struct ModelPtr<M> {
pub id: felt252,
}

/// Trait `KeyParser` defines a trait for parsing keys from a given model.
///
/// # Type Parameters
/// - `M`: The type of the model
/// - `K`: The type of the key
///
/// # Methods
/// - `parse_key`: Parses the key from the given model
pub trait KeyParser<M, K> {
/// Parses the key from the given model.
fn parse_key(self: @M) -> K;
}

/// Trait that defines a method for converting a span of model pointers to a span of model indexes.
///
/// # Type Parameters
Expand Down Expand Up @@ -43,11 +61,6 @@ pub impl ModelPtrsImpl<M> of ModelPtrsTrait<M> {
}
}

pub trait KeyParser<M, K> {
/// Parses the key from the given model.
fn parse_key(self: @M) -> K;
}

/// Defines a trait for parsing models, providing methods to serialize keys and values.
pub trait ModelParser<M> {
/// Serializes the keys of the model.
Expand Down
2 changes: 1 addition & 1 deletion crates/dojo/core/src/world/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,5 @@ pub fn invalid_resource_version_upgrade(
}

pub fn inconsistent_namespaces(old_hash: felt252, new_hash: felt252) -> ByteArray {
format!("Inconsistent namespaces (old: {old_hash} new: {new_hash}")
format!("Inconsistent namespaces (old: {old_hash} new: {new_hash})")
}
13 changes: 13 additions & 0 deletions crates/dojo/core/src/world/world_contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,18 @@ pub mod world {
}

#[derive(Drop, starknet::Event)]
/// Event emitted when a new world is spawned
pub struct WorldSpawned {
/// The address of the creator of the world
pub creator: ContractAddress,
/// The class hash of the world contract
pub class_hash: ClassHash,
}

#[derive(Drop, starknet::Event)]
/// Event emitted when the world contract is upgraded
pub struct WorldUpgraded {
/// The new class hash of the world contract
pub class_hash: ClassHash,
}

Expand Down Expand Up @@ -234,13 +239,21 @@ pub mod world {
}

#[storage]
/// Main storage structure for the World contract
struct Storage {
/// Counter for generating unique identifiers
nonce: usize,
/// Salt used for model deployments
models_salt: usize,
/// Salt used for event deployments
events_salt: usize,
/// Mapping of resource selectors to their corresponding Resource instances
resources: Map::<felt252, Resource>,
/// Mapping of (resource selector, contract address) to owner status
owners: Map::<(felt252, ContractAddress), bool>,
/// Mapping of (resource selector, contract address) to writer status
writers: Map::<(felt252, ContractAddress), bool>,
/// Mapping of contract selectors to their initialization status
initialized_contracts: Map::<felt252, bool>,
}

Expand Down