Skip to content
This repository was archived by the owner on Nov 11, 2024. It is now read-only.

Commit 3fa4fbb

Browse files
authored
docs: add proper documentation for the Resource enum (#34)
1 parent 8041c3b commit 3fa4fbb

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

crates/contracts/src/world/resource.cairo

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,28 @@ use starknet::ContractAddress;
88
/// of re-computing the descriptor each time, which involves several poseidon hash
99
/// operations.
1010
///
11+
/// Namespaced resources: Those resources are scoped by a namespace, which
12+
/// defines a logical separation of resources. Namespaced resources are Model, Event and Contract.
13+
///
14+
/// - World: The world itself, identified by the selector 0.
15+
///
16+
/// - Namespace: ByteArray
17+
/// Namespace is a unique resource type, identified by a `ByteArray`, to scope models, events and
18+
/// contracts.
19+
/// The poseidon hash of the serialized `ByteArray` is used as the namespace hash.
20+
///
1121
/// - Model: (ContractAddress, NamespaceHash)
22+
/// A model defines data that can be stored in the world's storage.
23+
///
24+
/// - Event: (ContractAddress, NamespaceHash)
25+
/// An event is never stored in the world's storage, but it's emitted by the world to be consumed by
26+
/// off-chain components.
27+
///
1228
/// - Contract: (ContractAddress, NamespaceHash)
13-
/// - Namespace: ByteArray
14-
/// - World: The world itself, identified by the selector 0.
15-
/// - Unregistered: The unregistered state.
29+
/// A contract defines user logic to interact with the world's data (models) and to emit events.
30+
///
31+
/// - Unregistered: The unregistered state, required to ensure the security of the world
32+
/// to not have operations done on non-existent resources.
1633
#[derive(Drop, starknet::Store, Serde, Default, Debug)]
1734
pub enum Resource {
1835
Model: (ContractAddress, felt252),
@@ -26,6 +43,7 @@ pub enum Resource {
2643

2744
#[generate_trait]
2845
pub impl ResourceIsNoneImpl of ResourceIsNoneTrait {
46+
/// Returns true if the resource is unregistered, false otherwise.
2947
fn is_unregistered(self: @Resource) -> bool {
3048
match self {
3149
Resource::Unregistered => true,

0 commit comments

Comments
 (0)