From ff040b05055707593c908fca3db39744602eced9 Mon Sep 17 00:00:00 2001 From: Tarrence van As Date: Thu, 28 Sep 2023 10:41:13 -0400 Subject: [PATCH] Rename component to model (#936) --- crates/dojo-core/src/database.cairo | 6 +- crates/dojo-core/src/database/utils.cairo | 2 +- crates/dojo-core/src/test_utils.cairo | 8 +- crates/dojo-core/src/world.cairo | 161 +++++++++--------- crates/dojo-core/src/world_test.cairo | 20 +-- crates/dojo-defi/src/market.cairo | 2 +- .../src/market/constant_product_market.cairo | 2 +- .../market/{components.cairo => models.cairo} | 0 crates/dojo-defi/src/market/systems.cairo | 8 +- .../tests/constant_product_market_tests.cairo | 2 +- crates/dojo-erc/src/lib.cairo | 2 +- crates/dojo-erc/src/tests/erc20_tests.cairo | 2 +- crates/dojo-erc/src/tests/erc721_tests.cairo | 2 +- crates/dojo-erc/src/token/erc20.cairo | 8 +- ...20_components.cairo => erc20_models.cairo} | 0 crates/dojo-erc/src/token/erc721.cairo | 4 +- crates/dojo-erc/src/token/erc721/erc721.cairo | 2 +- .../erc721/{components.cairo => models.cairo} | 0 crates/dojo-lang/README.md | 4 +- crates/dojo-lang/src/inline_macros/get.rs | 58 +++---- crates/dojo-lang/src/inline_macros/mod.rs | 22 ++- crates/dojo-lang/src/inline_macros/set.rs | 9 +- crates/dojo-lang/src/manifest.rs | 30 ++-- .../dojo-lang/src/manifest_test_data/manifest | 74 +++----- crates/dojo-lang/src/plugin.rs | 8 +- .../dojo-lang/src/plugin_test_data/introspect | 2 +- crates/dojo-lang/src/plugin_test_data/model | 2 +- crates/dojo-lang/src/plugin_test_data/print | 2 +- crates/dojo-lang/src/plugin_test_data/system | 2 +- crates/dojo-lang/src/print.rs | 2 +- crates/dojo-types/src/event.rs | 15 +- crates/dojo-types/src/lib.rs | 2 +- .../dojo-types/src/{component.rs => model.rs} | 2 +- crates/dojo-types/src/system.rs | 4 +- crates/dojo-world/src/manifest.rs | 24 +-- crates/dojo-world/src/migration/strategy.rs | 17 +- crates/dojo-world/src/migration/world.rs | 22 +-- crates/dojo-world/src/migration/world_test.rs | 14 +- crates/sozo/src/args.rs | 4 +- crates/sozo/src/commands/auth.rs | 4 +- crates/sozo/src/commands/events.rs | 4 +- crates/sozo/src/commands/register.rs | 8 +- .../sozo/src/commands/scarb_internal/mod.rs | 4 +- crates/sozo/src/commands/test.rs | 4 +- crates/sozo/src/ops/auth.rs | 4 +- crates/sozo/src/ops/events.rs | 2 +- .../sozo/src/ops/migration/migration_test.rs | 2 +- crates/sozo/src/ops/migration/mod.rs | 20 +-- crates/sozo/src/ops/model.rs | 12 +- crates/sozo/src/ops/register.rs | 6 +- crates/torii/client/src/contract/model.rs | 8 +- .../torii/client/src/contract/model_test.rs | 4 +- crates/torii/client/src/contract/world.rs | 24 +-- .../torii/client/src/contract/world_test.rs | 6 +- crates/torii/client/src/provider/jsonrpc.rs | 10 +- crates/torii/client/src/provider/mod.rs | 8 +- crates/torii/client/src/storage.rs | 11 +- crates/torii/client/src/sync.rs | 28 ++- crates/torii/client/wasm/index.js | 12 +- crates/torii/client/wasm/src/lib.rs | 12 +- crates/torii/client/wasm/src/storage.rs | 12 +- crates/torii/client/wasm/worker.js | 16 +- .../core/src/processors/register_model.rs | 2 +- .../core/src/processors/store_set_record.rs | 4 +- crates/torii/core/src/sql.rs | 2 +- crates/torii/core/src/sql_test.rs | 2 +- crates/torii/graphql/src/object/mod.rs | 2 +- .../graphql/src/tests/subscription_test.rs | 2 +- examples/ecs/README.md | 14 +- examples/ecs/Scarb.toml | 13 +- examples/ecs/src/lib.cairo | 2 +- .../src/{components.cairo => models.cairo} | 0 examples/ecs/src/systems/raw_contract.cairo | 16 +- examples/ecs/src/systems/with_decorator.cairo | 16 +- examples/ecs/src/utils.cairo | 2 +- 75 files changed, 387 insertions(+), 461 deletions(-) rename crates/dojo-defi/src/market/{components.cairo => models.cairo} (100%) rename crates/dojo-erc/src/token/{erc20_components.cairo => erc20_models.cairo} (100%) rename crates/dojo-erc/src/token/erc721/{components.cairo => models.cairo} (100%) rename crates/dojo-types/src/{component.rs => model.rs} (99%) rename examples/ecs/src/{components.cairo => models.cairo} (100%) diff --git a/crates/dojo-core/src/database.cairo b/crates/dojo-core/src/database.cairo index 1099ac9b47..8a2630d66e 100644 --- a/crates/dojo-core/src/database.cairo +++ b/crates/dojo-core/src/database.cairo @@ -42,14 +42,14 @@ fn del(class_hash: starknet::ClassHash, table: felt252, key: felt252) { // returns a tuple of spans, first contains the entity IDs, // second the deserialized entities themselves fn all( - class_hash: starknet::ClassHash, component: felt252, partition: felt252, length: usize, layout: Span + class_hash: starknet::ClassHash, model: felt252, partition: felt252, length: usize, layout: Span ) -> (Span, Span>) { let table = { if partition == 0.into() { - component + model } else { let mut serialized = ArrayTrait::new(); - component.serialize(ref serialized); + model.serialize(ref serialized); partition.serialize(ref serialized); let hash = poseidon_hash_span(serialized.span()); hash.into() diff --git a/crates/dojo-core/src/database/utils.cairo b/crates/dojo-core/src/database/utils.cairo index 3677623310..62ae3ff531 100644 --- a/crates/dojo-core/src/database/utils.cairo +++ b/crates/dojo-core/src/database/utils.cairo @@ -15,7 +15,7 @@ const OFFSET: felt252 = 0x10000000000000000000000000000000000; // * `entities` is a list of lists of deserialized entities; each list of entities // is of the same entity type in the order of IDs from `ids // -// to illustrate, consider we have two entity types (components), Place and Owner +// to illustrate, consider we have two entity types (models), Place and Owner // `ids` are [[4, 2, 3], [3, 4, 5]] // `entities` are [[P4, P2, P3], [O3, O4, O5]] // where P4 is a deserialized (i.e. a Span) Place entity with ID 4, diff --git a/crates/dojo-core/src/test_utils.cairo b/crates/dojo-core/src/test_utils.cairo index faad96adde..eb3db0c220 100644 --- a/crates/dojo-core/src/test_utils.cairo +++ b/crates/dojo-core/src/test_utils.cairo @@ -41,7 +41,7 @@ fn deploy_with_world_address(class_hash: felt252, world: IWorldDispatcher) -> Co deploy_contract(class_hash, array![world.contract_address.into()].span()) } -fn spawn_test_world(components: Array) -> IWorldDispatcher { +fn spawn_test_world(models: Array) -> IWorldDispatcher { // deploy executor let constructor_calldata = array::ArrayTrait::new(); let (executor_address, _) = deploy_syscall( @@ -57,13 +57,13 @@ fn spawn_test_world(components: Array) -> IWorldDispatcher { .unwrap(); let world = IWorldDispatcher { contract_address: world_address }; - // register components + // register models let mut index = 0; loop { - if index == components.len() { + if index == models.len() { break (); } - world.register_component((*components[index]).try_into().unwrap()); + world.register_model((*models[index]).try_into().unwrap()); index += 1; }; diff --git a/crates/dojo-core/src/world.cairo b/crates/dojo-core/src/world.cairo index 0ee99ffd0e..f95b70ba99 100644 --- a/crates/dojo-core/src/world.cairo +++ b/crates/dojo-core/src/world.cairo @@ -4,13 +4,13 @@ use option::OptionTrait; #[starknet::interface] trait IWorld { - fn component(self: @T, name: felt252) -> ClassHash; - fn register_component(ref self: T, class_hash: ClassHash); + fn model(self: @T, name: felt252) -> ClassHash; + fn register_model(ref self: T, class_hash: ClassHash); fn uuid(ref self: T) -> usize; fn emit(self: @T, keys: Array, values: Span); fn entity( self: @T, - component: felt252, + model: felt252, keys: Span, offset: u8, length: usize, @@ -18,25 +18,25 @@ trait IWorld { ) -> Span; fn set_entity( ref self: T, - component: felt252, + model: felt252, keys: Span, offset: u8, values: Span, layout: Span ); fn entities( - self: @T, component: felt252, index: felt252, length: usize, layout: Span + self: @T, model: felt252, index: felt252, length: usize, layout: Span ) -> (Span, Span>); fn set_executor(ref self: T, contract_address: ContractAddress); fn executor(self: @T) -> ContractAddress; - fn delete_entity(ref self: T, component: felt252, keys: Span); + fn delete_entity(ref self: T, model: felt252, keys: Span); fn is_owner(self: @T, address: ContractAddress, target: felt252) -> bool; fn grant_owner(ref self: T, address: ContractAddress, target: felt252); fn revoke_owner(ref self: T, address: ContractAddress, target: felt252); - fn is_writer(self: @T, component: felt252, system: ContractAddress) -> bool; - fn grant_writer(ref self: T, component: felt252, system: ContractAddress); - fn revoke_writer(ref self: T, component: felt252, system: ContractAddress); + fn is_writer(self: @T, model: felt252, system: ContractAddress) -> bool; + fn grant_writer(ref self: T, model: felt252, system: ContractAddress); + fn revoke_writer(ref self: T, model: felt252, system: ContractAddress); } #[starknet::contract] @@ -65,8 +65,7 @@ mod world { #[derive(Drop, starknet::Event)] enum Event { WorldSpawned: WorldSpawned, - ComponentRegistered: ComponentRegistered, - SystemRegistered: SystemRegistered, + ModelRegistered: ModelRegistered, StoreSetRecord: StoreSetRecord, StoreDelRecord: StoreDelRecord } @@ -78,17 +77,11 @@ mod world { } #[derive(Drop, starknet::Event)] - struct ComponentRegistered { + struct ModelRegistered { name: felt252, class_hash: ClassHash } - #[derive(Drop, starknet::Event)] - struct SystemRegistered { - name: felt252, - contract_address: ContractAddress - } - #[derive(Drop, starknet::Event)] struct StoreSetRecord { table: felt252, @@ -106,7 +99,7 @@ mod world { #[storage] struct Storage { executor_dispatcher: IExecutorDispatcher, - components: LegacyMap::, + models: LegacyMap::, nonce: usize, owners: LegacyMap::<(felt252, ContractAddress), bool>, writers: LegacyMap::<(felt252, ContractAddress), bool>, @@ -180,7 +173,7 @@ mod world { self.owners.write((target, address), bool::True(())); } - /// Revokes owner permission to the system for the component. + /// Revokes owner permission to the system for the model. /// Can only be called by an existing owner or the world admin. /// /// # Arguments @@ -193,89 +186,89 @@ mod world { self.owners.write((target, address), bool::False(())); } - /// Checks if the provided system is a writer of the component. + /// Checks if the provided system is a writer of the model. /// /// # Arguments /// - /// * `component` - The name of the component. + /// * `model` - The name of the model. /// * `system` - The name of the system. /// /// # Returns /// - /// * `bool` - True if the system is a writer of the component, false otherwise - fn is_writer(self: @ContractState, component: felt252, system: ContractAddress) -> bool { - self.writers.read((component, system)) + /// * `bool` - True if the system is a writer of the model, false otherwise + fn is_writer(self: @ContractState, model: felt252, system: ContractAddress) -> bool { + self.writers.read((model, system)) } - /// Grants writer permission to the system for the component. - /// Can only be called by an existing component owner or the world admin. + /// Grants writer permission to the system for the model. + /// Can only be called by an existing model owner or the world admin. /// /// # Arguments /// - /// * `component` - The name of the component. + /// * `model` - The name of the model. /// * `system` - The name of the system. - fn grant_writer(ref self: ContractState, component: felt252, system: ContractAddress) { + fn grant_writer(ref self: ContractState, model: felt252, system: ContractAddress) { let caller = get_caller_address(); assert( - self.is_owner(caller, component) || self.is_owner(caller, WORLD), + self.is_owner(caller, model) || self.is_owner(caller, WORLD), 'not owner or writer' ); - self.writers.write((component, system), bool::True(())); + self.writers.write((model, system), bool::True(())); } - /// Revokes writer permission to the system for the component. - /// Can only be called by an existing component writer, owner or the world admin. + /// Revokes writer permission to the system for the model. + /// Can only be called by an existing model writer, owner or the world admin. /// /// # Arguments /// - /// * `component` - The name of the component. + /// * `model` - The name of the model. /// * `system` - The name of the system. - fn revoke_writer(ref self: ContractState, component: felt252, system: ContractAddress) { + fn revoke_writer(ref self: ContractState, model: felt252, system: ContractAddress) { let caller = get_caller_address(); assert( - self.is_writer(component, caller) - || self.is_owner(caller, component) + self.is_writer(model, caller) + || self.is_owner(caller, model) || self.is_owner(caller, WORLD), 'not owner or writer' ); - self.writers.write((component, system), bool::False(())); + self.writers.write((model, system), bool::False(())); } - /// Registers a component in the world. If the component is already registered, + /// Registers a model in the world. If the model is already registered, /// the implementation will be updated. /// /// # Arguments /// - /// * `class_hash` - The class hash of the component to be registered. - fn register_component(ref self: ContractState, class_hash: ClassHash) { + /// * `class_hash` - The class hash of the model to be registered. + fn register_model(ref self: ContractState, class_hash: ClassHash) { let caller = get_caller_address(); let calldata = ArrayTrait::new(); let name = *class_call(@self, class_hash, NAME_ENTRYPOINT, calldata.span())[0]; - // If component is already registered, validate permission to update. - if self.components.read(name).is_non_zero() { + // If model is already registered, validate permission to update. + if self.models.read(name).is_non_zero() { assert(self.is_owner(caller, name), 'only owner can update'); } else { self.owners.write((name, caller), bool::True(())); }; - self.components.write(name, class_hash); - EventEmitter::emit(ref self, ComponentRegistered { name, class_hash }); + self.models.write(name, class_hash); + EventEmitter::emit(ref self, ModelRegistered { name, class_hash }); } - /// Gets the class hash of a registered component. + /// Gets the class hash of a registered model. /// /// # Arguments /// - /// * `name` - The name of the component. + /// * `name` - The name of the model. /// /// # Returns /// - /// * `ClassHash` - The class hash of the component. - fn component(self: @ContractState, name: felt252) -> ClassHash { - self.components.read(name) + /// * `ClassHash` - The class hash of the model. + fn model(self: @ContractState, name: felt252) -> ClassHash { + self.models.read(name) } /// Issues an autoincremented id to the caller. @@ -301,80 +294,80 @@ mod world { emit_event_syscall(keys.span(), values).unwrap_syscall(); } - /// Sets the component value for an entity. + /// Sets the model value for an entity. /// /// # Arguments /// - /// * `component` - The name of the component to be set. + /// * `model` - The name of the model to be set. /// * `key` - The key to be used to find the entity. - /// * `offset` - The offset of the component in the entity. + /// * `offset` - The offset of the model in the entity. /// * `value` - The value to be set. fn set_entity( ref self: ContractState, - component: felt252, + model: felt252, keys: Span, offset: u8, values: Span, layout: Span ) { - assert_can_write(@self, component, get_caller_address()); + assert_can_write(@self, model, get_caller_address()); let key = poseidon::poseidon_hash_span(keys); - let component_class_hash = self.components.read(component); - database::set(component_class_hash, component, key, offset, values, layout); + let model_class_hash = self.models.read(model); + database::set(model_class_hash, model, key, offset, values, layout); - EventEmitter::emit(ref self, StoreSetRecord { table: component, keys, offset, values }); + EventEmitter::emit(ref self, StoreSetRecord { table: model, keys, offset, values }); } - /// Deletes a component from an entity. + /// Deletes a model from an entity. /// /// # Arguments /// - /// * `component` - The name of the component to be deleted. + /// * `model` - The name of the model to be deleted. /// * `query` - The query to be used to find the entity. - fn delete_entity(ref self: ContractState, component: felt252, keys: Span) { + fn delete_entity(ref self: ContractState, model: felt252, keys: Span) { let system = get_caller_address(); assert(system.is_non_zero(), 'must be called thru system'); - assert_can_write(@self, component, system); + assert_can_write(@self, model, system); let key = poseidon::poseidon_hash_span(keys); - let component_class_hash = self.components.read(component); - database::del(component_class_hash, component, key); + let model_class_hash = self.models.read(model); + database::del(model_class_hash, model, key); - EventEmitter::emit(ref self, StoreDelRecord { table: component, keys }); + EventEmitter::emit(ref self, StoreDelRecord { table: model, keys }); } - /// Gets the component value for an entity. Returns a zero initialized - /// component value if the entity has not been set. + /// Gets the model value for an entity. Returns a zero initialized + /// model value if the entity has not been set. /// /// # Arguments /// - /// * `component` - The name of the component to be retrieved. + /// * `model` - The name of the model to be retrieved. /// * `query` - The query to be used to find the entity. - /// * `offset` - The offset of the component values. - /// * `length` - The length of the component values. + /// * `offset` - The offset of the model values. + /// * `length` - The length of the model values. /// /// # Returns /// - /// * `Span` - The value of the component, zero initialized if not set. + /// * `Span` - The value of the model, zero initialized if not set. fn entity( self: @ContractState, - component: felt252, + model: felt252, keys: Span, offset: u8, length: usize, layout: Span ) -> Span { - let class_hash = self.components.read(component); + let class_hash = self.models.read(model); let key = poseidon::poseidon_hash_span(keys); - database::get(class_hash, component, key, offset, length, layout) + database::get(class_hash, model, key, offset, length, layout) } - /// Returns entity IDs and entities that contain the component state. + /// Returns entity IDs and entities that contain the model state. /// /// # Arguments /// - /// * `component` - The name of the component to be retrieved. + /// * `model` - The name of the model to be retrieved. /// * `index` - The index to be retrieved. /// /// # Returns @@ -383,13 +376,13 @@ mod world { /// * `Span>` - The entities. fn entities( self: @ContractState, - component: felt252, + model: felt252, index: felt252, length: usize, layout: Span ) -> (Span, Span>) { - let class_hash = self.components.read(component); - database::all(class_hash, component.into(), index, length, layout) + let class_hash = self.models.read(model); + database::all(class_hash, model.into(), index, length, layout) } /// Sets the executor contract address. @@ -415,16 +408,16 @@ mod world { } } - /// Asserts that the current caller can write to the component. + /// Asserts that the current caller can write to the model. /// /// # Arguments /// - /// * `component` - The name of the component being written to. + /// * `model` - The name of the model being written to. /// * `caller` - The name of the caller writing. - fn assert_can_write(self: @ContractState, component: felt252, caller: ContractAddress) { + fn assert_can_write(self: @ContractState, model: felt252, caller: ContractAddress) { assert( - IWorld::is_writer(self, component, caller) - || IWorld::is_owner(self, get_tx_info().unbox().account_contract_address, component) + IWorld::is_writer(self, model, caller) + || IWorld::is_owner(self, get_tx_info().unbox().account_contract_address, model) || IWorld::is_owner(self, get_tx_info().unbox().account_contract_address, WORLD), 'not writer' ); diff --git a/crates/dojo-core/src/world_test.cairo b/crates/dojo-core/src/world_test.cairo index ef433e8ca2..5eac4ebb1f 100644 --- a/crates/dojo-core/src/world_test.cairo +++ b/crates/dojo-core/src/world_test.cairo @@ -12,8 +12,6 @@ use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait, world}; use dojo::database::schema::SchemaIntrospection; use dojo::test_utils::{spawn_test_world, deploy_with_world_address}; -// Components and Systems - #[derive(Model, Copy, Drop, Serde)] struct Foo { #[key] @@ -61,9 +59,9 @@ mod bar { #[test] #[available_gas(2000000)] -fn test_component() { +fn test_model() { let world = deploy_world(); - world.register_component(foo::TEST_CLASS_HASH.try_into().unwrap()); + world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap()); } #[test] @@ -71,7 +69,7 @@ fn test_component() { fn test_system() { // Spawn empty world let world = deploy_world(); - world.register_component(foo::TEST_CLASS_HASH.try_into().unwrap()); + world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap()); // System contract let bar_contract = IbarDispatcher { @@ -87,11 +85,11 @@ fn test_system() { #[test] #[available_gas(6000000)] -fn test_component_class_hash_getter() { +fn test_model_class_hash_getter() { let world = deploy_world(); - world.register_component(foo::TEST_CLASS_HASH.try_into().unwrap()); + world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap()); - let foo = world.component('Foo'); + let foo = world.model('Foo'); assert(foo == foo::TEST_CLASS_HASH.try_into().unwrap(), 'foo does not exists'); } @@ -113,7 +111,7 @@ fn test_emit() { fn test_set_entity_admin() { // Spawn empty world let world = deploy_world(); - world.register_component(foo::TEST_CLASS_HASH.try_into().unwrap()); + world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap()); let bar_contract = IbarDispatcher { contract_address: deploy_with_world_address(bar::TEST_CLASS_HASH, world) @@ -140,7 +138,7 @@ fn test_set_entity_unauthorized() { contract_address: deploy_with_world_address(bar::TEST_CLASS_HASH, world) }; - world.register_component(foo::TEST_CLASS_HASH.try_into().unwrap()); + world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap()); let caller = starknet::contract_address_const::<0x1337>(); starknet::testing::set_account_contract_address(caller); @@ -158,7 +156,7 @@ fn test_set_entity_unauthorized() { // fn test_set_entity_directly() { // // Spawn world // let world = deploy_world(); -// world.register_component(foo::TEST_CLASS_HASH.try_into().unwrap()); +// world.register_model(foo::TEST_CLASS_HASH.try_into().unwrap()); // let bar_contract = IbarDispatcher { // contract_address: deploy_with_world_address(bar::TEST_CLASS_HASH, world) diff --git a/crates/dojo-defi/src/market.cairo b/crates/dojo-defi/src/market.cairo index fff5b7e67f..cb5ccb799c 100644 --- a/crates/dojo-defi/src/market.cairo +++ b/crates/dojo-defi/src/market.cairo @@ -1,3 +1,3 @@ -mod components; +mod models; mod systems; mod constant_product_market; diff --git a/crates/dojo-defi/src/market/constant_product_market.cairo b/crates/dojo-defi/src/market/constant_product_market.cairo index 5658f8d057..1fd4839804 100644 --- a/crates/dojo-defi/src/market/constant_product_market.cairo +++ b/crates/dojo-defi/src/market/constant_product_market.cairo @@ -1,5 +1,5 @@ use starknet::ContractAddress; -use dojo_defi::market::components::Market; +use dojo_defi::market::models::Market; use cubit::f128::types::fixed::{Fixed, FixedTrait}; const SCALING_FACTOR: u128 = 10000; diff --git a/crates/dojo-defi/src/market/components.cairo b/crates/dojo-defi/src/market/models.cairo similarity index 100% rename from crates/dojo-defi/src/market/components.cairo rename to crates/dojo-defi/src/market/models.cairo diff --git a/crates/dojo-defi/src/market/systems.cairo b/crates/dojo-defi/src/market/systems.cairo index e7bbbe0e83..078bd5cec1 100644 --- a/crates/dojo-defi/src/market/systems.cairo +++ b/crates/dojo-defi/src/market/systems.cairo @@ -1,6 +1,6 @@ #[system] mod Buy { - use dojo_defi::market::components::{Item, Cash, Market}; + use dojo_defi::market::models::{Item, Cash, Market}; use dojo_defi::market::constant_product_market::MarketTrait; use dojo::world::Context; @@ -38,7 +38,7 @@ mod Buy { #[system] mod Sell { - use dojo_defi::market::components::{Item, Cash, Market}; + use dojo_defi::market::models::{Item, Cash, Market}; use dojo_defi::market::constant_product_market::MarketTrait; use dojo::world::Context; @@ -77,7 +77,7 @@ mod Sell { #[system] mod AddLiquidity { - use dojo_defi::market::components::{Item, Cash, Market, Liquidity}; + use dojo_defi::market::models::{Item, Cash, Market, Liquidity}; use dojo_defi::market::constant_product_market::MarketTrait; use dojo::world::Context; @@ -126,7 +126,7 @@ mod AddLiquidity { #[system] mod RemoveLiquidity { - use dojo_defi::market::components::{Item, Cash, Market, Liquidity}; + use dojo_defi::market::models::{Item, Cash, Market, Liquidity}; use dojo_defi::market::constant_product_market::MarketTrait; use dojo::world::Context; diff --git a/crates/dojo-defi/src/tests/constant_product_market_tests.cairo b/crates/dojo-defi/src/tests/constant_product_market_tests.cairo index b125eb4ea0..4d51200d4d 100644 --- a/crates/dojo-defi/src/tests/constant_product_market_tests.cairo +++ b/crates/dojo-defi/src/tests/constant_product_market_tests.cairo @@ -1,6 +1,6 @@ use traits::Into; -use dojo_defi::market::components::Market; +use dojo_defi::market::models::Market; use dojo_defi::market::constant_product_market::{MarketTrait, SCALING_FACTOR}; use dojo_defi::tests::utils::{TOLERANCE, assert_approx_equal}; diff --git a/crates/dojo-erc/src/lib.cairo b/crates/dojo-erc/src/lib.cairo index 8d7760a12b..d72ce1149b 100644 --- a/crates/dojo-erc/src/lib.cairo +++ b/crates/dojo-erc/src/lib.cairo @@ -1,6 +1,6 @@ mod token { mod erc20; - mod erc20_components; + mod erc20_models; mod erc721; } diff --git a/crates/dojo-erc/src/tests/erc20_tests.cairo b/crates/dojo-erc/src/tests/erc20_tests.cairo index a75f625038..669cfc7c4d 100644 --- a/crates/dojo-erc/src/tests/erc20_tests.cairo +++ b/crates/dojo-erc/src/tests/erc20_tests.cairo @@ -17,7 +17,7 @@ use zeroable::Zeroable; use dojo::test_utils::spawn_test_world; use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; -use dojo_erc::token::erc20_components::{ +use dojo_erc::token::erc20_models::{ ERC20Allowance, erc_20_allowance, ERC20Balance, erc_20_balance, ERC20Meta, erc_20_meta }; use dojo_erc::token::erc20::ERC20::_worldContractMemberStateTrait; diff --git a/crates/dojo-erc/src/tests/erc721_tests.cairo b/crates/dojo-erc/src/tests/erc721_tests.cairo index 65bc34df19..a4c194eddb 100644 --- a/crates/dojo-erc/src/tests/erc721_tests.cairo +++ b/crates/dojo-erc/src/tests/erc721_tests.cairo @@ -20,7 +20,7 @@ use zeroable::Zeroable; use dojo::test_utils::spawn_test_world; use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; -use dojo_erc::token::erc721::components::{ +use dojo_erc::token::erc721::models::{ ERC721Meta, erc_721_meta, ERC721OperatorApproval, erc_721_operator_approval, ERC721Owner, erc_721_owner, ERC721Balance, erc_721_balance, ERC721TokenApproval, erc_721_token_approval }; diff --git a/crates/dojo-erc/src/token/erc20.cairo b/crates/dojo-erc/src/token/erc20.cairo index 3fb468a477..238e05a1e6 100644 --- a/crates/dojo-erc/src/token/erc20.cairo +++ b/crates/dojo-erc/src/token/erc20.cairo @@ -25,7 +25,7 @@ trait IERC20CamelOnly { #[starknet::contract] mod ERC20 { - use dojo_erc::token::erc20_components::{ERC20Allowance, ERC20Balance, ERC20Meta}; + use dojo_erc::token::erc20_models::{ERC20Allowance, ERC20Balance, ERC20Meta}; use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; use integer::BoundedInt; use super::IERC20; @@ -209,7 +209,7 @@ mod ERC20 { get!(self.world(), get_contract_address(), ERC20Meta) } - // Helper function to update total_supply component + // Helper function to update total_supply model fn update_total_supply(ref self: ContractState, subtract: u256, add: u256) { let mut meta = self.get_meta(); // adding and subtracting is fewer steps than if @@ -218,7 +218,7 @@ mod ERC20 { set!(self.world(), (meta)); } - // Helper function for balance component + // Helper function for balance model fn get_balance(self: @ContractState, account: ContractAddress) -> ERC20Balance { get!(self.world(), (get_contract_address(), account), ERC20Balance) } @@ -233,7 +233,7 @@ mod ERC20 { set!(self.world(), (balance)); } - // Helper function for allowance component + // Helper function for allowance model fn get_allowance( self: @ContractState, owner: ContractAddress, spender: ContractAddress, ) -> ERC20Allowance { diff --git a/crates/dojo-erc/src/token/erc20_components.cairo b/crates/dojo-erc/src/token/erc20_models.cairo similarity index 100% rename from crates/dojo-erc/src/token/erc20_components.cairo rename to crates/dojo-erc/src/token/erc20_models.cairo diff --git a/crates/dojo-erc/src/token/erc721.cairo b/crates/dojo-erc/src/token/erc721.cairo index 92af52a460..15b96462ac 100644 --- a/crates/dojo-erc/src/token/erc721.cairo +++ b/crates/dojo-erc/src/token/erc721.cairo @@ -1,5 +1,5 @@ mod erc721; -mod components; +mod models; mod interface; -use erc721::ERC721; \ No newline at end of file +use erc721::ERC721; diff --git a/crates/dojo-erc/src/token/erc721/erc721.cairo b/crates/dojo-erc/src/token/erc721/erc721.cairo index 7809ef6616..ffd7915d82 100644 --- a/crates/dojo-erc/src/token/erc721/erc721.cairo +++ b/crates/dojo-erc/src/token/erc721/erc721.cairo @@ -1,6 +1,6 @@ #[starknet::contract] mod ERC721 { - use dojo_erc::token::erc721::components::{ + use dojo_erc::token::erc721::models::{ ERC721Meta, ERC721OperatorApproval, ERC721Owner, ERC721Balance, ERC721TokenApproval }; use dojo_erc::token::erc721::interface; diff --git a/crates/dojo-erc/src/token/erc721/components.cairo b/crates/dojo-erc/src/token/erc721/models.cairo similarity index 100% rename from crates/dojo-erc/src/token/erc721/components.cairo rename to crates/dojo-erc/src/token/erc721/models.cairo diff --git a/crates/dojo-lang/README.md b/crates/dojo-lang/README.md index 961d8e77bf..2868ce5cb4 100644 --- a/crates/dojo-lang/README.md +++ b/crates/dojo-lang/README.md @@ -4,12 +4,12 @@ Cairo language plugin for compiling the Dojo Entity Component System to Starknet ## Testing -Expected test outputs are defined in `crates/dojo-lang/src/plugin_test_data/component`. +Expected test outputs are defined in `crates/dojo-lang/src/plugin_test_data/model`. To run the tests, run: ``` -cargo test --package dojo-lang --lib -- plugin::test::expand_contract::component --exact --nocapture +cargo test --package dojo-lang --lib -- plugin::test::expand_contract::model --exact --nocapture ``` To regenerate, set `CAIRO_FIX_TESTS=1`. diff --git a/crates/dojo-lang/src/inline_macros/get.rs b/crates/dojo-lang/src/inline_macros/get.rs index 5209dfd5bd..c58b638479 100644 --- a/crates/dojo-lang/src/inline_macros/get.rs +++ b/crates/dojo-lang/src/inline_macros/get.rs @@ -7,7 +7,7 @@ use cairo_lang_syntax::node::ast::Expr; use cairo_lang_syntax::node::{ast, TypedSyntaxNode}; use itertools::Itertools; -use super::{extract_components, unsupported_arg_diagnostic, CAIRO_ERR_MSG_LEN}; +use super::{extract_models, unsupported_arg_diagnostic, CAIRO_ERR_MSG_LEN}; #[derive(Debug)] pub struct GetMacro; @@ -36,7 +36,7 @@ impl InlineMacroExprPlugin for GetMacro { code: None, diagnostics: vec![PluginDiagnostic { stable_ptr: syntax.stable_ptr().untyped(), - message: "Invalid arguments. Expected \"get!(world, keys, (components,))\"" + message: "Invalid arguments. Expected \"get!(world, keys, (models,))\"" .to_string(), }], }; @@ -48,22 +48,22 @@ impl InlineMacroExprPlugin for GetMacro { return unsupported_arg_diagnostic(db, syntax); }; - let ast::ArgClause::Unnamed(components) = args[2].arg_clause(db) else { + let ast::ArgClause::Unnamed(models) = args[2].arg_clause(db) else { return unsupported_arg_diagnostic(db, syntax); }; - let components = match extract_components(db, &components.value(db)) { - Ok(components) => components, + let models = match extract_models(db, &models.value(db)) { + Ok(models) => models, Err(diagnostic) => { return InlinePluginResult { code: None, diagnostics: vec![diagnostic] }; } }; - if components.is_empty() { + if models.is_empty() { return InlinePluginResult { code: None, diagnostics: vec![PluginDiagnostic { stable_ptr: syntax.stable_ptr().untyped(), - message: "Component types cannot be empty".to_string(), + message: "Model types cannot be empty".to_string(), }], }; } @@ -78,33 +78,29 @@ impl InlineMacroExprPlugin for GetMacro { let __get_macro_keys__ = array::ArrayTrait::span(@__get_macro_keys__);" )); - for component in &components { - let mut lookup_err_msg = format!("{} not found", component.to_string()); + for model in &models { + let mut lookup_err_msg = format!("{} not found", model.to_string()); lookup_err_msg.truncate(CAIRO_ERR_MSG_LEN); - let mut deser_err_msg = format!("{} failed to deserialize", component.to_string()); + let mut deser_err_msg = format!("{} failed to deserialize", model.to_string()); deser_err_msg.truncate(CAIRO_ERR_MSG_LEN); builder.add_str(&format!( - "\n let mut __{component}_layout__ = array::ArrayTrait::new(); - dojo::database::schema::SchemaIntrospection::<{component}>::layout(ref \ - __{component}_layout__); - let mut __{component}_layout_clone__ = __{component}_layout__.clone(); - let mut __{component}_layout_span__ = \ - array::ArrayTrait::span(@__{component}_layout__); - let mut __{component}_layout_clone_span__ = \ - array::ArrayTrait::span(@__{component}_layout_clone__); - let mut __{component}_values__ = {}.entity('{component}', __get_macro_keys__, \ - 0_u8, dojo::packing::calculate_packed_size(ref \ - __{component}_layout_clone_span__), __{component}_layout_span__); - let mut __{component}_component__ = array::ArrayTrait::new(); - array::serialize_array_helper(__get_macro_keys__, ref __{component}_component__); - array::serialize_array_helper(__{component}_values__, ref \ - __{component}_component__); - let mut __{component}_component_span__ = \ - array::ArrayTrait::span(@__{component}_component__); - let __{component} = \ - option::OptionTrait::expect(serde::Serde::<{component}>::deserialize( - ref __{component}_component_span__ + "\n let mut __{model}_layout__ = array::ArrayTrait::new(); + dojo::database::schema::SchemaIntrospection::<{model}>::layout(ref \ + __{model}_layout__); + let mut __{model}_layout_clone__ = __{model}_layout__.clone(); + let mut __{model}_layout_span__ = array::ArrayTrait::span(@__{model}_layout__); + let mut __{model}_layout_clone_span__ = \ + array::ArrayTrait::span(@__{model}_layout_clone__); + let mut __{model}_values__ = {}.entity('{model}', __get_macro_keys__, 0_u8, \ + dojo::packing::calculate_packed_size(ref __{model}_layout_clone_span__), \ + __{model}_layout_span__); + let mut __{model}_model__ = array::ArrayTrait::new(); + array::serialize_array_helper(__get_macro_keys__, ref __{model}_model__); + array::serialize_array_helper(__{model}_values__, ref __{model}_model__); + let mut __{model}_model_span__ = array::ArrayTrait::span(@__{model}_model__); + let __{model} = option::OptionTrait::expect(serde::Serde::<{model}>::deserialize( + ref __{model}_model_span__ ), '{deser_err_msg}');\n", world.as_syntax_node().get_text(db), )); @@ -112,7 +108,7 @@ impl InlineMacroExprPlugin for GetMacro { builder.add_str(&format!( "({}) }}", - components.iter().map(|c| format!("__{c}")).join(",") + models.iter().map(|c| format!("__{c}")).join(",") )); InlinePluginResult { diff --git a/crates/dojo-lang/src/inline_macros/mod.rs b/crates/dojo-lang/src/inline_macros/mod.rs index c51a45e5c8..74aa1c9fb9 100644 --- a/crates/dojo-lang/src/inline_macros/mod.rs +++ b/crates/dojo-lang/src/inline_macros/mod.rs @@ -9,25 +9,23 @@ pub mod set; const CAIRO_ERR_MSG_LEN: usize = 31; -pub fn extract_components( +pub fn extract_models( db: &dyn SyntaxGroup, expression: &ast::Expr, ) -> Result, PluginDiagnostic> { - let mut components = vec![]; + let mut models = vec![]; match expression { ast::Expr::Tuple(tuple) => { for element in tuple.expressions(db).elements(db) { - match extract_components(db, &element) { - Ok(mut element_components) => components.append(&mut element_components), + match extract_models(db, &element) { + Ok(mut element_models) => models.append(&mut element_models), Err(diagnostic) => return Err(diagnostic), } } } ast::Expr::Parenthesized(parenthesized) => { - match extract_components(db, &parenthesized.expr(db)) { - Ok(mut parenthesized_components) => { - components.append(&mut parenthesized_components) - } + match extract_models(db, &parenthesized.expr(db)) { + Ok(mut parenthesized_models) => models.append(&mut parenthesized_models), Err(diagnostic) => return Err(diagnostic), } } @@ -50,14 +48,14 @@ pub fn extract_components( }); }; - match extract_components(db, &expr.expr(db)) { - Ok(mut expr_components) => components.append(&mut expr_components), + match extract_models(db, &expr.expr(db)) { + Ok(mut expr_models) => models.append(&mut expr_models), Err(diagnostic) => return Err(diagnostic), } } } ast::PathSegment::Simple(segment) => { - components.push(segment.ident(db).text(db)); + models.push(segment.ident(db).text(db)); } }, _ => { @@ -71,7 +69,7 @@ pub fn extract_components( } } - Ok(components) + Ok(models) } pub fn unsupported_arg_diagnostic( db: &dyn SyntaxGroup, diff --git a/crates/dojo-lang/src/inline_macros/set.rs b/crates/dojo-lang/src/inline_macros/set.rs index 0542affd95..36ae5c7a8e 100644 --- a/crates/dojo-lang/src/inline_macros/set.rs +++ b/crates/dojo-lang/src/inline_macros/set.rs @@ -31,20 +31,20 @@ impl InlineMacroExprPlugin for SetMacro { code: None, diagnostics: vec![PluginDiagnostic { stable_ptr: arg_list.args(db).stable_ptr().untyped(), - message: "Invalid arguments. Expected \"(world, (components,))\"".to_string(), + message: "Invalid arguments. Expected \"(world, (models,))\"".to_string(), }], }; } let world = &args[0]; - let ast::ArgClause::Unnamed(components) = args[1].arg_clause(db) else { + let ast::ArgClause::Unnamed(models) = args[1].arg_clause(db) else { return unsupported_arg_diagnostic(db, syntax); }; let mut bundle = vec![]; - match components.value(db) { + match models.value(db) { ast::Expr::Parenthesized(parens) => { bundle.push(parens.expr(db).as_syntax_node().get_text(db)) } @@ -56,8 +56,7 @@ impl InlineMacroExprPlugin for SetMacro { return InlinePluginResult { code: None, diagnostics: vec![PluginDiagnostic { - message: "Invalid arguments. Expected \"(world, (components,))\"" - .to_string(), + message: "Invalid arguments. Expected \"(world, (models,))\"".to_string(), stable_ptr: arg_list.args(db).stable_ptr().untyped(), }], }; diff --git a/crates/dojo-lang/src/manifest.rs b/crates/dojo-lang/src/manifest.rs index 04dde184a4..a02fc048bc 100644 --- a/crates/dojo-lang/src/manifest.rs +++ b/crates/dojo-lang/src/manifest.rs @@ -74,7 +74,7 @@ impl Manifest { if let Some(contracts) = aux_data.downcast_ref::() { manifest.find_contracts(contracts, &compiled_classes); } else if let Some(dojo_aux_data) = aux_data.downcast_ref() { - manifest.find_components(db, dojo_aux_data, *module_id, &compiled_classes); + manifest.find_models(db, dojo_aux_data, *module_id, &compiled_classes); } } } @@ -84,31 +84,31 @@ impl Manifest { manifest } - /// Finds the inline modules annotated as components in the given crate_ids and + /// Finds the inline modules annotated as models in the given crate_ids and /// returns the corresponding Models. - fn find_components( + fn find_models( &mut self, db: &dyn SemanticGroup, aux_data: &DojoAuxData, module_id: ModuleId, compiled_classes: &HashMap)>, ) { - for component in &aux_data.models { - let component = component.clone(); - let name: SmolStr = component.name.clone().into(); + for model in &aux_data.models { + let model = model.clone(); + let name: SmolStr = model.name.clone().into(); if let Ok(Some(ModuleItemId::Struct(_))) = db.module_item_by_name(module_id, name.clone()) { - // It needs the `Component` suffix because we are + // It needs the `Model` suffix because we are // searching from the compiled contracts. let (class_hash, class_abi) = compiled_classes .get(name.to_case(Case::Snake).as_str()) - .with_context(|| format!("Component {name} not found in target.")) + .with_context(|| format!("Model {name} not found in target.")) .unwrap(); - self.0.components.push(dojo_world::manifest::Model { - name: component.name, - members: component.members, + self.0.models.push(dojo_world::manifest::Model { + name: model.name, + members: model.members, class_hash: *class_hash, abi: class_abi.clone(), }); @@ -118,14 +118,14 @@ impl Manifest { // removes contracts with DojoAuxType fn filter_contracts(&mut self) { - let mut components = HashMap::new(); + let mut models = HashMap::new(); - for component in &self.0.components { - components.insert(component.class_hash, true); + for model in &self.0.models { + models.insert(model.class_hash, true); } for i in (0..self.0.contracts.len()).rev() { - if components.get(&self.0.contracts[i].class_hash).is_some() { + if models.get(&self.0.contracts[i].class_hash).is_some() { self.0.contracts.remove(i); } } diff --git a/crates/dojo-lang/src/manifest_test_data/manifest b/crates/dojo-lang/src/manifest_test_data/manifest index d07c4fa928..d5975f8808 100644 --- a/crates/dojo-lang/src/manifest_test_data/manifest +++ b/crates/dojo-lang/src/manifest_test_data/manifest @@ -8,7 +8,7 @@ test_manifest_file "world": { "name": "world", "address": null, - "class_hash": "0x370195d9fa250c4844f750f68ca77adf86c7f3293cc1cbac5c65d3404e2b2af", + "class_hash": "0x260bc39baaf87e4310e5213178b5f7bea7344b9806b9d08101ec066aa7bc18", "abi": [ { "type": "impl", @@ -65,7 +65,7 @@ test_manifest_file "items": [ { "type": "function", - "name": "component", + "name": "model", "inputs": [ { "name": "name", @@ -81,7 +81,7 @@ test_manifest_file }, { "type": "function", - "name": "register_component", + "name": "register_model", "inputs": [ { "name": "class_hash", @@ -123,7 +123,7 @@ test_manifest_file "name": "entity", "inputs": [ { - "name": "component", + "name": "model", "type": "core::felt252" }, { @@ -155,7 +155,7 @@ test_manifest_file "name": "set_entity", "inputs": [ { - "name": "component", + "name": "model", "type": "core::felt252" }, { @@ -183,7 +183,7 @@ test_manifest_file "name": "entities", "inputs": [ { - "name": "component", + "name": "model", "type": "core::felt252" }, { @@ -234,7 +234,7 @@ test_manifest_file "name": "delete_entity", "inputs": [ { - "name": "component", + "name": "model", "type": "core::felt252" }, { @@ -302,7 +302,7 @@ test_manifest_file "name": "is_writer", "inputs": [ { - "name": "component", + "name": "model", "type": "core::felt252" }, { @@ -322,7 +322,7 @@ test_manifest_file "name": "grant_writer", "inputs": [ { - "name": "component", + "name": "model", "type": "core::felt252" }, { @@ -338,7 +338,7 @@ test_manifest_file "name": "revoke_writer", "inputs": [ { - "name": "component", + "name": "model", "type": "core::felt252" }, { @@ -380,7 +380,7 @@ test_manifest_file }, { "type": "event", - "name": "dojo::world::world::ComponentRegistered", + "name": "dojo::world::world::ModelRegistered", "kind": "struct", "members": [ { @@ -395,23 +395,6 @@ test_manifest_file } ] }, - { - "type": "event", - "name": "dojo::world::world::SystemRegistered", - "kind": "struct", - "members": [ - { - "name": "name", - "type": "core::felt252", - "kind": "data" - }, - { - "name": "contract_address", - "type": "core::starknet::contract_address::ContractAddress", - "kind": "data" - } - ] - }, { "type": "event", "name": "dojo::world::world::StoreSetRecord", @@ -467,13 +450,8 @@ test_manifest_file "kind": "nested" }, { - "name": "ComponentRegistered", - "type": "dojo::world::world::ComponentRegistered", - "kind": "nested" - }, - { - "name": "SystemRegistered", - "type": "dojo::world::world::SystemRegistered", + "name": "ModelRegistered", + "type": "dojo::world::world::ModelRegistered", "kind": "nested" }, { @@ -553,7 +531,7 @@ test_manifest_file { "name": "player_actions", "address": null, - "class_hash": "0x76e85c6abaa082687466201db4edc0427ca814c6a89d962b4c884ba365bee17", + "class_hash": "0xf28d16dc402498e8e945a5762776172ee690e0c3445257b38d73844eadfb4f", "abi": [ { "type": "impl", @@ -572,7 +550,7 @@ test_manifest_file }, { "type": "enum", - "name": "dojo_examples::components::Direction", + "name": "dojo_examples::models::Direction", "variants": [ { "name": "None", @@ -622,7 +600,7 @@ test_manifest_file }, { "name": "direction", - "type": "dojo_examples::components::Direction" + "type": "dojo_examples::models::Direction" } ], "outputs": [], @@ -653,7 +631,7 @@ test_manifest_file }, { "name": "direction", - "type": "dojo_examples::components::Direction", + "type": "dojo_examples::models::Direction", "kind": "data" } ] @@ -675,7 +653,7 @@ test_manifest_file { "name": "player_actions_external", "address": null, - "class_hash": "0x66af9023e04e381743a83314fbe1bb7dc63c9aeebee6bbeb96578423fe53a9d", + "class_hash": "0x49a96abd2a2e1148a290a7e0aa101e17653d0990456c6a400614534e3696e49", "abi": [ { "type": "impl", @@ -694,7 +672,7 @@ test_manifest_file }, { "type": "enum", - "name": "dojo_examples::components::Direction", + "name": "dojo_examples::models::Direction", "variants": [ { "name": "None", @@ -744,7 +722,7 @@ test_manifest_file }, { "name": "direction", - "type": "dojo_examples::components::Direction" + "type": "dojo_examples::models::Direction" } ], "outputs": [], @@ -764,7 +742,7 @@ test_manifest_file }, { "name": "direction", - "type": "dojo_examples::components::Direction", + "type": "dojo_examples::models::Direction", "kind": "data" } ] @@ -784,7 +762,7 @@ test_manifest_file ] } ], - "components": [ + "models": [ { "name": "Moves", "members": [ @@ -804,7 +782,7 @@ test_manifest_file "key": false } ], - "class_hash": "0x3dedf3d747db10aee693c0d034fcde1064ec66c84d285e60630f860dc9df566", + "class_hash": "0x3fc154aaf236e0478a5ea100b3d1971b30c70c14fa0e1a25606973ec75247a4", "abi": [ { "type": "function", @@ -947,7 +925,7 @@ test_manifest_file }, { "type": "event", - "name": "dojo_examples::components::moves::Event", + "name": "dojo_examples::models::moves::Event", "kind": "enum", "variants": [] } @@ -967,7 +945,7 @@ test_manifest_file "key": false } ], - "class_hash": "0x1b5f19668b9299cea232978c59856b16da649e6aa4dfc3f2a42aa8435e06bc7", + "class_hash": "0x7a812f2cfb414d5aa04bb9a3c91cdcaf1d30e193bd6cb7faf9b7c294722fab4", "abi": [ { "type": "function", @@ -1110,7 +1088,7 @@ test_manifest_file }, { "type": "event", - "name": "dojo_examples::components::position::Event", + "name": "dojo_examples::models::position::Event", "kind": "enum", "variants": [] } diff --git a/crates/dojo-lang/src/plugin.rs b/crates/dojo-lang/src/plugin.rs index 767fdf068f..4cf4656835 100644 --- a/crates/dojo-lang/src/plugin.rs +++ b/crates/dojo-lang/src/plugin.rs @@ -48,7 +48,7 @@ pub struct SystemAuxData { pub struct DojoAuxData { /// A list of models that were processed by the plugin. pub models: Vec, - /// A list of systems that were processed by the plugin and their component dependencies. + /// A list of systems that were processed by the plugin and their model dependencies. pub systems: Vec, } impl GeneratedFileAuxData for DojoAuxData { @@ -155,10 +155,10 @@ impl MacroPlugin for DojoPlugin { match derived.as_str() { "Model" => { - let (component_rewrite_nodes, component_diagnostics) = + let (model_rewrite_nodes, model_diagnostics) = handle_model_struct(db, &mut aux_data, struct_ast.clone()); - rewrite_nodes.push(component_rewrite_nodes); - diagnostics.extend(component_diagnostics); + rewrite_nodes.push(model_rewrite_nodes); + diagnostics.extend(model_diagnostics); } "Print" => { rewrite_nodes.push(derive_print(db, struct_ast.clone())); diff --git a/crates/dojo-lang/src/plugin_test_data/introspect b/crates/dojo-lang/src/plugin_test_data/introspect index aeed661cdf..be0d55726e 100644 --- a/crates/dojo-lang/src/plugin_test_data/introspect +++ b/crates/dojo-lang/src/plugin_test_data/introspect @@ -1,4 +1,4 @@ -//! > Test expansion of the component contract. +//! > Test expansion of the derive(Introspect). //! > test_runner_name test_expand_plugin diff --git a/crates/dojo-lang/src/plugin_test_data/model b/crates/dojo-lang/src/plugin_test_data/model index a5c09cb890..a60d0c5f57 100644 --- a/crates/dojo-lang/src/plugin_test_data/model +++ b/crates/dojo-lang/src/plugin_test_data/model @@ -1,4 +1,4 @@ -//! > Test expansion of the component contract. +//! > Test expansion of the derive(Model). //! > test_runner_name test_expand_plugin diff --git a/crates/dojo-lang/src/plugin_test_data/print b/crates/dojo-lang/src/plugin_test_data/print index b428f50a9d..cf138de450 100644 --- a/crates/dojo-lang/src/plugin_test_data/print +++ b/crates/dojo-lang/src/plugin_test_data/print @@ -1,4 +1,4 @@ -//! > Test expansion of the component contract. +//! > Test expansion of the derive(Print). //! > test_runner_name test_expand_plugin diff --git a/crates/dojo-lang/src/plugin_test_data/system b/crates/dojo-lang/src/plugin_test_data/system index 09c2d21c93..f6459214ab 100644 --- a/crates/dojo-lang/src/plugin_test_data/system +++ b/crates/dojo-lang/src/plugin_test_data/system @@ -1,4 +1,4 @@ -//! > Test expansion of the component contract. +//! > Test expansion of the #[system]. //! > test_runner_name test_expand_plugin diff --git a/crates/dojo-lang/src/print.rs b/crates/dojo-lang/src/print.rs index e48a9a956a..0506fa368c 100644 --- a/crates/dojo-lang/src/print.rs +++ b/crates/dojo-lang/src/print.rs @@ -7,7 +7,7 @@ use cairo_lang_utils::unordered_hash_map::UnorderedHashMap; /// Derives PrintTrait for a struct. /// Parameters: /// * db: The semantic database. -/// * struct_ast: The AST of the component struct. +/// * struct_ast: The AST of the model struct. /// Returns: /// * A RewriteNode containing the generated code. pub fn derive_print(db: &dyn SyntaxGroup, struct_ast: ItemStruct) -> RewriteNode { diff --git a/crates/dojo-types/src/event.rs b/crates/dojo-types/src/event.rs index f5b6f8ab23..38319ff684 100644 --- a/crates/dojo-types/src/event.rs +++ b/crates/dojo-types/src/event.rs @@ -7,21 +7,14 @@ pub struct WorldSpawned { pub caller: FieldElement, } -/// The event emitted when a system is registered to a World. +/// The event emitted when a model is registered to a World. #[derive(Clone, Debug)] -pub struct SystemRegistered { +pub struct ModelRegistered { pub name: String, pub class_hash: FieldElement, } -/// The event emitted when a component is registered to a World. -#[derive(Clone, Debug)] -pub struct ComponentRegistered { - pub name: String, - pub class_hash: FieldElement, -} - -/// The event emmitted when a component value of an entity is set. +/// The event emmitted when a model value of an entity is set. #[derive(Clone, Debug)] pub struct StoreSetRecord { pub table_id: FieldElement, @@ -30,7 +23,7 @@ pub struct StoreSetRecord { pub value: Vec, } -/// The event emmitted when a component is deleted from an entity. +/// The event emmitted when a model is deleted from an entity. #[derive(Clone, Debug)] pub struct StoreDelRecord { pub table_id: FieldElement, diff --git a/crates/dojo-types/src/lib.rs b/crates/dojo-types/src/lib.rs index a52c4b61ee..a794e8a319 100644 --- a/crates/dojo-types/src/lib.rs +++ b/crates/dojo-types/src/lib.rs @@ -1,5 +1,5 @@ -pub mod component; pub mod core; pub mod event; +pub mod model; pub mod storage; pub mod system; diff --git a/crates/dojo-types/src/component.rs b/crates/dojo-types/src/model.rs similarity index 99% rename from crates/dojo-types/src/component.rs rename to crates/dojo-types/src/model.rs index d454639700..c9cd6db080 100644 --- a/crates/dojo-types/src/component.rs +++ b/crates/dojo-types/src/model.rs @@ -1,6 +1,6 @@ use serde::{Deserialize, Serialize}; -/// Represents a component member. +/// Represents a model member. #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct Member { pub name: String, diff --git a/crates/dojo-types/src/system.rs b/crates/dojo-types/src/system.rs index e4853d0865..68472fe8c9 100644 --- a/crates/dojo-types/src/system.rs +++ b/crates/dojo-types/src/system.rs @@ -1,9 +1,9 @@ use serde::{Deserialize, Serialize}; -/// Represents a system's component dependency. +/// Represents a system's model dependency. #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct Dependency { - /// Name of the component. + /// Name of the model. pub name: String, pub read: bool, pub write: bool, diff --git a/crates/dojo-world/src/manifest.rs b/crates/dojo-world/src/manifest.rs index 3189f9c0e0..ef43909513 100644 --- a/crates/dojo-world/src/manifest.rs +++ b/crates/dojo-world/src/manifest.rs @@ -38,7 +38,7 @@ pub enum ManifestError { Provider(ProviderError), } -/// Represents a component member. +/// Represents a model member. #[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] pub struct Member { /// Name of the member. @@ -49,13 +49,13 @@ pub struct Member { pub key: bool, } -impl From for Member { - fn from(m: dojo_types::component::Member) -> Self { +impl From for Member { + fn from(m: dojo_types::model::Member) -> Self { Self { name: m.name, ty: m.ty.name(), key: m.key } } } -/// Represents a declaration of a component. +/// Represents a declaration of a model. #[serde_as] #[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq)] pub struct Model { @@ -112,7 +112,7 @@ pub struct Manifest { pub executor: Contract, pub systems: Vec, pub contracts: Vec, - pub components: Vec, + pub models: Vec, } impl Manifest { @@ -167,27 +167,27 @@ impl Manifest { })?; let mut systems = vec![]; - let mut components = vec![]; + let mut models = vec![]; if let Some(match_manifest) = match_manifest { - for component in match_manifest.components { + for model in match_manifest.models { let result = provider .call( FunctionCall { contract_address: world_address, calldata: vec![ - cairo_short_string_to_felt(&component.name) + cairo_short_string_to_felt(&model.name) .map_err(ManifestError::InvalidNameError)?, ], - entry_point_selector: get_selector_from_name("component").unwrap(), + entry_point_selector: get_selector_from_name("model").unwrap(), }, BlockId::Tag(BlockTag::Pending), ) .await .map_err(ManifestError::Provider)?; - components.push(Model { - name: component.name.clone(), + models.push(Model { + name: model.name.clone(), class_hash: result[0], ..Default::default() }); @@ -223,7 +223,7 @@ impl Manifest { Ok(Manifest { systems, - components, + models, contracts: vec![], world: Contract { name: WORLD_CONTRACT_NAME.into(), diff --git a/crates/dojo-world/src/migration/strategy.rs b/crates/dojo-world/src/migration/strategy.rs index 1c09bac90f..eea4d9271a 100644 --- a/crates/dojo-world/src/migration/strategy.rs +++ b/crates/dojo-world/src/migration/strategy.rs @@ -18,7 +18,7 @@ pub struct MigrationOutput { pub world: Option, pub executor: Option, pub contracts: Vec, - pub components: Option, + pub models: Option, } #[derive(Debug)] @@ -27,7 +27,7 @@ pub struct MigrationStrategy { pub world: Option, pub executor: Option, pub contracts: Vec, - pub components: Vec, + pub models: Vec, } #[derive(Debug)] @@ -67,7 +67,7 @@ impl MigrationStrategy { MigrationType::Update => update += 1, }); - self.components.iter().for_each(|item| match item.migration_type() { + self.models.iter().for_each(|item| match item.migration_type() { MigrationType::New => new += 1, MigrationType::Update => update += 1, }); @@ -113,8 +113,7 @@ where evaluate_contract_to_migrate(&diff.executor, &artifact_paths, world.is_some())?; let contracts = evaluate_contracts_to_migrate(&diff.contracts, &artifact_paths, world.is_some())?; - let components = - evaluate_components_to_migrate(&diff.components, &artifact_paths, world.is_some())?; + let models = evaluate_models_to_migrate(&diff.models, &artifact_paths, world.is_some())?; if let Some(executor) = &mut executor { executor.contract_address = @@ -135,17 +134,17 @@ where ); } - Ok(MigrationStrategy { world_address, world, executor, contracts, components }) + Ok(MigrationStrategy { world_address, world, executor, contracts, models }) } -fn evaluate_components_to_migrate( - components: &[ClassDiff], +fn evaluate_models_to_migrate( + models: &[ClassDiff], artifact_paths: &HashMap, world_contract_will_migrate: bool, ) -> Result> { let mut comps_to_migrate = vec![]; - for c in components { + for c in models { match c.remote { Some(remote) if remote == c.local && !world_contract_will_migrate => continue, _ => { diff --git a/crates/dojo-world/src/migration/world.rs b/crates/dojo-world/src/migration/world.rs index c06d082e65..52fd359b5d 100644 --- a/crates/dojo-world/src/migration/world.rs +++ b/crates/dojo-world/src/migration/world.rs @@ -15,7 +15,7 @@ pub struct WorldDiff { pub world: ContractDiff, pub executor: ContractDiff, pub contracts: Vec, - pub components: Vec, + pub models: Vec, pub systems: Vec, } @@ -37,14 +37,14 @@ impl WorldDiff { }) .collect::>(); - let components = local - .components + let models = local + .models .iter() - .map(|component| ClassDiff { - name: component.name.to_string(), - local: component.class_hash, + .map(|model| ClassDiff { + name: model.name.to_string(), + local: model.class_hash, remote: remote.as_ref().and_then(|m| { - m.components.iter().find(|e| e.name == component.name).map(|s| s.class_hash) + m.models.iter().find(|e| e.name == model.name).map(|s| s.class_hash) }), }) .collect::>(); @@ -71,7 +71,7 @@ impl WorldDiff { remote: remote.map(|m| m.world.class_hash), }; - WorldDiff { world, executor, systems, contracts, components } + WorldDiff { world, executor, systems, contracts, models } } pub fn count_diffs(&self) -> usize { @@ -86,7 +86,7 @@ impl WorldDiff { } count += self.systems.iter().filter(|s| !s.is_same()).count(); - count += self.components.iter().filter(|s| !s.is_same()).count(); + count += self.models.iter().filter(|s| !s.is_same()).count(); count += self.contracts.iter().filter(|s| !s.is_same()).count(); count } @@ -97,8 +97,8 @@ impl Display for WorldDiff { writeln!(f, "{}", self.world)?; writeln!(f, "{}", self.executor)?; - for component in &self.components { - writeln!(f, "{component}")?; + for model in &self.models { + writeln!(f, "{model}")?; } for system in &self.systems { diff --git a/crates/dojo-world/src/migration/world_test.rs b/crates/dojo-world/src/migration/world_test.rs index 0d9e0d4e9d..24118681dc 100644 --- a/crates/dojo-world/src/migration/world_test.rs +++ b/crates/dojo-world/src/migration/world_test.rs @@ -17,9 +17,9 @@ fn no_diff_when_local_and_remote_are_equal() { ..Default::default() }; - let components = vec![Model { + let models = vec![Model { members: vec![], - name: "Component".into(), + name: "Model".into(), class_hash: 11_u32.into(), ..Default::default() }]; @@ -28,7 +28,7 @@ fn no_diff_when_local_and_remote_are_equal() { vec![System { name: "System".into(), class_hash: 22_u32.into(), ..Default::default() }]; let local = Manifest { - components, + models, world: world_contract, executor: executor_contract, systems, @@ -55,9 +55,9 @@ fn diff_when_local_and_remote_are_different() { ..Default::default() }; - let components = vec![Model { + let models = vec![Model { members: vec![], - name: "Component".into(), + name: "Model".into(), class_hash: 11_u32.into(), ..Default::default() }]; @@ -66,7 +66,7 @@ fn diff_when_local_and_remote_are_different() { vec![System { name: "System".into(), class_hash: 22_u32.into(), ..Default::default() }]; let local = Manifest { - components, + models, world: world_contract, executor: executor_contract, systems, @@ -76,7 +76,7 @@ fn diff_when_local_and_remote_are_different() { let mut remote = local.clone(); remote.world.class_hash = 44_u32.into(); remote.executor.class_hash = 55_u32.into(); - remote.components[0].class_hash = 33_u32.into(); + remote.models[0].class_hash = 33_u32.into(); let diff = WorldDiff::compute(local, Some(remote)); diff --git a/crates/sozo/src/args.rs b/crates/sozo/src/args.rs index e52fd7b907..909c7ba10d 100644 --- a/crates/sozo/src/args.rs +++ b/crates/sozo/src/args.rs @@ -63,9 +63,9 @@ pub enum Commands { Test(TestArgs), #[command(about = "Execute a world's system")] Execute(ExecuteArgs), - #[command(about = "Interact with a worlds components")] + #[command(about = "Interact with a worlds models")] Model(ModelArgs), - #[command(about = "Register new systems and components")] + #[command(about = "Register new models")] Register(RegisterArgs), #[command(about = "Queries world events")] Events(EventsArgs), diff --git a/crates/sozo/src/commands/auth.rs b/crates/sozo/src/commands/auth.rs index 51366b3921..c004e386cb 100644 --- a/crates/sozo/src/commands/auth.rs +++ b/crates/sozo/src/commands/auth.rs @@ -18,8 +18,8 @@ pub struct AuthArgs { pub enum AuthCommand { #[command(about = "Auth a system with the given calldata.")] Writer { - #[arg(help = "Name of the component to grant write access to.")] - component: String, + #[arg(help = "Name of the model to grant write access to.")] + model: String, #[arg(help = "Name of the system to grant writer access to.")] system: String, diff --git a/crates/sozo/src/commands/events.rs b/crates/sozo/src/commands/events.rs index 254553dccc..eba63efc25 100644 --- a/crates/sozo/src/commands/events.rs +++ b/crates/sozo/src/commands/events.rs @@ -100,8 +100,8 @@ fn extract_events(manifest: &Manifest) -> HashMap> { inner_helper(&mut events_map, &contract.abi); } - for component in &manifest.components { - inner_helper(&mut events_map, &component.abi); + for model in &manifest.models { + inner_helper(&mut events_map, &model.abi); } events_map diff --git a/crates/sozo/src/commands/register.rs b/crates/sozo/src/commands/register.rs index 0e04d94a18..74cfa2ae22 100644 --- a/crates/sozo/src/commands/register.rs +++ b/crates/sozo/src/commands/register.rs @@ -17,13 +17,13 @@ pub struct RegisterArgs { #[derive(Debug, Subcommand)] pub enum RegisterCommand { - #[command(about = "Register a component to a world.")] - Component { + #[command(about = "Register a model to a world.")] + Model { #[arg(num_args = 1..)] #[arg(required = true)] #[arg(value_name = "CLASS_HASH")] - #[arg(help = "The class hash of the components to register.")] - components: Vec, + #[arg(help = "The class hash of the models to register.")] + models: Vec, #[command(flatten)] world: WorldOptions, diff --git a/crates/sozo/src/commands/scarb_internal/mod.rs b/crates/sozo/src/commands/scarb_internal/mod.rs index 6f216c16eb..a7f3379580 100644 --- a/crates/sozo/src/commands/scarb_internal/mod.rs +++ b/crates/sozo/src/commands/scarb_internal/mod.rs @@ -38,8 +38,8 @@ fn build_project_config(unit: &CompilationUnit) -> Result { let crate_roots = unit .components .iter() - .filter(|component| !component.package.id.is_core()) - .map(|component| (component.cairo_package_name(), component.target.source_root().into())) + .filter(|model| !model.package.id.is_core()) + .map(|model| (model.cairo_package_name(), model.target.source_root().into())) .collect(); let corelib = Some(Directory::Real(unit.core_package_component().target.source_root().into())); diff --git a/crates/sozo/src/commands/test.rs b/crates/sozo/src/commands/test.rs index 82a750101e..4bd21ce5d8 100644 --- a/crates/sozo/src/commands/test.rs +++ b/crates/sozo/src/commands/test.rs @@ -107,8 +107,8 @@ fn build_project_config(unit: &CompilationUnit) -> Result { let crate_roots = unit .components .iter() - .filter(|component| !component.package.id.is_core()) - .map(|component| (component.cairo_package_name(), component.target.source_root().into())) + .filter(|model| !model.package.id.is_core()) + .map(|model| (model.cairo_package_name(), model.target.source_root().into())) .collect(); let corelib = Some(Directory::Real(unit.core_package_component().target.source_root().into())); diff --git a/crates/sozo/src/ops/auth.rs b/crates/sozo/src/ops/auth.rs index 11d4af7d51..9e0b45262a 100644 --- a/crates/sozo/src/ops/auth.rs +++ b/crates/sozo/src/ops/auth.rs @@ -6,7 +6,7 @@ use crate::commands::auth::AuthCommand; pub async fn execute(command: AuthCommand, env_metadata: Option) -> Result<()> { match command { - AuthCommand::Writer { component, system, world, starknet, account } => { + AuthCommand::Writer { model, system, world, starknet, account } => { let world_address = world.address(env_metadata.as_ref())?; let provider = starknet.provider(env_metadata.as_ref())?; @@ -14,7 +14,7 @@ pub async fn execute(command: AuthCommand, env_metadata: Option) -> let world = WorldContract::new(world_address, &account); let res = world - .grant_writer(&component, &system) + .grant_writer(&model, &system) .await .with_context(|| "Failed to send transaction")?; diff --git a/crates/sozo/src/ops/events.rs b/crates/sozo/src/ops/events.rs index 184d552dfd..02aa24e260 100644 --- a/crates/sozo/src/ops/events.rs +++ b/crates/sozo/src/ops/events.rs @@ -78,7 +78,7 @@ fn parse_event( // Length is two only when its custom event if keys.len() == 2 { let name = parse_cairo_short_string(&keys[1]).ok()?; - ret.push_str(&format!("Component name: {}\n", name)); + ret.push_str(&format!("Model name: {}\n", name)); } match &e.kind { diff --git a/crates/sozo/src/ops/migration/migration_test.rs b/crates/sozo/src/ops/migration/migration_test.rs index 94d6975146..b8f9a6acd4 100644 --- a/crates/sozo/src/ops/migration/migration_test.rs +++ b/crates/sozo/src/ops/migration/migration_test.rs @@ -135,6 +135,6 @@ async fn migration_from_remote() { assert_eq!(local_manifest.world.class_hash, remote_manifest.world.class_hash); assert_eq!(local_manifest.executor.class_hash, remote_manifest.executor.class_hash); - assert_eq!(local_manifest.components.len(), remote_manifest.components.len()); + assert_eq!(local_manifest.models.len(), remote_manifest.models.len()); assert_eq!(local_manifest.systems.len(), remote_manifest.systems.len()); } diff --git a/crates/sozo/src/ops/migration/mod.rs b/crates/sozo/src/ops/migration/mod.rs index 62dcf9de00..e69f8ce41d 100644 --- a/crates/sozo/src/ops/migration/mod.rs +++ b/crates/sozo/src/ops/migration/mod.rs @@ -283,7 +283,7 @@ where None => {} }; - register_components(strategy, migrator, ui, txn_config.clone()).await?; + register_models(strategy, migrator, ui, txn_config.clone()).await?; deploy_contracts(strategy, migrator, ui, txn_config).await?; // This gets current block numder if helpful @@ -337,7 +337,7 @@ where } } -async fn register_components( +async fn register_models( strategy: &MigrationStrategy, migrator: &SingleOwnerAccount, ui: &Ui, @@ -347,17 +347,17 @@ where P: Provider + Sync + Send + 'static, S: Signer + Sync + Send + 'static, { - let components = &strategy.components; + let models = &strategy.models; - if components.is_empty() { + if models.is_empty() { return Ok(None); } - ui.print_header(format!("# Models ({})", components.len())); + ui.print_header(format!("# Models ({})", models.len())); let mut declare_output = vec![]; - for c in components.iter() { + for c in models.iter() { ui.print(italic_message(&c.diff.name).to_string()); let res = @@ -369,12 +369,12 @@ where declare_output.push(output); } - // Continue if component is already declared + // Continue if model is already declared Err(MigrationError::ClassAlreadyDeclared) => { ui.print_sub("Already declared"); continue; } - Err(e) => bail!("Failed to declare component {}: {e}", c.diff.name), + Err(e) => bail!("Failed to declare model {}: {e}", c.diff.name), } ui.print_sub(format!("Class hash: {:#x}", c.diff.local)); @@ -383,9 +383,9 @@ where let world_address = strategy.world_address()?; let InvokeTransactionResult { transaction_hash } = WorldContract::new(world_address, migrator) - .register_components(&components.iter().map(|c| c.diff.local).collect::>()) + .register_models(&models.iter().map(|c| c.diff.local).collect::>()) .await - .map_err(|e| anyhow!("Failed to register components to World: {e}"))?; + .map_err(|e| anyhow!("Failed to register models to World: {e}"))?; TransactionWaiter::new(transaction_hash, migrator.provider()).await?; diff --git a/crates/sozo/src/ops/model.rs b/crates/sozo/src/ops/model.rs index b2eb532341..b06bcf8b7b 100644 --- a/crates/sozo/src/ops/model.rs +++ b/crates/sozo/src/ops/model.rs @@ -12,9 +12,9 @@ pub async fn execute(command: ModelCommands, env_metadata: Option) let provider = starknet.provider(env_metadata.as_ref())?; let world = WorldContractReader::new(world_address, &provider); - let component = world.model(&name, BlockId::Tag(BlockTag::Pending)).await?; + let model = world.model(&name, BlockId::Tag(BlockTag::Pending)).await?; - println!("{:#x}", component.class_hash()); + println!("{:#x}", model.class_hash()); } ModelCommands::Schema { name, world, starknet, to_json } => { @@ -22,9 +22,9 @@ pub async fn execute(command: ModelCommands, env_metadata: Option) let provider = starknet.provider(env_metadata.as_ref())?; let world = WorldContractReader::new(world_address, &provider); - let component = world.model(&name, BlockId::Tag(BlockTag::Pending)).await?; + let model = world.model(&name, BlockId::Tag(BlockTag::Pending)).await?; - let schema = component.schema(BlockId::Tag(BlockTag::Pending)).await?; + let schema = model.schema(BlockId::Tag(BlockTag::Pending)).await?; if to_json { println!("{}", serde_json::to_string_pretty(&schema)?) @@ -38,9 +38,9 @@ pub async fn execute(command: ModelCommands, env_metadata: Option) let provider = starknet.provider(env_metadata.as_ref())?; let world = WorldContractReader::new(world_address, &provider); - let component = world.model(&name, BlockId::Tag(BlockTag::Pending)).await?; + let model = world.model(&name, BlockId::Tag(BlockTag::Pending)).await?; - let entity = component.entity(keys, BlockId::Tag(BlockTag::Pending)).await?; + let entity = model.entity(keys, BlockId::Tag(BlockTag::Pending)).await?; println!( "{}", diff --git a/crates/sozo/src/ops/register.rs b/crates/sozo/src/ops/register.rs index 9325f0dbab..738fa394a7 100644 --- a/crates/sozo/src/ops/register.rs +++ b/crates/sozo/src/ops/register.rs @@ -6,7 +6,7 @@ use crate::commands::register::RegisterCommand; pub async fn execute(command: RegisterCommand, env_metadata: Option) -> Result<()> { match command { - RegisterCommand::Component { components, world, starknet, account } => { + RegisterCommand::Model { models, world, starknet, account } => { let world_address = world.address(env_metadata.as_ref())?; let provider = starknet.provider(env_metadata.as_ref())?; @@ -14,11 +14,11 @@ pub async fn execute(command: RegisterCommand, env_metadata: Option let world = WorldContract::new(world_address, &account); let res = world - .register_components(&components) + .register_models(&models) .await .with_context(|| "Failed to send transaction")?; - println!("Components registered at transaction: {:#x}", res.transaction_hash) + println!("Models registered at transaction: {:#x}", res.transaction_hash) } } Ok(()) diff --git a/crates/torii/client/src/contract/model.rs b/crates/torii/client/src/contract/model.rs index 48700ed8ee..c968239b7e 100644 --- a/crates/torii/client/src/contract/model.rs +++ b/crates/torii/client/src/contract/model.rs @@ -1,7 +1,7 @@ use std::vec; use crypto_bigint::U256; -use dojo_types::component::{Enum, Member, Struct, Ty}; +use dojo_types::model::{Enum, Member, Struct, Ty}; use starknet::core::types::{BlockId, FieldElement, FunctionCall}; use starknet::core::utils::{ cairo_short_string_to_felt, get_selector_from_name, parse_cairo_short_string, @@ -55,7 +55,7 @@ impl<'a, P: Provider + Sync> ModelReader<'a, P> { FunctionCall { contract_address: world.address, calldata: vec![name], - entry_point_selector: get_selector_from_name("component").unwrap(), + entry_point_selector: get_selector_from_name("model").unwrap(), }, block_id, ) @@ -161,8 +161,8 @@ impl<'a, P: Provider + Sync> ModelReader<'a, P> { /// /// # Returns /// -/// * `Result, ComponentError>` - A Result containing a vector of -/// unpacked FieldElement values if successful, or an error if unsuccessful. +/// * `Result, ModelError>` - A Result containing a vector of unpacked +/// FieldElement values if successful, or an error if unsuccessful. pub fn unpack( mut packed: Vec, layout: Vec, diff --git a/crates/torii/client/src/contract/model_test.rs b/crates/torii/client/src/contract/model_test.rs index b69080b733..8bdf412051 100644 --- a/crates/torii/client/src/contract/model_test.rs +++ b/crates/torii/client/src/contract/model_test.rs @@ -2,7 +2,7 @@ use camino::Utf8PathBuf; use dojo_test_utils::sequencer::{ get_default_test_starknet_config, SequencerConfig, TestSequencer, }; -use dojo_types::component::{Enum, Member, Struct, Ty}; +use dojo_types::model::{Enum, Member, Struct, Ty}; use starknet::accounts::ConnectedAccount; use starknet::core::types::{BlockId, BlockTag, FieldElement}; @@ -62,7 +62,7 @@ async fn test_model() { assert_eq!( position.class_hash(), FieldElement::from_hex_be( - "0x01b5f19668b9299cea232978c59856b16da649e6aa4dfc3f2a42aa8435e06bc7" + "0x07a812f2cfb414d5aa04bb9a3c91cdcaf1d30e193bd6cb7faf9b7c294722fab4" ) .unwrap() ); diff --git a/crates/torii/client/src/contract/world.rs b/crates/torii/client/src/contract/world.rs index 2bcf7d21cb..135b3618ac 100644 --- a/crates/torii/client/src/contract/world.rs +++ b/crates/torii/client/src/contract/world.rs @@ -60,14 +60,14 @@ impl<'a, A: ConnectedAccount + Sync> WorldContract<'a, A> { InvokeTransactionResult, WorldContractError::Error>, > { - let component = cairo_short_string_to_felt(model) + let model = cairo_short_string_to_felt(model) .map_err(WorldContractError::CairoShortStringToFeltError)?; let system = cairo_short_string_to_felt(system) .map_err(WorldContractError::CairoShortStringToFeltError)?; self.account .execute(vec![Call { - calldata: vec![component, system], + calldata: vec![model, system], to: self.address, selector: get_selector_from_name("grant_writer").unwrap(), }]) @@ -76,22 +76,16 @@ impl<'a, A: ConnectedAccount + Sync> WorldContract<'a, A> { .map_err(WorldContractError::AccountError) } - pub async fn register_components( + pub async fn register_models( &self, - components: &[FieldElement], + models: &[FieldElement], ) -> Result::Error>> { - let calls = components + let calls = models .iter() .map(|c| Call { to: self.address, - // function selector: "register_component" - selector: FieldElement::from_mont([ - 11981012454229264524, - 8784065169116922201, - 15056747385353365869, - 456849768949735353, - ]), + selector: get_selector_from_name("register_model").unwrap(), calldata: vec![*c], }) .collect::>(); @@ -115,7 +109,7 @@ impl<'a, A: ConnectedAccount + Sync> WorldContract<'a, A> { self.reader.call(system, calldata, block_id).await } - pub async fn component( + pub async fn model( &'a self, name: &str, block_id: BlockId, @@ -146,7 +140,7 @@ impl<'a, P: Provider + Sync> WorldContractReader<'a, P> { pub async fn is_authorized( &self, system: &str, - component: &str, + model: &str, execution_role: &str, block_id: BlockId, ) -> Result> { @@ -158,7 +152,7 @@ impl<'a, P: Provider + Sync> WorldContractReader<'a, P> { calldata: vec![ cairo_short_string_to_felt(system) .map_err(ContractReaderError::CairoShortStringToFeltError)?, - cairo_short_string_to_felt(component) + cairo_short_string_to_felt(model) .map_err(ContractReaderError::CairoShortStringToFeltError)?, cairo_short_string_to_felt(execution_role) .map_err(ContractReaderError::CairoShortStringToFeltError)?, diff --git a/crates/torii/client/src/contract/world_test.rs b/crates/torii/client/src/contract/world_test.rs index 27ec3c6130..450efaffc0 100644 --- a/crates/torii/client/src/contract/world_test.rs +++ b/crates/torii/client/src/contract/world_test.rs @@ -71,8 +71,8 @@ pub async fn deploy_world( .contract_address; let mut declare_output = vec![]; - for component in strategy.components { - let res = component.declare(&account, Default::default()).await.unwrap(); + for model in strategy.models { + let res = model.declare(&account, Default::default()).await.unwrap(); declare_output.push(res); } @@ -80,7 +80,7 @@ pub async fn deploy_world( tokio::time::sleep(Duration::from_millis(250)).await; let _ = WorldContract::new(world_address, &account) - .register_components(&declare_output.iter().map(|o| o.class_hash).collect::>()) + .register_models(&declare_output.iter().map(|o| o.class_hash).collect::>()) .await .unwrap(); diff --git a/crates/torii/client/src/provider/jsonrpc.rs b/crates/torii/client/src/provider/jsonrpc.rs index 6235eccc5e..2244855ee9 100644 --- a/crates/torii/client/src/provider/jsonrpc.rs +++ b/crates/torii/client/src/provider/jsonrpc.rs @@ -45,7 +45,7 @@ where { type Error = JsonRpcProviderError>; - async fn component(&self, name: &str) -> Result { + async fn model(&self, name: &str) -> Result { let world = self.world(); let class_hash = world .model(name, self.block_id) @@ -57,14 +57,14 @@ where async fn entity( &self, - component: &str, + model: &str, keys: Vec, ) -> Result, Self::Error> { let world = self.world(); - let component = world - .model(component, self.block_id) + let model = world + .model(model, self.block_id) .await .map_err(JsonRpcProviderError::ComponetReader)?; - component.entity(keys, self.block_id).await.map_err(JsonRpcProviderError::ComponetReader) + model.entity(keys, self.block_id).await.map_err(JsonRpcProviderError::ComponetReader) } } diff --git a/crates/torii/client/src/provider/mod.rs b/crates/torii/client/src/provider/mod.rs index e7ffa683d6..8863d2b9d0 100644 --- a/crates/torii/client/src/provider/mod.rs +++ b/crates/torii/client/src/provider/mod.rs @@ -10,13 +10,13 @@ pub mod jsonrpc; pub trait Provider { type Error: Error + Send + Sync; - /// Get the class hash of a component. - async fn component(&self, name: &str) -> Result; + /// Get the class hash of a model. + async fn model(&self, name: &str) -> Result; - /// Get the component values of an entity. + /// Get the model values of an entity. async fn entity( &self, - component: &str, + model: &str, keys: Vec, ) -> Result, Self::Error>; } diff --git a/crates/torii/client/src/storage.rs b/crates/torii/client/src/storage.rs index b26393b87f..4f7926e213 100644 --- a/crates/torii/client/src/storage.rs +++ b/crates/torii/client/src/storage.rs @@ -14,7 +14,7 @@ pub trait EntityStorage { /// This function mimic `world::set_entity` of `dojo-core` async fn set( &mut self, - component: FieldElement, + model: FieldElement, keys: Vec, values: Vec, ) -> Result<(), Self::Error>; @@ -22,16 +22,13 @@ pub trait EntityStorage { /// This function mimic `world::entity` of `dojo-core` async fn get( &self, - component: FieldElement, + model: FieldElement, keys: Vec, length: usize, ) -> Result, Self::Error>; } -pub fn component_storage_base_address( - component: FieldElement, - keys: &[FieldElement], -) -> FieldElement { +pub fn model_storage_base_address(model: FieldElement, keys: &[FieldElement]) -> FieldElement { let id = poseidon_hash_many(keys); - poseidon_hash_many(&[short_string!("dojo_storage"), component, id]) + poseidon_hash_many(&[short_string!("dojo_storage"), model, id]) } diff --git a/crates/torii/client/src/sync.rs b/crates/torii/client/src/sync.rs index ed6e42eda2..f1162bb547 100644 --- a/crates/torii/client/src/sync.rs +++ b/crates/torii/client/src/sync.rs @@ -23,24 +23,24 @@ pub enum ClientError { Storage(S), } -/// Request to sync a component of an entity. +/// Request to sync a model of an entity. #[cfg_attr(target_arch = "wasm32", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, Clone, Hash, Eq, PartialEq)] pub struct Entity { - /// Component name - pub component: String, + /// Model name + pub model: String, /// The entity keys pub keys: Vec, } -/// A client to sync entity components from the World. +/// A client to sync entity models from the World. pub struct Client { // We wrap it in an Arc to allow sharing the storage between threads. - /// Storage to store the synced entity component values. + /// Storage to store the synced entity model values. storage: Arc>, - /// A provider implementation to query the World for entity components. + /// A provider implementation to query the World for entity models. provider: P, - /// The entity components to sync. + /// The entity models to sync. pub sync_entities: RwLock>, /// The interval to run the syncing loop. @@ -117,7 +117,7 @@ where for entity in entities { let values = self .provider - .entity(&entity.component, entity.keys.clone()) + .entity(&entity.model, entity.keys.clone()) .await .map_err(ClientError::Provider)?; @@ -125,11 +125,7 @@ where self.storage .write() .await - .set( - cairo_short_string_to_felt(&entity.component).unwrap(), - entity.keys, - values, - ) + .set(cairo_short_string_to_felt(&entity.model).unwrap(), entity.keys, values) .await .map_err(ClientError::Storage)?; @@ -137,11 +133,7 @@ where self.storage .write() .await - .set( - cairo_short_string_to_felt(&entity.component).unwrap(), - entity.keys, - values, - ) + .set(cairo_short_string_to_felt(&entity.model).unwrap(), entity.keys, values) .await .map_err(ClientError::Storage)?; } diff --git a/crates/torii/client/wasm/index.js b/crates/torii/client/wasm/index.js index 0707f32d80..62419c9f8b 100644 --- a/crates/torii/client/wasm/index.js +++ b/crates/torii/client/wasm/index.js @@ -16,10 +16,10 @@ async function run_wasm() { const event = e.data.type; const data = e.data.data; - if (event === "getComponentValue") { + if (event === "getModelValue") { console.log( - "Main thread | component: ", - data.component, + "Main thread | model: ", + data.model, "keys: ", data.keys, "values: ", @@ -35,7 +35,7 @@ async function run_wasm() { syncWorker.postMessage({ type: "addEntityToSync", data: { - component: "Position", + model: "Position", keys: [ "0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973", ], @@ -45,9 +45,9 @@ async function run_wasm() { setInterval(() => { // Get the entity values from the sync worker syncWorker.postMessage({ - type: "getComponentValue", + type: "getModelValue", data: { - component: "Position", + model: "Position", keys: [ "0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973", ], diff --git a/crates/torii/client/wasm/src/lib.rs b/crates/torii/client/wasm/src/lib.rs index 6a021ff038..15a4fea46f 100644 --- a/crates/torii/client/wasm/src/lib.rs +++ b/crates/torii/client/wasm/src/lib.rs @@ -22,7 +22,7 @@ pub struct WasmClient(Client>); #[wasm_bindgen] impl WasmClient { /// Create an instance of the client. This will create an instance of the client - /// without any entity components to sync. + /// without any entity models to sync. /// /// # Arguments /// * `url` - The url of the Starknet JSON-RPC provider. @@ -46,11 +46,11 @@ impl WasmClient { self.0.start().await.map_err(|e| JsValue::from_str(&e.to_string())) } - /// Returns the component values of the requested entity keys. - #[wasm_bindgen(js_name = getComponentValue)] - pub async fn get_component_value( + /// Returns the model values of the requested entity keys. + #[wasm_bindgen(js_name = getModelValue)] + pub async fn get_model_value( &self, - component: &str, + model: &str, keys: JsValue, length: usize, ) -> Result { @@ -63,7 +63,7 @@ impl WasmClient { .read() .await .get( - cairo_short_string_to_felt(component) + cairo_short_string_to_felt(model) .map_err(|e| JsValue::from_str(&e.to_string()))?, keys, length, diff --git a/crates/torii/client/wasm/src/storage.rs b/crates/torii/client/wasm/src/storage.rs index 999c70c27d..df87cb387c 100644 --- a/crates/torii/client/wasm/src/storage.rs +++ b/crates/torii/client/wasm/src/storage.rs @@ -3,12 +3,12 @@ use std::collections::HashMap; use async_trait::async_trait; use serde::{Deserialize, Serialize}; use starknet::core::types::FieldElement; -use torii_client::storage::{component_storage_base_address, EntityStorage}; +use torii_client::storage::{model_storage_base_address, EntityStorage}; /// Simple in memory implementation of [EntityStorage] #[derive(Serialize, Deserialize)] pub struct InMemoryStorage { - /// storage key -> Component value + /// storage key -> Model value pub inner: HashMap, } @@ -29,11 +29,11 @@ impl EntityStorage for InMemoryStorage { async fn set( &mut self, - component: FieldElement, + model: FieldElement, keys: Vec, values: Vec, ) -> Result<(), Self::Error> { - let base_address = component_storage_base_address(component, &keys); + let base_address = model_storage_base_address(model, &keys); for (offset, value) in values.into_iter().enumerate() { self.inner.insert(base_address + offset.into(), value); } @@ -42,11 +42,11 @@ impl EntityStorage for InMemoryStorage { async fn get( &self, - component: FieldElement, + model: FieldElement, keys: Vec, length: usize, ) -> Result, Self::Error> { - let base_address = component_storage_base_address(component, &keys); + let base_address = model_storage_base_address(model, &keys); let mut values = Vec::with_capacity(length); for i in 0..length { let address = base_address + i.into(); diff --git a/crates/torii/client/wasm/worker.js b/crates/torii/client/wasm/worker.js index fc237045d2..5beb1b6af0 100644 --- a/crates/torii/client/wasm/worker.js +++ b/crates/torii/client/wasm/worker.js @@ -25,8 +25,8 @@ async function setup() { const event = e.data.type; const data = e.data.data; - if (event === "getComponentValue") { - getComponentValueHandler(client, data); + if (event === "getModelValue") { + getModelValueHandler(client, data); } else if (event === "addEntityToSync") { addEntityToSyncHandler(client, data); } else { @@ -42,19 +42,19 @@ function addEntityToSyncHandler(client, data) { /// Handler for the `get_entity` event from the main thread. /// Returns back the entity data to the main thread via `postMessage`. -async function getComponentValueHandler(client, data) { - console.log("Sync Worker | Getting component value | data: ", data); +async function getModelValueHandler(client, data) { + console.log("Sync Worker | Getting model value | data: ", data); - const component = data.component; + const model = data.model; const keys = data.keys; const length = data.length; - const values = await client.getComponentValue(component, keys, length); + const values = await client.getModelValue(model, keys, length); self.postMessage({ - type: "getComponentValue", + type: "getModelValue", data: { - component: "Position", + model: "Position", keys, values, }, diff --git a/crates/torii/core/src/processors/register_model.rs b/crates/torii/core/src/processors/register_model.rs index e9e754e39c..e97a8bdd0e 100644 --- a/crates/torii/core/src/processors/register_model.rs +++ b/crates/torii/core/src/processors/register_model.rs @@ -15,7 +15,7 @@ pub struct RegisterModelProcessor; #[async_trait] impl EventProcessor

for RegisterModelProcessor { fn event_key(&self) -> String { - "ComponentRegistered".to_string() + "ModelRegistered".to_string() } async fn process( diff --git a/crates/torii/core/src/processors/store_set_record.rs b/crates/torii/core/src/processors/store_set_record.rs index f67f04b652..ff178dcca0 100644 --- a/crates/torii/core/src/processors/store_set_record.rs +++ b/crates/torii/core/src/processors/store_set_record.rs @@ -13,7 +13,7 @@ use crate::sql::Sql; #[derive(Default)] pub struct StoreSetRecordProcessor; -const COMPONENT_INDEX: usize = 0; +const MODEL_INDEX: usize = 0; const NUM_KEYS_INDEX: usize = 1; #[async_trait] @@ -31,7 +31,7 @@ impl EventProcessor

for StoreSetRecordProcessor { _transaction_receipt: &InvokeTransactionReceipt, event: &Event, ) -> Result<(), Error> { - let name = parse_cairo_short_string(&event.data[COMPONENT_INDEX])?; + let name = parse_cairo_short_string(&event.data[MODEL_INDEX])?; info!("store set record: {}", name); let keys = values_at(&event.data, NUM_KEYS_INDEX)?; diff --git a/crates/torii/core/src/sql.rs b/crates/torii/core/src/sql.rs index 7d9d100c87..144dcdc09d 100644 --- a/crates/torii/core/src/sql.rs +++ b/crates/torii/core/src/sql.rs @@ -3,8 +3,8 @@ use std::str::FromStr; use anyhow::Result; use async_trait::async_trait; use chrono::{DateTime, Utc}; -use dojo_types::component::Ty; use dojo_types::core::CairoType; +use dojo_types::model::Ty; use dojo_world::manifest::{Manifest, System}; use sqlx::pool::PoolConnection; use sqlx::sqlite::SqliteRow; diff --git a/crates/torii/core/src/sql_test.rs b/crates/torii/core/src/sql_test.rs index 5a1c9d36e3..96163e0582 100644 --- a/crates/torii/core/src/sql_test.rs +++ b/crates/torii/core/src/sql_test.rs @@ -1,5 +1,5 @@ use camino::Utf8PathBuf; -use dojo_types::component::{Member, Struct, Ty}; +use dojo_types::model::{Member, Struct, Ty}; use dojo_world::manifest::System; use sqlx::sqlite::SqlitePool; use starknet::core::types::{Event, FieldElement}; diff --git a/crates/torii/graphql/src/object/mod.rs b/crates/torii/graphql/src/object/mod.rs index 2a2d9215ac..a8c61b038e 100644 --- a/crates/torii/graphql/src/object/mod.rs +++ b/crates/torii/graphql/src/object/mod.rs @@ -96,7 +96,7 @@ pub trait ObjectTrait { }; } - // Component union queries is a special case, it instead passes down a + // Model union queries is a special case, it instead passes down a // IndexMap. This could be avoided if // async-graphql allowed union resolver to be passed down as Value. if let Some(indexmap) = ctx.parent_value.downcast_ref::() { diff --git a/crates/torii/graphql/src/tests/subscription_test.rs b/crates/torii/graphql/src/tests/subscription_test.rs index dea292bdb2..3673ea21cd 100644 --- a/crates/torii/graphql/src/tests/subscription_test.rs +++ b/crates/torii/graphql/src/tests/subscription_test.rs @@ -3,7 +3,7 @@ mod tests { use std::time::Duration; use async_graphql::value; - use dojo_types::component::{Member, Struct, Ty}; + use dojo_types::model::{Member, Struct, Ty}; use sqlx::SqlitePool; use starknet_crypto::{poseidon_hash_many, FieldElement}; use tokio::sync::mpsc; diff --git a/examples/ecs/README.md b/examples/ecs/README.md index 311deed032..2571aeb003 100644 --- a/examples/ecs/README.md +++ b/examples/ecs/README.md @@ -11,20 +11,20 @@ sozo build # Migrate the world sozo migrate -# Get the class hash of the Moves component by name -sozo component get --world 0x26065106fa319c3981618e7567480a50132f23932226a51c219ffb8e47daa84 Moves +# Get the class hash of the Moves model by name +sozo model get --world 0x26065106fa319c3981618e7567480a50132f23932226a51c219ffb8e47daa84 Moves > 0x2b97f0b24be59ecf4504a27ac2301179be7df44c4c7d9482cd7b36137bc0fa4 -# Get the schema of the Moves component -sozo component schema --world 0x26065106fa319c3981618e7567480a50132f23932226a51c219ffb8e47daa84 Moves +# Get the schema of the Moves model +sozo model schema --world 0x26065106fa319c3981618e7567480a50132f23932226a51c219ffb8e47daa84 Moves > struct Moves { > remaining: u8 > } -# Get the value of the Moves component for an entity. (in this example, +# Get the value of the Moves model for an entity. (in this example, # 0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973 is # the calling account. -sozo component entity --world 0x26065106fa319c3981618e7567480a50132f23932226a51c219ffb8e47daa84 Moves 0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973 +sozo model entity --world 0x26065106fa319c3981618e7567480a50132f23932226a51c219ffb8e47daa84 Moves 0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973 > 0x0 # The returned value is 0 since we haven't spawned yet. Let's spawn @@ -32,6 +32,6 @@ sozo component entity --world 0x26065106fa319c3981618e7567480a50132f23932226a51c sozo execute --world 0x26065106fa319c3981618e7567480a50132f23932226a51c219ffb8e47daa84 spawn # Fetch the updated entity -sozo component entity --world 0x26065106fa319c3981618e7567480a50132f23932226a51c219ffb8e47daa84 Moves 0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973 +sozo model entity --world 0x26065106fa319c3981618e7567480a50132f23932226a51c219ffb8e47daa84 Moves 0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973 > 0xa ``` diff --git a/examples/ecs/Scarb.toml b/examples/ecs/Scarb.toml index daacfcdc19..d9ef9bfbee 100644 --- a/examples/ecs/Scarb.toml +++ b/examples/ecs/Scarb.toml @@ -11,18 +11,7 @@ dojo = { path = "../../crates/dojo-core" } # dojo_erc = { path = "../../crates/dojo-erc" } [[target.dojo]] -build-external-contracts = [ - # "dojo_erc::erc721::components::Balance", - # "dojo_erc::erc721::components::OperatorApproval", - # "dojo_erc::erc721::components::Owner", - # "dojo_erc::erc721::components::TokenApproval", - # "dojo_erc::erc721::erc721::ERC721", - # "dojo_erc::erc721::systems::erc721_approve", - # "dojo_erc::erc721::systems::erc721_burn", - # "dojo_erc::erc721::systems::erc721_mint", - # "dojo_erc::erc721::systems::erc721_set_approval_for_all", - # "dojo_erc::erc721::systems::erc721_transfer_from", -] +build-external-contracts = [] [tool.dojo] initializer_class_hash = "0xbeef" diff --git a/examples/ecs/src/lib.cairo b/examples/ecs/src/lib.cairo index 1a585cb71d..b0a80e56b0 100644 --- a/examples/ecs/src/lib.cairo +++ b/examples/ecs/src/lib.cairo @@ -1,4 +1,4 @@ -mod components; +mod models; mod systems { // example with #[system] decorator diff --git a/examples/ecs/src/components.cairo b/examples/ecs/src/models.cairo similarity index 100% rename from examples/ecs/src/components.cairo rename to examples/ecs/src/models.cairo diff --git a/examples/ecs/src/systems/raw_contract.cairo b/examples/ecs/src/systems/raw_contract.cairo index 26e751330b..32f405dec6 100644 --- a/examples/ecs/src/systems/raw_contract.cairo +++ b/examples/ecs/src/systems/raw_contract.cairo @@ -1,5 +1,5 @@ use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; -use dojo_examples::components::{Direction}; +use dojo_examples::models::{Direction}; // trait: specify functions to implement #[starknet::interface] @@ -14,7 +14,7 @@ trait IPlayerActions { mod player_actions_external { use starknet::{ContractAddress, get_caller_address}; use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; - use dojo_examples::components::{Position, Moves, Direction, Vec2}; + use dojo_examples::models::{Position, Moves, Direction, Vec2}; use dojo_examples::utils::next_position; use super::IPlayerActions; @@ -69,8 +69,8 @@ mod tests { use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; use dojo::test_utils::{spawn_test_world, deploy_contract}; - use dojo_examples::components::{position, moves}; - use dojo_examples::components::{Position, Moves, Direction, Vec2}; + use dojo_examples::models::{position, moves}; + use dojo_examples::models::{Position, Moves, Direction, Vec2}; use super::{ IPlayerActionsDispatcher, IPlayerActionsDispatcherTrait, @@ -82,10 +82,10 @@ mod tests { fn test_move() { let caller = starknet::contract_address_const::<0x0>(); - // components - let mut components = array![position::TEST_CLASS_HASH, moves::TEST_CLASS_HASH,]; - // deploy world with components - let world = spawn_test_world(components); + // models + let mut models = array![position::TEST_CLASS_HASH, moves::TEST_CLASS_HASH,]; + // deploy world with models + let world = spawn_test_world(models); // deploy systems contract let contract_address = deploy_contract(player_actions::TEST_CLASS_HASH, array![].span()); diff --git a/examples/ecs/src/systems/with_decorator.cairo b/examples/ecs/src/systems/with_decorator.cairo index 0bad00ab9b..4214e1026d 100644 --- a/examples/ecs/src/systems/with_decorator.cairo +++ b/examples/ecs/src/systems/with_decorator.cairo @@ -1,5 +1,5 @@ use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; -use dojo_examples::components::{Position, Moves, Direction}; +use dojo_examples::models::{Position, Moves, Direction}; use starknet::{ContractAddress, ClassHash}; // trait: specify functions to implement @@ -12,7 +12,7 @@ trait IPlayerActions { #[system] mod player_actions { use starknet::{ContractAddress, get_caller_address}; - use dojo_examples::components::{Position, Moves, Direction, Vec2}; + use dojo_examples::models::{Position, Moves, Direction, Vec2}; use dojo_examples::utils::next_position; use super::IPlayerActions; @@ -66,8 +66,8 @@ mod tests { use dojo::test_utils::{spawn_test_world, deploy_contract}; - use dojo_examples::components::{position, moves}; - use dojo_examples::components::{Position, Moves, Direction, Vec2}; + use dojo_examples::models::{position, moves}; + use dojo_examples::models::{Position, Moves, Direction, Vec2}; use super::{player_actions, IPlayerActionsDispatcher, IPlayerActionsDispatcherTrait}; #[test] @@ -75,10 +75,10 @@ mod tests { fn test_move() { let caller = starknet::contract_address_const::<0x0>(); - // components - let mut components = array![position::TEST_CLASS_HASH, moves::TEST_CLASS_HASH,]; - // deploy world with components - let world = spawn_test_world(components); + // models + let mut models = array![position::TEST_CLASS_HASH, moves::TEST_CLASS_HASH,]; + // deploy world with models + let world = spawn_test_world(models); // deploy systems contract let contract_address = deploy_contract(player_actions::TEST_CLASS_HASH, array![].span()); diff --git a/examples/ecs/src/utils.cairo b/examples/ecs/src/utils.cairo index 586cea42ce..ca5c5714f1 100644 --- a/examples/ecs/src/utils.cairo +++ b/examples/ecs/src/utils.cairo @@ -1,4 +1,4 @@ -use dojo_examples::components::{Position, Direction}; +use dojo_examples::models::{Position, Direction}; fn next_position(mut position: Position, direction: Direction) -> Position { match direction {