diff --git a/bin/sozo/src/commands/build.rs b/bin/sozo/src/commands/build.rs index 1f2d4598a3..91a7ba15b3 100644 --- a/bin/sozo/src/commands/build.rs +++ b/bin/sozo/src/commands/build.rs @@ -1,5 +1,5 @@ use anyhow::{Context, Result}; -use clap::Args; +use clap::{Args, Parser}; use dojo_bindgen::{BuiltinPlugins, PluginManager}; use dojo_lang::scarb_internal::compile_workspace; use dojo_world::manifest::MANIFESTS_DIR; @@ -7,7 +7,8 @@ use dojo_world::metadata::dojo_metadata_from_workspace; use prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE; use prettytable::{format, Cell, Row, Table}; use scarb::core::{Config, TargetKind}; -use scarb::ops::{CompileOpts, FeaturesOpts, FeaturesSelector}; +use scarb::ops::CompileOpts; +use scarb_ui::args::FeaturesSpec; use sozo_ops::statistics::{get_contract_statistics_for_dir, ContractStatistics}; use tracing::trace; @@ -18,7 +19,7 @@ const CONTRACT_CLASS_SIZE_LABEL: &str = "Contract Class size [in bytes]\n(Sierra const CONTRACT_NAME_LABEL: &str = "Contract"; -#[derive(Debug, Args, Default)] +#[derive(Debug, Args)] pub struct BuildArgs { // Should we deprecate typescript bindings codegen? // Disabled due to lack of support in dojo.js @@ -39,6 +40,10 @@ pub struct BuildArgs { #[arg(long, help = "Display statistics about the compiled contracts")] pub stats: bool, + + /// Specify the features to activate. + #[command(flatten)] + pub features: FeaturesSpec, } impl BuildArgs { @@ -71,9 +76,7 @@ impl BuildArgs { let profile_dir = manifest_dir.join(MANIFESTS_DIR).join(profile_name); CleanArgs::clean_manifests(&profile_dir)?; - - let features_opts = - FeaturesOpts { features: FeaturesSelector::AllFeatures, no_default_features: false }; + let packages: Vec = ws.members().map(|p| p.id).collect(); let compile_info = compile_workspace( config, @@ -81,8 +84,9 @@ impl BuildArgs { include_target_names: vec![], include_target_kinds: vec![], exclude_target_kinds: vec![TargetKind::TEST], - features: features_opts, + features: self.features.try_into()?, }, + packages, )?; trace!(?compile_info, "Compiled workspace."); @@ -153,6 +157,21 @@ impl BuildArgs { } } +impl Default for BuildArgs { + fn default() -> Self { + // use the clap defaults + let features = FeaturesSpec::parse_from([""]); + + Self { + features, + typescript_v2: false, + unity: false, + bindings_output: "bindings".to_string(), + stats: false, + } + } +} + fn create_stats_table(mut contracts_statistics: Vec) -> Table { let mut table = Table::new(); table.set_format(*FORMAT_NO_LINESEP_WITH_TITLE); @@ -219,6 +238,7 @@ mod tests { unity: true, typescript_v2: true, stats: true, + ..Default::default() }; let result = build_args.run(&config); assert!(result.is_ok()); diff --git a/bin/sozo/src/commands/test.rs b/bin/sozo/src/commands/test.rs index 19f8279f18..637a8daa9e 100644 --- a/bin/sozo/src/commands/test.rs +++ b/bin/sozo/src/commands/test.rs @@ -14,8 +14,9 @@ use dojo_lang::plugin::dojo_plugin_suite; use dojo_lang::scarb_internal::crates_config_for_compilation_unit; use scarb::compiler::helpers::collect_main_crate_ids; use scarb::compiler::{CairoCompilationUnit, CompilationUnit, CompilationUnitAttributes}; -use scarb::core::Config; -use scarb::ops::{self, FeaturesOpts, FeaturesSelector}; +use scarb::core::{Config, TargetKind}; +use scarb::ops::{self, CompileOpts}; +use scarb_ui::args::FeaturesSpec; use tracing::trace; pub(crate) const LOG_TARGET: &str = "sozo::cli::commands::test"; @@ -58,6 +59,9 @@ pub struct TestArgs { /// Should we print the resource usage. #[arg(long, default_value_t = false)] print_resource_usage: bool, + /// Specify the features to activate. + #[command(flatten)] + features: FeaturesSpec, } impl TestArgs { @@ -68,15 +72,22 @@ impl TestArgs { }); let resolve = ops::resolve_workspace(&ws)?; - // TODO: Compute all compilation units and remove duplicates, could be unnecessary in future - // version of Scarb. - let features_opts = - FeaturesOpts { features: FeaturesSelector::AllFeatures, no_default_features: false }; - - let mut compilation_units = ops::generate_compilation_units(&resolve, &features_opts, &ws)?; - compilation_units.sort_by_key(|unit| unit.main_package_id()); - compilation_units.dedup_by_key(|unit| unit.main_package_id()); + let opts = CompileOpts { + include_target_kinds: vec![TargetKind::TEST], + exclude_target_kinds: vec![], + include_target_names: vec![], + features: self.features.try_into()?, + }; + + let compilation_units = ops::generate_compilation_units(&resolve, &opts.features, &ws)? + .into_iter() + .filter(|cu| !opts.exclude_target_kinds.contains(&cu.main_component().target_kind())) + .filter(|cu| { + opts.include_target_kinds.is_empty() + || opts.include_target_kinds.contains(&cu.main_component().target_kind()) + }) + .collect::>(); for unit in compilation_units { let unit = if let CompilationUnit::Cairo(unit) = unit { diff --git a/bin/sozo/tests/test_migrate.rs b/bin/sozo/tests/test_migrate.rs index 35d4a57fa7..df39bfc51a 100644 --- a/bin/sozo/tests/test_migrate.rs +++ b/bin/sozo/tests/test_migrate.rs @@ -39,9 +39,13 @@ async fn migrate_dry_run() { ]; let assert = get_snapbox().args(args_vec.iter()).assert().success(); - assert!(format!("{:?}", assert.get_output()).contains("Migration Strategy")); - assert!(format!("{:?}", assert.get_output()).contains("# Base Contract")); - assert!(format!("{:?}", assert.get_output()).contains("# Models (8)")); - assert!(format!("{:?}", assert.get_output()).contains("# World")); - assert!(format!("{:?}", assert.get_output()).contains("# Contracts (3)")); + let output = format!("{:#?}", assert.get_output()); + + dbg!("{}", &output); + + assert!(output.contains("Migration Strategy")); + assert!(output.contains("# Base Contract")); + assert!(output.contains("# Models (8)")); + assert!(output.contains("# World")); + assert!(output.contains("# Contracts (4)")); } diff --git a/crates/dojo-lang/src/compiler_test.rs b/crates/dojo-lang/src/compiler_test.rs index 627fc85c86..9a134aa7e1 100644 --- a/crates/dojo-lang/src/compiler_test.rs +++ b/crates/dojo-lang/src/compiler_test.rs @@ -13,6 +13,8 @@ fn test_compiler_cairo_features() { let features_opts = FeaturesOpts { features: FeaturesSelector::AllFeatures, no_default_features: false }; + let ws = scarb::ops::read_workspace(config.manifest_path(), &config).unwrap(); + let packages: Vec = ws.members().map(|p| p.id).collect(); let compile_info = scarb_internal::compile_workspace( &config, @@ -22,6 +24,7 @@ fn test_compiler_cairo_features() { exclude_target_kinds: vec![TargetKind::TEST], features: features_opts, }, + packages, ) .unwrap(); diff --git a/crates/dojo-lang/src/scarb_internal/mod.rs b/crates/dojo-lang/src/scarb_internal/mod.rs index d58eb2ff2e..93526f77f3 100644 --- a/crates/dojo-lang/src/scarb_internal/mod.rs +++ b/crates/dojo-lang/src/scarb_internal/mod.rs @@ -15,8 +15,8 @@ use cairo_lang_test_plugin::test_plugin_suite; use cairo_lang_utils::ordered_hash_map::OrderedHashMap; use camino::Utf8PathBuf; use scarb::compiler::{CairoCompilationUnit, CompilationUnit, CompilationUnitAttributes}; -use scarb::core::Config; -use scarb::ops::{CompileOpts, FeaturesOpts, FeaturesSelector}; +use scarb::core::{Config, PackageId}; +use scarb::ops::CompileOpts; use smol_str::SmolStr; use tracing::trace; @@ -57,7 +57,7 @@ pub fn crates_config_for_compilation_unit(unit: &CairoCompilationUnit) -> AllCra .contains(&SmolStr::new_inline("negative_impls")), coupons: experimental_features.contains(&SmolStr::new_inline("coupons")), }, - ..Default::default() + cfg_set: component.cfg_set.clone(), }, ) }) @@ -83,15 +83,15 @@ pub fn build_scarb_root_database(unit: &CairoCompilationUnit) -> Result Result { +pub fn compile_workspace( + config: &Config, + opts: CompileOpts, + packages: Vec, +) -> Result { let ws = scarb::ops::read_workspace(config.manifest_path(), config)?; - let packages: Vec = ws.members().map(|p| p.id).collect(); let resolve = scarb::ops::resolve_workspace(&ws)?; - let features_opts = - FeaturesOpts { features: FeaturesSelector::AllFeatures, no_default_features: false }; - - let compilation_units = scarb::ops::generate_compilation_units(&resolve, &features_opts, &ws)? + let compilation_units = scarb::ops::generate_compilation_units(&resolve, &opts.features, &ws)? .into_iter() .filter(|cu| !opts.exclude_target_kinds.contains(&cu.main_component().target_kind())) .filter(|cu| { diff --git a/crates/dojo-test-utils/build.rs b/crates/dojo-test-utils/build.rs index 881098a1ad..81dc015168 100644 --- a/crates/dojo-test-utils/build.rs +++ b/crates/dojo-test-utils/build.rs @@ -53,6 +53,8 @@ fn main() { let features_opts = FeaturesOpts { features: FeaturesSelector::AllFeatures, no_default_features: false }; + let ws = scarb::ops::read_workspace(config.manifest_path(), &config).unwrap(); + let packages: Vec = ws.members().map(|p| p.id).collect(); compile_workspace( &config, @@ -62,6 +64,7 @@ fn main() { include_target_names: vec![], features: features_opts, }, + packages, ) .unwrap(); } diff --git a/crates/dojo-test-utils/src/compiler.rs b/crates/dojo-test-utils/src/compiler.rs index 2d58848812..91352fe6f5 100644 --- a/crates/dojo-test-utils/src/compiler.rs +++ b/crates/dojo-test-utils/src/compiler.rs @@ -74,6 +74,9 @@ pub fn copy_build_project_temp( let features_opts = FeaturesOpts { features: FeaturesSelector::AllFeatures, no_default_features: false }; + let ws = scarb::ops::read_workspace(config.manifest_path(), &config).unwrap(); + + let packages: Vec = ws.members().map(|p| p.id).collect(); let compile_info = if do_build { Some( @@ -85,6 +88,7 @@ pub fn copy_build_project_temp( exclude_target_kinds: vec![TargetKind::TEST], features: features_opts, }, + packages, ) .unwrap(), ) diff --git a/crates/dojo-world/src/manifest/manifest_test.rs b/crates/dojo-world/src/manifest/manifest_test.rs index a26e60af08..d6a0aa4e11 100644 --- a/crates/dojo-world/src/manifest/manifest_test.rs +++ b/crates/dojo-world/src/manifest/manifest_test.rs @@ -353,10 +353,10 @@ fn fetch_remote_manifest() { }); assert_eq!(local_manifest.models.len(), 8); - assert_eq!(local_manifest.contracts.len(), 3); + assert_eq!(local_manifest.contracts.len(), 4); assert_eq!(remote_manifest.models.len(), 8); - assert_eq!(remote_manifest.contracts.len(), 3); + assert_eq!(remote_manifest.contracts.len(), 4); // compute diff from local and remote manifest diff --git a/examples/spawn-and-move/Scarb.toml b/examples/spawn-and-move/Scarb.toml index 408f29ab3c..47d3d5ee9e 100644 --- a/examples/spawn-and-move/Scarb.toml +++ b/examples/spawn-and-move/Scarb.toml @@ -15,6 +15,10 @@ dojo = { path = "../../crates/dojo-core" } [[target.dojo]] build-external-contracts = [ ] +[features] +default = ["something"] +something = [] + # `dev` profile [tool.dojo.world] @@ -31,6 +35,7 @@ account_address = "0x6162896d1d7ab204c7ccac6dd5f8e9e7c25ecd5ae4fcb4ad32e57786bb4 private_key = "0x1800000000300000180000000000030000000000003006001800006600" world_address = "0x504b804eeac62e68d12dc030e56b8f62cb047950c346e60a974da02795f6aba" + # `release` profile # # for now configurations in `tool` are not merged recursively so to override diff --git a/examples/spawn-and-move/manifests/dev/base/abis/contracts/dojo_examples-actions-40b6994c.json b/examples/spawn-and-move/manifests/dev/base/abis/contracts/dojo_examples-actions-40b6994c.json index 16ee68e05e..a8654af001 100644 --- a/examples/spawn-and-move/manifests/dev/base/abis/contracts/dojo_examples-actions-40b6994c.json +++ b/examples/spawn-and-move/manifests/dev/base/abis/contracts/dojo_examples-actions-40b6994c.json @@ -296,6 +296,18 @@ ], "outputs": [], "state_mutability": "external" + }, + { + "type": "function", + "name": "call_something", + "inputs": [ + { + "name": "something_address", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [], + "state_mutability": "view" } ] }, diff --git a/examples/spawn-and-move/manifests/dev/base/abis/contracts/dojo_examples-something-71cfad55.json b/examples/spawn-and-move/manifests/dev/base/abis/contracts/dojo_examples-something-71cfad55.json new file mode 100644 index 0000000000..fc1c520022 --- /dev/null +++ b/examples/spawn-and-move/manifests/dev/base/abis/contracts/dojo_examples-something-71cfad55.json @@ -0,0 +1,224 @@ +[ + { + "type": "impl", + "name": "ContractImpl", + "interface_name": "dojo::contract::IContract" + }, + { + "type": "struct", + "name": "core::byte_array::ByteArray", + "members": [ + { + "name": "data", + "type": "core::array::Array::" + }, + { + "name": "pending_word", + "type": "core::felt252" + }, + { + "name": "pending_word_len", + "type": "core::integer::u32" + } + ] + }, + { + "type": "interface", + "name": "dojo::contract::IContract", + "items": [ + { + "type": "function", + "name": "contract_name", + "inputs": [], + "outputs": [ + { + "type": "core::byte_array::ByteArray" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "namespace", + "inputs": [], + "outputs": [ + { + "type": "core::byte_array::ByteArray" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "tag", + "inputs": [], + "outputs": [ + { + "type": "core::byte_array::ByteArray" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "name_hash", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "namespace_hash", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "selector", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "WorldProviderImpl", + "interface_name": "dojo::world::IWorldProvider" + }, + { + "type": "struct", + "name": "dojo::world::IWorldDispatcher", + "members": [ + { + "name": "contract_address", + "type": "core::starknet::contract_address::ContractAddress" + } + ] + }, + { + "type": "interface", + "name": "dojo::world::IWorldProvider", + "items": [ + { + "type": "function", + "name": "world", + "inputs": [], + "outputs": [ + { + "type": "dojo::world::IWorldDispatcher" + } + ], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "ISomethingImpl", + "interface_name": "dojo_examples::something::ISomething" + }, + { + "type": "interface", + "name": "dojo_examples::something::ISomething", + "items": [ + { + "type": "function", + "name": "something", + "inputs": [], + "outputs": [], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "IDojoInitImpl", + "interface_name": "dojo_examples::something::something::IDojoInit" + }, + { + "type": "interface", + "name": "dojo_examples::something::something::IDojoInit", + "items": [ + { + "type": "function", + "name": "dojo_init", + "inputs": [], + "outputs": [], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "UpgradableImpl", + "interface_name": "dojo::components::upgradeable::IUpgradeable" + }, + { + "type": "interface", + "name": "dojo::components::upgradeable::IUpgradeable", + "items": [ + { + "type": "function", + "name": "upgrade", + "inputs": [ + { + "name": "new_class_hash", + "type": "core::starknet::class_hash::ClassHash" + } + ], + "outputs": [], + "state_mutability": "external" + } + ] + }, + { + "type": "event", + "name": "dojo::components::upgradeable::upgradeable::Upgraded", + "kind": "struct", + "members": [ + { + "name": "class_hash", + "type": "core::starknet::class_hash::ClassHash", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "dojo::components::upgradeable::upgradeable::Event", + "kind": "enum", + "variants": [ + { + "name": "Upgraded", + "type": "dojo::components::upgradeable::upgradeable::Upgraded", + "kind": "nested" + } + ] + }, + { + "type": "event", + "name": "dojo_examples::something::something::Event", + "kind": "enum", + "variants": [ + { + "name": "UpgradeableEvent", + "type": "dojo::components::upgradeable::upgradeable::Event", + "kind": "nested" + } + ] + } +] \ No newline at end of file diff --git a/examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-actions-40b6994c.toml b/examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-actions-40b6994c.toml index b3fc65dfe2..9bd796836c 100644 --- a/examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-actions-40b6994c.toml +++ b/examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-actions-40b6994c.toml @@ -1,6 +1,6 @@ kind = "DojoContract" -class_hash = "0x647694c15fff8476c82ea146d0dbdbbb17d3425d5ba05a7320e4322f916df1d" -original_class_hash = "0x647694c15fff8476c82ea146d0dbdbbb17d3425d5ba05a7320e4322f916df1d" +class_hash = "0x1843e2e8c174c087de5ebaf04eee196eb0526b6345ad5ac3a6055d4e0dd1363" +original_class_hash = "0x1843e2e8c174c087de5ebaf04eee196eb0526b6345ad5ac3a6055d4e0dd1363" base_class_hash = "0x0" abi = "manifests/dev/base/abis/contracts/dojo_examples-actions-40b6994c.json" reads = [] diff --git a/examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-something-71cfad55.toml b/examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-something-71cfad55.toml new file mode 100644 index 0000000000..f088c8a356 --- /dev/null +++ b/examples/spawn-and-move/manifests/dev/base/contracts/dojo_examples-something-71cfad55.toml @@ -0,0 +1,11 @@ +kind = "DojoContract" +class_hash = "0x2633dd37ecb3e273b309a3339da5dc820f2b77d4da474d7215952a1b60950dc" +original_class_hash = "0x2633dd37ecb3e273b309a3339da5dc820f2b77d4da474d7215952a1b60950dc" +base_class_hash = "0x0" +abi = "manifests/dev/base/abis/contracts/dojo_examples-something-71cfad55.json" +reads = [] +writes = [] +computed = [] +init_calldata = [] +tag = "dojo_examples-something" +manifest_name = "dojo_examples-something-71cfad55" diff --git a/examples/spawn-and-move/manifests/dev/deployment/abis/contracts/dojo_examples-something-71cfad55.json b/examples/spawn-and-move/manifests/dev/deployment/abis/contracts/dojo_examples-something-71cfad55.json new file mode 100644 index 0000000000..fc1c520022 --- /dev/null +++ b/examples/spawn-and-move/manifests/dev/deployment/abis/contracts/dojo_examples-something-71cfad55.json @@ -0,0 +1,224 @@ +[ + { + "type": "impl", + "name": "ContractImpl", + "interface_name": "dojo::contract::IContract" + }, + { + "type": "struct", + "name": "core::byte_array::ByteArray", + "members": [ + { + "name": "data", + "type": "core::array::Array::" + }, + { + "name": "pending_word", + "type": "core::felt252" + }, + { + "name": "pending_word_len", + "type": "core::integer::u32" + } + ] + }, + { + "type": "interface", + "name": "dojo::contract::IContract", + "items": [ + { + "type": "function", + "name": "contract_name", + "inputs": [], + "outputs": [ + { + "type": "core::byte_array::ByteArray" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "namespace", + "inputs": [], + "outputs": [ + { + "type": "core::byte_array::ByteArray" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "tag", + "inputs": [], + "outputs": [ + { + "type": "core::byte_array::ByteArray" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "name_hash", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "namespace_hash", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "selector", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "WorldProviderImpl", + "interface_name": "dojo::world::IWorldProvider" + }, + { + "type": "struct", + "name": "dojo::world::IWorldDispatcher", + "members": [ + { + "name": "contract_address", + "type": "core::starknet::contract_address::ContractAddress" + } + ] + }, + { + "type": "interface", + "name": "dojo::world::IWorldProvider", + "items": [ + { + "type": "function", + "name": "world", + "inputs": [], + "outputs": [ + { + "type": "dojo::world::IWorldDispatcher" + } + ], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "ISomethingImpl", + "interface_name": "dojo_examples::something::ISomething" + }, + { + "type": "interface", + "name": "dojo_examples::something::ISomething", + "items": [ + { + "type": "function", + "name": "something", + "inputs": [], + "outputs": [], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "IDojoInitImpl", + "interface_name": "dojo_examples::something::something::IDojoInit" + }, + { + "type": "interface", + "name": "dojo_examples::something::something::IDojoInit", + "items": [ + { + "type": "function", + "name": "dojo_init", + "inputs": [], + "outputs": [], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "UpgradableImpl", + "interface_name": "dojo::components::upgradeable::IUpgradeable" + }, + { + "type": "interface", + "name": "dojo::components::upgradeable::IUpgradeable", + "items": [ + { + "type": "function", + "name": "upgrade", + "inputs": [ + { + "name": "new_class_hash", + "type": "core::starknet::class_hash::ClassHash" + } + ], + "outputs": [], + "state_mutability": "external" + } + ] + }, + { + "type": "event", + "name": "dojo::components::upgradeable::upgradeable::Upgraded", + "kind": "struct", + "members": [ + { + "name": "class_hash", + "type": "core::starknet::class_hash::ClassHash", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "dojo::components::upgradeable::upgradeable::Event", + "kind": "enum", + "variants": [ + { + "name": "Upgraded", + "type": "dojo::components::upgradeable::upgradeable::Upgraded", + "kind": "nested" + } + ] + }, + { + "type": "event", + "name": "dojo_examples::something::something::Event", + "kind": "enum", + "variants": [ + { + "name": "UpgradeableEvent", + "type": "dojo::components::upgradeable::upgradeable::Event", + "kind": "nested" + } + ] + } +] \ No newline at end of file diff --git a/examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-actions-40b6994c.json b/examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-actions-40b6994c.json index 16ee68e05e..a8654af001 100644 --- a/examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-actions-40b6994c.json +++ b/examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-actions-40b6994c.json @@ -296,6 +296,18 @@ ], "outputs": [], "state_mutability": "external" + }, + { + "type": "function", + "name": "call_something", + "inputs": [ + { + "name": "something_address", + "type": "core::starknet::contract_address::ContractAddress" + } + ], + "outputs": [], + "state_mutability": "view" } ] }, diff --git a/examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-something-71cfad55.json b/examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-something-71cfad55.json new file mode 100644 index 0000000000..fc1c520022 --- /dev/null +++ b/examples/spawn-and-move/manifests/release/base/abis/contracts/dojo_examples-something-71cfad55.json @@ -0,0 +1,224 @@ +[ + { + "type": "impl", + "name": "ContractImpl", + "interface_name": "dojo::contract::IContract" + }, + { + "type": "struct", + "name": "core::byte_array::ByteArray", + "members": [ + { + "name": "data", + "type": "core::array::Array::" + }, + { + "name": "pending_word", + "type": "core::felt252" + }, + { + "name": "pending_word_len", + "type": "core::integer::u32" + } + ] + }, + { + "type": "interface", + "name": "dojo::contract::IContract", + "items": [ + { + "type": "function", + "name": "contract_name", + "inputs": [], + "outputs": [ + { + "type": "core::byte_array::ByteArray" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "namespace", + "inputs": [], + "outputs": [ + { + "type": "core::byte_array::ByteArray" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "tag", + "inputs": [], + "outputs": [ + { + "type": "core::byte_array::ByteArray" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "name_hash", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "namespace_hash", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + }, + { + "type": "function", + "name": "selector", + "inputs": [], + "outputs": [ + { + "type": "core::felt252" + } + ], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "WorldProviderImpl", + "interface_name": "dojo::world::IWorldProvider" + }, + { + "type": "struct", + "name": "dojo::world::IWorldDispatcher", + "members": [ + { + "name": "contract_address", + "type": "core::starknet::contract_address::ContractAddress" + } + ] + }, + { + "type": "interface", + "name": "dojo::world::IWorldProvider", + "items": [ + { + "type": "function", + "name": "world", + "inputs": [], + "outputs": [ + { + "type": "dojo::world::IWorldDispatcher" + } + ], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "ISomethingImpl", + "interface_name": "dojo_examples::something::ISomething" + }, + { + "type": "interface", + "name": "dojo_examples::something::ISomething", + "items": [ + { + "type": "function", + "name": "something", + "inputs": [], + "outputs": [], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "IDojoInitImpl", + "interface_name": "dojo_examples::something::something::IDojoInit" + }, + { + "type": "interface", + "name": "dojo_examples::something::something::IDojoInit", + "items": [ + { + "type": "function", + "name": "dojo_init", + "inputs": [], + "outputs": [], + "state_mutability": "view" + } + ] + }, + { + "type": "impl", + "name": "UpgradableImpl", + "interface_name": "dojo::components::upgradeable::IUpgradeable" + }, + { + "type": "interface", + "name": "dojo::components::upgradeable::IUpgradeable", + "items": [ + { + "type": "function", + "name": "upgrade", + "inputs": [ + { + "name": "new_class_hash", + "type": "core::starknet::class_hash::ClassHash" + } + ], + "outputs": [], + "state_mutability": "external" + } + ] + }, + { + "type": "event", + "name": "dojo::components::upgradeable::upgradeable::Upgraded", + "kind": "struct", + "members": [ + { + "name": "class_hash", + "type": "core::starknet::class_hash::ClassHash", + "kind": "data" + } + ] + }, + { + "type": "event", + "name": "dojo::components::upgradeable::upgradeable::Event", + "kind": "enum", + "variants": [ + { + "name": "Upgraded", + "type": "dojo::components::upgradeable::upgradeable::Upgraded", + "kind": "nested" + } + ] + }, + { + "type": "event", + "name": "dojo_examples::something::something::Event", + "kind": "enum", + "variants": [ + { + "name": "UpgradeableEvent", + "type": "dojo::components::upgradeable::upgradeable::Event", + "kind": "nested" + } + ] + } +] \ No newline at end of file diff --git a/examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-actions-40b6994c.toml b/examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-actions-40b6994c.toml index aa9b1571cd..e5a46e3a69 100644 --- a/examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-actions-40b6994c.toml +++ b/examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-actions-40b6994c.toml @@ -1,6 +1,6 @@ kind = "DojoContract" -class_hash = "0x647694c15fff8476c82ea146d0dbdbbb17d3425d5ba05a7320e4322f916df1d" -original_class_hash = "0x647694c15fff8476c82ea146d0dbdbbb17d3425d5ba05a7320e4322f916df1d" +class_hash = "0x1843e2e8c174c087de5ebaf04eee196eb0526b6345ad5ac3a6055d4e0dd1363" +original_class_hash = "0x1843e2e8c174c087de5ebaf04eee196eb0526b6345ad5ac3a6055d4e0dd1363" base_class_hash = "0x0" abi = "manifests/release/base/abis/contracts/dojo_examples-actions-40b6994c.json" reads = [] diff --git a/examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-something-71cfad55.toml b/examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-something-71cfad55.toml new file mode 100644 index 0000000000..cb4974411e --- /dev/null +++ b/examples/spawn-and-move/manifests/release/base/contracts/dojo_examples-something-71cfad55.toml @@ -0,0 +1,11 @@ +kind = "DojoContract" +class_hash = "0x2633dd37ecb3e273b309a3339da5dc820f2b77d4da474d7215952a1b60950dc" +original_class_hash = "0x2633dd37ecb3e273b309a3339da5dc820f2b77d4da474d7215952a1b60950dc" +base_class_hash = "0x0" +abi = "manifests/release/base/abis/contracts/dojo_examples-something-71cfad55.json" +reads = [] +writes = [] +computed = [] +init_calldata = [] +tag = "dojo_examples-something" +manifest_name = "dojo_examples-something-71cfad55" diff --git a/examples/spawn-and-move/src/actions.cairo b/examples/spawn-and-move/src/actions.cairo index a0d7753e0f..350ad568ee 100644 --- a/examples/spawn-and-move/src/actions.cairo +++ b/examples/spawn-and-move/src/actions.cairo @@ -1,4 +1,6 @@ use dojo_examples::models::{Direction, Position, Vec2}; +#[cfg(feature: 'something')] +use starknet::ContractAddress; #[dojo::interface] trait IActions { @@ -8,6 +10,8 @@ trait IActions { fn get_player_position(world: @IWorldDispatcher) -> Position; fn reset_player_config(ref world: IWorldDispatcher); fn set_player_server_profile(ref world: IWorldDispatcher, server_id: u32, name: ByteArray); + #[cfg(feature: 'something')] + fn call_something(something_address: ContractAddress); } #[dojo::interface] @@ -26,6 +30,8 @@ mod actions { Position, Moves, Direction, Vec2, PlayerConfig, PlayerItem, ServerProfile }; use dojo_examples::utils::next_position; + #[cfg(feature: 'something')] + use dojo_examples::something::{ISomethingDispatcher, ISomethingDispatcherTrait}; #[derive(Copy, Drop, Serde)] #[dojo::event] @@ -123,6 +129,13 @@ mod actions { let player = get_caller_address(); get!(world, player, (Position)) } + + #[cfg(feature: 'something')] + fn call_something(something_address: ContractAddress) { + let something = ISomethingDispatcher { contract_address: something_address }; + + something.something(); + } } // The `generate_trait` attribute is not compatible with `world` parameter expansion. diff --git a/examples/spawn-and-move/src/lib.cairo b/examples/spawn-and-move/src/lib.cairo index b1273839ec..1eb02d648a 100644 --- a/examples/spawn-and-move/src/lib.cairo +++ b/examples/spawn-and-move/src/lib.cairo @@ -3,3 +3,5 @@ mod models; mod utils; mod others; mod mock_token; +#[cfg(feature: 'something')] +mod something; diff --git a/examples/spawn-and-move/src/something.cairo b/examples/spawn-and-move/src/something.cairo new file mode 100644 index 0000000000..d6746dfce6 --- /dev/null +++ b/examples/spawn-and-move/src/something.cairo @@ -0,0 +1,12 @@ +#[dojo::interface] +trait ISomething { + fn something(); +} + +#[dojo::contract] +mod something { + #[abi(embed_v0)] + impl ISomethingImpl of super::ISomething { + fn something() {} + } +}