From 5a55f0b0db3fca2267718e9c06b097ffa095a3fb Mon Sep 17 00:00:00 2001 From: Asuma Yamada Date: Thu, 12 Sep 2024 15:00:23 -0400 Subject: [PATCH 1/8] feat: update to latest dojo development environment --- .tool-versions | 2 + .vscode/extensions.json | 3 + .vscode/settings.json | 7 ++ README.md | 232 ++++++++++++++++++++++------------------ README_old.md | 127 ---------------------- Scarb.lock | 11 +- Scarb.toml | 66 +----------- dojo_dev.toml | 14 +++ dojo_release.toml | 18 ++++ src/app.cairo | 14 +-- src/tests.cairo | 44 +++----- 11 files changed, 201 insertions(+), 337 deletions(-) create mode 100644 .tool-versions create mode 100644 .vscode/extensions.json create mode 100644 .vscode/settings.json delete mode 100644 README_old.md create mode 100644 dojo_dev.toml create mode 100644 dojo_release.toml diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..e1e700a --- /dev/null +++ b/.tool-versions @@ -0,0 +1,2 @@ +dojo 1.0.0-alpha.11 +scarb 2.7.0 diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 0000000..b1946bc --- /dev/null +++ b/.vscode/extensions.json @@ -0,0 +1,3 @@ +{ + "recommendations": ["StarkWare.cairo1", "tamasfe.even-better-toml"] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..daae992 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "cairo1.enableLanguageServer": true, + "cairo1.languageServerPath": "${userHome}/.asdf/installs/dojo/1.0.0-alpha.11/bin/dojo-language-server", + "cairo1.enableScarb": true, + "cairo1.scarbPath": "${userHome}/.asdf/installs/scarb/2.7.0/bin/scarb", + "cairo1.preferScarbLanguageServer": false +} diff --git a/README.md b/README.md index 99487ea..61a5fc1 100644 --- a/README.md +++ b/README.md @@ -1,103 +1,129 @@ -# PixeLAW App template -## Documents -For additional step-by-step explanations on how to build and deploy your own PixeLAW app follow along [PixeLAW book](https://pixelaw.github.io/book/getting-started/quick-start.html)! - - -## Prerequisites -### Dojo -PixeLAW is built on top of Dojo. Refer to this [page](https://book.dojoengine.org/getting-started/quick-start) to get it installed. - -## Getting started -### Clone this repository -#### Via GitHub -Use this template to create a new repository or clone this repository locally. - -## Run this code -### Run the tests made for this app -````console -sozo test -```` - -### Local Development -#### Run [Pixelaw/core](https://github.com/pixelaw/core) -We are using [devcontainer](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) environments. Please open this code with vscode and launch the container with devcontainer. - -This is the easiest way to get PixeLAW core up and running in http://localhost:3000. We recommend you to use incognito mode to browse. - - ---- -### Check the status -If you succesfully start up PixeLAW core, it will take a while for all the core contracts to get deployed -and start running. Wait until http://localhost:3000/manifests/core stops returning NOT FOUND. To check if you can -start deploying your app, use the following script (this will print out "Ready for app deployment" when the core -contracts have finished initialization): - -````console -scarb run ready_for_deployment -```` - -After which you can start deploying your app onto your local PixeLAW via: - ---- -### Build and Deploy your contracts locally -#### Building -````console -sozo build -```` - -#### Deploying your contracts -This will deploy your app to the local PixeLAW using sozo migrate. -````console -sozo migrate apply --name pixelaw -```` - -#### Initializing your contracts -This will grant writer permission to your app for any custom models made. -````console -scarb run initialize -```` - -#### Uploading your manifest -````console -scarb run upload_manifest -```` - ---- -### Deploying to Demo -Deploying to demo is almost the same as local development. The only difference is needing -the RPC_URL of the Demo environment, the DEMO_URL (NOTE: this must end in a slash i.e. '/') -of the Demo App to upload your manifest to, and the world name. Both URLs and world name can be provided by us. -Please reach out through discord. Currently, sozo checks first if an environment variable was set in Scarb.toml for -rpc-url. So, comment that out before beginning with the following steps. - -#### Build your contracts -````console -sozo build -```` - -#### Deploy your contracts -This will deploy your app to the local PixeLAW using sozo migrate. -````console -sozo migrate apply --name --rpc-url -```` - -#### Initializing your contracts -This will grant writer permission to your app for any custom models made. -````console -scarb run initialize -```` - -#### Uploading your manifest -````console -scarb run upload_manifest -```` - - -### FAQs -#### error when deploying to rpc-url - -Please check the `[[tool.dojo.env]]` in your `Sarb.toml`. You have to modify it correctly. - -Also, please verify `account_address` and `private_key`. - -For dojo problems, please check the version is correct. +# PixeLAW App Template + +Contracts written in Cairo using Dojo to showcase a Pixel World with app interoperability. Its interoperability is made possible with core actions. Apps are any other contracts that are deployed to the Pixel World. + +## Development + +### Prerequisites + +- [asdf](https://asdf-vm.com/) +- [scarb](https://docs.swmansion.com/scarb/) +- [dojo](https://github.com/dojoengine/dojo) + +### Install asdf + +Follow the asdf installation instructions. + +### Install dojo + +``` +asdf plugin add dojo https://github.com/dojoengine/asdf-dojo +asdf install dojo 1.0.0-alpha.11 +``` + +### Install scarb + +``` +asdf plugin add scarb +asdf install scarb 2.7.0-rc.4 +``` + +And after moving into contracts directory, the versions for these libs are set in the .tool-versions file. + +## Default Apps + +These are apps developed by PixeLAW + +## Paint + +### Overview + +The Paint App is a collection of functions that allow players to manipulate the color of a Pixel. + +### Properties + +None, Paint is just behavior. + +### Behavior + +- public `put_color(color)` + - context: position +- both `put_fading_color(color)` + - context: position +- public `remove_color()` + - context: position + +## Snake + +### Overview + +It it basically the game "snake", but with Pixels not necessarily available to move on/over. It is a player-initialized instance that coordinates pixel's color and text being overriden and reverted (if allowed). +If hitting an unowned Pixel, the snake will move, if Pixel is owned by player, Snake grows, and if Pixel is not owned but it's App allows Snake, it shrinks. In all other cases, Snake dies. + +### Properties + +- position +- color +- text +- direction + +### Behavior + +- public `spawn(color, text, direction)` + - context: position +- public `turn(snake_id, direction)` + - context: player +- private `move(snake_id)` + +## Rock Paper Scissors + +### Overview + +Each Pixel can contain an instance of the RPS App, where it holds a commitment (rock, paper or scissors) from player1. Any other player can now "join" and submit their move. Player1 can then reveal, the winner is decided then. Winner gains ownership of the losing RPS pixel. In case of a draw, the pixel is reset. +The App is also tracking score for each Player. + +### Global Properties + +- player+wins + +### Game-based Properties + +- player1 +- player2 + +### Behavior + +- create (position, player1, commit1) +- join (position, player2, move2) +- finish (position, move1, salt1) +- reset (position) + +## CommitReveal inputs + +### Param of the action + +- (Hashed Commit) + - parametername of action has structure: "PREFIX_TYPE_NAME" + - PREFIX is "cr\_" + - TYPE for now is the name of an int, felt or Enum declared in the manifest + - NAME is a chosen name to refer to the param. +- (Value+Salt reveal) + - parametername of action has structure: "PREFIX_NAME" + - PREFIX shall always be "rv\_" + - NAME is the same name user during sending the commit + +### Clientside functioning + +- If client finds a param starting with "cr\_" +- It will prompt user for a param with TYPE + - example: + - The game RPS needs player1 to choose one option, but only send the hashedcommit + - Then, during a next stage of the game, the plaintext move and the salt will be requested + - The challenge is that the UI needsto be capable of doing this without knowing about the specific application. Reveal/Commit is a feature of the platform. + - Commit + - RpsMove is an enum with 3 fields, so ui presents user with 3 choices + - UI stores this clientside related to the pixel/app + - UI then hashes this with a salt, and also stores the salt with the choice + - UI then calls the functions with only the hash value + - Reveal + - there will be 2 params: "rv_NAME" (the actual param) and "rs_NAME" (the used salt) diff --git a/README_old.md b/README_old.md deleted file mode 100644 index 8d2c902..0000000 --- a/README_old.md +++ /dev/null @@ -1,127 +0,0 @@ -# PixeLAW App template -For additional step-by-step explanations on how to build and deploy your own PixeLAW app follow along [here](https://pixelaw.github.io/book/getting-started/quick-start.html)! - -# Prerequisites -## Dojo -PixeLAW is built on top of Dojo. Refer to this [page](https://book.dojoengine.org/getting-started/quick-start) to get it installed. - -# Getting started -## Clone this repository -### Via GitHub -Use this template to create a new repository or clone this repository locally. - -## Run this code -### Run the tests made for this app -````console -sozo test -```` - -### Local Development - -#### Run [Pixelaw/core](https://github.com/pixelaw/core) -There are multiple ways to have a local copy of PixeLAW core for development: - -##### Using Docker Compose (Recommended) -This is the easiest way to get PixeLAW core up and running in http://localhost:3000. There is a docker-compose file in this repository specifically for running a local image -of PixeLAW core. - -###### Prerequisites -1. [Docker](https://docs.docker.com/engine/install/) -2. [Docker Compose plugin](https://docs.docker.com/compose/install/) - -Running the following command will run core in a container. -````console -docker compose up -d -```` - -##### Using Docker -Another way to go about it is by using the Docker engine by itself. - -###### -1. [Docker](https://docs.docker.com/engine/install/) - -The following script will create the docker network for the container to run in: -````console -docker network create --driver bridge pixelaw -```` -And this will run the actual container in http://localhost:3000: -````console -docker run -d --name pixelaw-core -p 5050:5050 -p 3000:3000 -p 8080:8080 -p 50051 --restart unless-stopped --network pixelaw oostvoort/pixelaw-core:v0.0.33 -```` - -##### Manually -This will take the most time. This entails cloning the PixeLAW core repos and running each individual component -manually. Refer to the [GitHub repository](https://github.com/pixelaw/core) for how to run it. - ---- -Whichever way you've chosen to start up PixeLAW core, it will take a while for all the core contracts to get deployed -and start running. Wait until http://localhost:3000/manifests/core stops returning NOT FOUND. To check if you can -start deploying your app, use the following script (this will print out "Ready for app deployment" when the core -contracts have finished initialization): - -````console -scarb run ready_for_deployment -```` - -After which you can start deploying your app onto your local PixeLAW via: - -#### Building your contracts -````console -sozo build -```` - -#### Deploying your contracts -This will deploy your app to the local PixeLAW using sozo migrate. -````console -sozo migrate --name pixelaw -```` - -#### Initializing your contracts -This will grant writer permission to your app for any custom models made. -````console -scarb run initialize -```` - -#### Uploading your manifest -````console -scarb run upload_manifest -```` - -### Deploying to Demo -Deploying to demo is almost the same as local development. The only difference is needing -the RPC_URL of the Demo environment, the DEMO_URL (NOTE: this must end in a slash i.e. '/') -of the Demo App to upload your manifest to, and the world name. Both URLs and world name can be provided by us. -Please reach out through discord. Currently, sozo checks first if an environment variable was set in Scarb.toml for -rpc-url. So, comment that out before beginning with the following steps. - -#### Build your contracts -````console -sozo build -```` - -#### Deploy your contracts -This will deploy your app to the local PixeLAW using sozo migrate. -````console -sozo migrate --name --rpc-url -```` - -#### Initializing your contracts -This will grant writer permission to your app for any custom models made. -````console -scarb run initialize -```` - -#### Uploading your manifest -````console -scarb run upload_manifest -```` - - -### FAQs -#### error when deploying to rpc-url - -Please check the `[[tool.dojo.env]]` in your `Sarb.toml`. You have to modify it correctly. - -Also, please verify `account_address` and `private_key`. - -For dojo problems, please check the version is correct. diff --git a/Scarb.lock b/Scarb.lock index 940d1ef..544bc90 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -3,16 +3,16 @@ version = 1 [[package]] name = "dojo" -version = "0.7.3" -source = "git+https://github.com/dojoengine/dojo?tag=v1.0.0-alpha.4#d08c46191fc1b4c4f90816cef4787cb8db02988f" +version = "1.0.0-alpha.4" +source = "git+https://github.com/dojoengine/dojo?tag=v1.0.0-alpha.11#fbff45b249e2b931f5007edf2d526beef7dc553f" dependencies = [ "dojo_plugin", ] [[package]] name = "dojo_plugin" -version = "0.7.3" -source = "git+https://github.com/dojoengine/dojo?rev=71b1f1a4#71b1f1a467534cbeeb901356f41e612ed4187bd1" +version = "1.0.0-alpha.4" +source = "git+https://github.com/dojoengine/dojo?rev=f15def33#f15def330c0d099e79351d11c197f63e8cc1ff36" [[package]] name = "myapp" @@ -23,8 +23,7 @@ dependencies = [ [[package]] name = "pixelaw" -version = "0.3.35" -source = "git+https://github.com/pixelaw/core?tag=v0.3.35#c60df919fa9e683a39763366a09623cd4bbdfb09" +version = "0.3.50" dependencies = [ "dojo", ] diff --git a/Scarb.toml b/Scarb.toml index c5e8efa..b8a829c 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -1,5 +1,5 @@ [package] -cairo-version = "=2.7.0-rc.3" +cairo-version = "=2.7.0" name = "myapp" version = "0.0.0" @@ -7,66 +7,8 @@ version = "0.0.0" sierra-replace-ids = true [dependencies] -pixelaw = { git = "https://github.com/pixelaw/core", tag = "v0.3.35" } +pixelaw = { path = "/Users/asumayamada/Private/pixelaw/core/contracts" } +# pixelaw = { git = "https://github.com/pixelaw/core", tag = "v0.3.50" } [[target.dojo]] -build-external-contracts = [ - "pixelaw::apps::snake::app::snake", - "pixelaw::apps::snake::app::snake_segment", - "pixelaw::core::models::pixel::pixel", - "pixelaw::core::models::pixel::Pixel", - "pixelaw::core::models::pixel::PixelUpdate", - "pixelaw::core::models::queue::queue_item", - "pixelaw::core::models::registry::app", - "pixelaw::core::models::registry::app_name", - "pixelaw::core::models::registry::app_user", - "pixelaw::core::models::registry::app_instruction", - "pixelaw::core::models::registry::instruction", - "pixelaw::core::models::registry::core_actions_address", - "pixelaw::core::models::permissions::permissions", - "pixelaw::core::utils::get_core_actions", - "pixelaw::core::utils::Direction", - "pixelaw::core::utils::Position", - "pixelaw::core::utils::DefaultParameters", - "pixelaw::core::actions::actions", - "pixelaw::core::actions::IActionsDispatcher", - "pixelaw::core::actions::IActionsDispatcherTrait" -] - -[tool.dojo] -initializer_class_hash = "0xbeef" - -[tool.dojo.world.namespace] -default = "myapp" -mappings = { } - - - -[tool.dojo.world] -description = "myapp world" -name = "myapp" -seed = "dojo_examples" - - -# Dev: http://localhost:3000 -[tool.dojo.env] -rpc_url = "http://127.0.0.1:5050/" -account_address = "0x003c4dd268780ef738920c801edc3a75b6337bc17558c74795b530c0ff502486" -private_key = "0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a" -world_address= "0x00a712727a27defbf77122fae30c91e90ec62bba8f09a2a396eddc29b768386b" - -## demo.pixelaw.xyz -#[profile.demo.tool.dojo.env] -#rpc_url = "https://katana.demo.pixelaw.xyz/" -#account_address = "0x003c4dd268780ef738920c801edc3a75b6337bc17558c74795b530c0ff502486" -#private_key = "0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a" -#world_address = "0x00a712727a27defbf77122fae30c91e90ec62bba8f09a2a396eddc29b768386b" -#manifest_url="https://demo.pixelaw.xyz/manifests" - -[scripts] -ready_for_deployment = "bash ./scripts/ready_for_deployment.sh" -initialize = "bash ./scripts/default_auth.sh" -upload_manifest = "bash ./scripts/upload_manifest.sh" -ready_for_deployment_zsh = "zsh ./scripts/ready_for_deployment.sh" -initialize_zsh = "zsh ./scripts/default_auth.sh" -upload_manifest_zsh = "zsh ./scripts/upload_manifest.sh" +build-external-contracts = [] diff --git a/dojo_dev.toml b/dojo_dev.toml new file mode 100644 index 0000000..14b92a4 --- /dev/null +++ b/dojo_dev.toml @@ -0,0 +1,14 @@ +[world] +description = "Empty PixeLAW world" +name = "pixelaw" +seed = "pixelaw" + +[namespace] +default = "pixelaw" +mappings = {} + +[env] +rpc_url = "http://localhost:5050/" +account_address = "0xb3ff441a68610b30fd5e2abbf3a1548eb6ba6f3559f2862bf2dc757e5828ca" +private_key = "0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a" +world_address = "0x263ae44e5414519a5c5a135cccaf3d9d7ee196d37e8de47a178da91f3de9b34" diff --git a/dojo_release.toml b/dojo_release.toml new file mode 100644 index 0000000..4637002 --- /dev/null +++ b/dojo_release.toml @@ -0,0 +1,18 @@ +[world] +description = "PixeLAW world" +name = "pixelaw" +seed = "pixelaw" + +[world.socials] +x = "https://x.com/pixelaw" +github = "https://github.com/pixelaw" + +[namespace] +default = "pixelaw" +mappings = {} + +[env] +rpc_url = "https://api.cartridge.gg/x/pixelaw-dev/katana/" +account_address = "0x5233cfca86bfa18af0bdef2fd09ac4c1d7c8da71303eb7fc9997fc6d0914d0d" +private_key = "0xf0e37335d0c020789dd02c0460d99637ac23bd2df3d1d25002fd15621542d" +world_address = "0x99b8dbc71926673405f5dfff9e4900ee4d9249798cc5e7ac6f3c3a07907399" diff --git a/src/app.cairo b/src/app.cairo index 796ba85..5253aef 100644 --- a/src/app.cairo +++ b/src/app.cairo @@ -18,8 +18,8 @@ const APP_ICON: felt252 = 'U+263A'; /// prefixing with BASE means using the server's default manifest.json handler const APP_MANIFEST: felt252 = 'BASE/manifests/myapp'; -#[dojo::contract] /// contracts must be named as such (APP_KEY + underscore + "actions") +#[dojo::contract(namespace: "pixelaw", nomapping: true)] mod myapp_actions { use starknet::{ get_tx_info, get_caller_address, get_contract_address, get_execution_info, ContractAddress @@ -41,14 +41,12 @@ mod myapp_actions { // impl: implement functions specified in trait #[abi(embed_v0)] impl ActionsImpl of IMyAppActions { - /// Initialize the MyApp App (TODO I think, do we need this??) fn init(ref world: IWorldDispatcher) { let core_actions = pixelaw::core::utils::get_core_actions(world); core_actions.update_app(APP_KEY, APP_ICON, APP_MANIFEST); - //Grant permission to the snake App core_actions .update_permission( @@ -71,8 +69,6 @@ mod myapp_actions { /// * `position` - Position of the pixel. /// * `new_color` - Color to set the pixel to. fn interact(ref world: IWorldDispatcher, default_params: DefaultParameters) { - 'put_color'.print(); - // Load important variables let core_actions = get_core_actions(world); let position = default_params.position; @@ -88,9 +84,9 @@ mod myapp_actions { // Check if 5 seconds have passed or if the sender is the owner assert( - pixel.owner.is_zero() || (pixel.owner) == player || starknet::get_block_timestamp() - - pixel.timestamp < COOLDOWN_SECS, - 'Cooldown not over' + pixel.owner.is_zero() || (pixel.owner) == player || starknet::get_block_timestamp() + - pixel.timestamp < COOLDOWN_SECS, + 'Cooldown not over' ); // We can now update color of the pixel @@ -109,8 +105,6 @@ mod myapp_actions { action: Option::None // Not using this feature for myapp } ); - - 'put_color DONE'.print(); } } } diff --git a/src/tests.cairo b/src/tests.cairo index 4049ae1..34d8ea3 100644 --- a/src/tests.cairo +++ b/src/tests.cairo @@ -9,29 +9,28 @@ mod tests { use pixelaw::core::models::pixel::{Pixel, PixelUpdate}; use pixelaw::core::models::pixel::{pixel}; use pixelaw::core::models::permissions::{permissions}; - use pixelaw::core::utils::{get_core_actions, Direction, Position, DefaultParameters}; + use pixelaw::core::utils::{ + get_core_actions, encode_color, decode_color, Direction, Position, DefaultParameters + }; use pixelaw::core::actions::{actions, IActionsDispatcher, IActionsDispatcherTrait}; - use dojo::test_utils::{spawn_test_world, deploy_contract}; + use dojo::utils::test::{spawn_test_world}; - use myapp::app::{ - myapp_actions, IMyAppActionsDispatcher, IMyAppActionsDispatcherTrait - }; + use myapp::app::{myapp_actions, IMyAppActionsDispatcher, IMyAppActionsDispatcherTrait}; use zeroable::Zeroable; // Helper function: deploys world and actions fn deploy_world() -> (IWorldDispatcher, IActionsDispatcher, IMyAppActionsDispatcher) { // Deploy World and models - let world = spawn_test_world( - array![ - pixel::TEST_CLASS_HASH, - app::TEST_CLASS_HASH, - app_name::TEST_CLASS_HASH, - core_actions_address::TEST_CLASS_HASH, - permissions::TEST_CLASS_HASH, - ] - ); + let mut models = array![ + pixel::TEST_CLASS_HASH, + app::TEST_CLASS_HASH, + app_name::TEST_CLASS_HASH, + core_actions_address::TEST_CLASS_HASH, + permissions::TEST_CLASS_HASH, + ]; + let world = spawn_test_world(["pixelaw"].span(), models.span()); // Deploy Core actions let core_actions_address = world @@ -51,8 +50,7 @@ mod tests { world.grant_writer('Permissions', core_actions_address); // PLEASE ADD YOUR APP PERMISSIONS HERE - - + (world, core_actions, myapp_actions) } @@ -68,7 +66,7 @@ mod tests { let player1 = starknet::contract_address_const::<0x1337>(); starknet::testing::set_account_contract_address(player1); - let color = encode_color(1, 1, 1); + let color = encode_color(1, 1, 1, 1); myapp_actions .interact( @@ -85,16 +83,4 @@ mod tests { 'Passed test'.print(); } - - fn encode_color(r: u8, g: u8, b: u8) -> u32 { - (r.into() * 0x10000) + (g.into() * 0x100) + b.into() - } - - fn decode_color(color: u32) -> (u8, u8, u8) { - let r = (color / 0x10000); - let g = (color / 0x100) & 0xff; - let b = color & 0xff; - - (r.try_into().unwrap(), g.try_into().unwrap(), b.try_into().unwrap()) - } } From 5235fb9cac645d4fc44cd3e2fb3692acf6023bf4 Mon Sep 17 00:00:00 2001 From: Asuma Yamada Date: Thu, 12 Sep 2024 15:01:50 -0400 Subject: [PATCH 2/8] fix: make it simple --- .devcontainer/devcontainer.json | 54 --------------------------------- Makefile | 38 ----------------------- docker-compose.yml | 28 ----------------- 3 files changed, 120 deletions(-) delete mode 100644 .devcontainer/devcontainer.json delete mode 100644 Makefile delete mode 100644 docker-compose.yml diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json deleted file mode 100644 index aebf75c..0000000 --- a/.devcontainer/devcontainer.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "name": "My Project", - "image": "ghcr.io/pixelaw/core:0.3.35", - "forwardPorts": [ - 5050, - 8080, - 9090, - 3000 - ], - "containerEnv": { - "RPC_URL": "http://localhost:5050", - "TORII_URL": "http://localhost:8080", - "RELAY_URL": "http://localhost:8080", - "PUBLIC_SERVER_URL": "http://localhost:3000", - "PUBLIC_RPC_URL": "http://localhost:5050", - "PUBLIC_TORII_URL": "http://localhost:8080", - "PUBLIC_RELAY_URL": "http://localhost:8080", - "MASTER_ADDRESS": "0x003c4dd268780ef738920c801edc3a75b6337bc17558c74795b530c0ff502486", - "MASTER_PRIVATE_KEY": "0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a", - "WORLD_ADDRESS": "0xd4136ca2b9f1b08c6d6857b0f19da3dc8d136105ec46459787a6de0fd92bf8", - "ACCOUNT_CLASS_HASH": "0x05400e90f7e0ae78bd02c77cd75527280470e2fe19c54970dd79dc37a9d3645c", - "FEETOKEN_ADDRESS": "0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7", - "SERVER_PORT": "3000" - }, - "postStartCommand": [ - "/pixelaw/scripts/startup.sh" - ], - // Configure tool-specific properties. - "customizations": { - // Configure properties specific to VS Code. - "vscode": { - // Set *default* container specific settings.json values on container create. - "settings": { - "cairo1.enableLanguageServer": true, - "cairo1.enableScarb": true, - "cairo1.languageServerPath": "/root/.dojo/dojo-language-server", - "cairo1.scarbPath": "/root/.local/bin/scarb", - "lldb.executable": "/usr/bin/lldb", - // VS Code don't watch files under ./target - "files.watcherExclude": { - "**/target/**": true - }, - "rust-analyzer.checkOnSave.command": "clippy", - "terminal.integrated.shell.linux": "/bin/bash" - }, - // Add the IDs of extensions you want installed when the container is created. - "extensions": [ - "mutantdino.resourcemonitor", - "tamasfe.even-better-toml", - "starkware.cairo1" - ] - } - } -} \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index c530150..0000000 --- a/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -PROFILE ?= dev - -build: - sozo --profile $(PROFILE) build; - -test: - sozo --profile $(PROFILE) test; - -deploy_new: reset deploy - scarb --profile $(PROFILE) run initialize; - scarb --profile $(PROFILE) run upload_manifest; - @echo "PixeLAW should be back at http://localhost:3000 again." - -deploy_local: - /pixelaw/tools/local_deploy.sh - - -deploy: build - sozo --profile $(PROFILE) migrate; - -dev: - sozo --profile $(PROFILE) dev --name pixelaw; - -reset: - docker compose down -v; - docker compose up -d; - -shell: - docker compose exec pixelaw-core bash; - -log_katana: - docker compose exec pixelaw-core /bin/bash klog - -log_torii: - docker compose exec pixelaw-core tail -f /keiko/log/torii.log - -log_bots: - docker compose exec pixelaw-core tail -f /keiko/log/bots.log \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml deleted file mode 100644 index af8ac66..0000000 --- a/docker-compose.yml +++ /dev/null @@ -1,28 +0,0 @@ -services: - pixelaw-core: - image: ghcr.io/pixelaw/core:0.3.27 - platform: linux/x86_64 - container_name: pixelaw-core - environment: - - DISABLE_FEE=true -# - RUST_LOG=debug,hyper=off - - SERVER_PORT=3000 - - WORLD_ADDRESS=0x00a712727a27defbf77122fae30c91e90ec62bba8f09a2a396eddc29b768386b - ports: - - "127.0.0.1:5050:5050" - - "127.0.0.1:3000:3000" - - "127.0.0.1:8080:8080" - - "127.0.0.1:9090:9090" - restart: no - networks: - - pixelaw - volumes: - - storage:/pixelaw/storage - - .:/mounted - - -networks: - pixelaw: - driver: bridge -volumes: - storage: From 9527dc9825fdb72e0f0292185c15bb5545fee7fe Mon Sep 17 00:00:00 2001 From: Asuma Yamada Date: Sun, 15 Sep 2024 15:36:05 -0400 Subject: [PATCH 3/8] fix: sort modules --- Scarb.toml | 3 +++ src/app.cairo | 19 +++++++++---------- src/lib.cairo | 2 +- src/tests.cairo | 16 ++++++++-------- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Scarb.toml b/Scarb.toml index b8a829c..b8b21b9 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -12,3 +12,6 @@ pixelaw = { path = "/Users/asumayamada/Private/pixelaw/core/contracts" } [[target.dojo]] build-external-contracts = [] + +[tool.fmt] +sort-module-level-items = true \ No newline at end of file diff --git a/src/app.cairo b/src/app.cairo index 5253aef..dff85f2 100644 --- a/src/app.cairo +++ b/src/app.cairo @@ -21,22 +21,21 @@ const APP_MANIFEST: felt252 = 'BASE/manifests/myapp'; /// contracts must be named as such (APP_KEY + underscore + "actions") #[dojo::contract(namespace: "pixelaw", nomapping: true)] mod myapp_actions { - use starknet::{ - get_tx_info, get_caller_address, get_contract_address, get_execution_info, ContractAddress - }; - - use super::IMyAppActions; - use pixelaw::core::models::pixel::{Pixel, PixelUpdate}; - - use pixelaw::core::models::permissions::{Permission}; + use debug::PrintTrait; use pixelaw::core::actions::{ IActionsDispatcher as ICoreActionsDispatcher, IActionsDispatcherTrait as ICoreActionsDispatcherTrait }; - use super::{APP_KEY, APP_ICON, APP_MANIFEST}; + + use pixelaw::core::models::permissions::{Permission}; + use pixelaw::core::models::pixel::{Pixel, PixelUpdate}; use pixelaw::core::utils::{get_core_actions, Direction, Position, DefaultParameters}; + use starknet::{ + get_tx_info, get_caller_address, get_contract_address, get_execution_info, ContractAddress + }; - use debug::PrintTrait; + use super::IMyAppActions; + use super::{APP_KEY, APP_ICON, APP_MANIFEST}; // impl: implement functions specified in trait #[abi(embed_v0)] diff --git a/src/lib.cairo b/src/lib.cairo index 478a945..c241698 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -1,2 +1,2 @@ mod app; -mod tests; \ No newline at end of file +mod tests; diff --git a/src/tests.cairo b/src/tests.cairo index 34d8ea3..9cb5363 100644 --- a/src/tests.cairo +++ b/src/tests.cairo @@ -1,22 +1,22 @@ #[cfg(test)] mod tests { - use starknet::class_hash::Felt252TryIntoClassHash; use debug::PrintTrait; + use dojo::utils::test::{spawn_test_world}; + use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; - use pixelaw::core::models::registry::{app, app_name, core_actions_address}; + + use myapp::app::{myapp_actions, IMyAppActionsDispatcher, IMyAppActionsDispatcherTrait}; + use pixelaw::core::actions::{actions, IActionsDispatcher, IActionsDispatcherTrait}; + use pixelaw::core::models::permissions::{permissions}; use pixelaw::core::models::pixel::{Pixel, PixelUpdate}; use pixelaw::core::models::pixel::{pixel}; - use pixelaw::core::models::permissions::{permissions}; + use pixelaw::core::models::registry::{app, app_name, core_actions_address}; use pixelaw::core::utils::{ get_core_actions, encode_color, decode_color, Direction, Position, DefaultParameters }; - use pixelaw::core::actions::{actions, IActionsDispatcher, IActionsDispatcherTrait}; - - use dojo::utils::test::{spawn_test_world}; - - use myapp::app::{myapp_actions, IMyAppActionsDispatcher, IMyAppActionsDispatcherTrait}; + use starknet::class_hash::Felt252TryIntoClassHash; use zeroable::Zeroable; From 7affe51e225b47eef977fc62bc7df9c34c961602 Mon Sep 17 00:00:00 2001 From: Asuma Yamada Date: Sun, 15 Sep 2024 20:55:14 -0400 Subject: [PATCH 4/8] feat: cleanup repo --- .cursorrules | 73 ++++++++++++++++ .github/workflows/ci-contracts.yml | 33 ++++++++ README.md | 132 ++++++++--------------------- Scarb.lock | 2 + Scarb.toml | 32 ++++++- scripts/default_auth.sh | 49 ----------- scripts/init_auth.sh | 52 ++++++++++++ scripts/ready_for_deployment.sh | 10 --- scripts/upload_manifest.sh | 31 ------- src/app.cairo | 18 +--- src/lib.cairo | 2 +- 11 files changed, 226 insertions(+), 208 deletions(-) create mode 100644 .cursorrules create mode 100644 .github/workflows/ci-contracts.yml delete mode 100644 scripts/default_auth.sh create mode 100755 scripts/init_auth.sh delete mode 100644 scripts/ready_for_deployment.sh delete mode 100644 scripts/upload_manifest.sh diff --git a/.cursorrules b/.cursorrules new file mode 100644 index 0000000..484277f --- /dev/null +++ b/.cursorrules @@ -0,0 +1,73 @@ +You are an expert in Cairo, game development, ECS (Entity Component System), blockchain technology, Starknet, and the Dojo Framework. + +Key Principles + +- Write clear, concise, and idiomatic Cairo code with accurate examples. +- Use ECS paradigms effectively for game development. +- Prioritize modularity, clean code organization, and efficient resource management in Cairo and Dojo projects. +- Use expressive variable names that convey intent (e.g., `is_ready`, `has_data`). +- Adhere to Cairo's naming conventions: snake_case for variables and functions, PascalCase for types and structs. +- Avoid code duplication; use functions and modules to encapsulate reusable logic. +- Write code with safety, concurrency, and performance in mind, embracing Cairo's ownership and type system. + +Game Development with ECS + +- Implement ECS architecture using Dojo's components, systems, and world. +- Use Dojo's query system for efficient entity management and data access. +- Leverage Dojo's event system for game state changes and inter-system communication. +- Implement game loops and update cycles using Dojo's system execution order. +- Optimize performance by minimizing state changes and leveraging Dojo's batched updates. + +Smart Contract Development + +- Use Starknet-specific annotations and decorators for contract development. +- Implement storage variables and mappings using Starknet's storage model. +- Use events for logging important state changes in smart contracts. +- Implement view and external functions for contract interactions. +- Utilize Starknet's native types (e.g., felt252, ContractAddress) appropriately. + +Blockchain Integration + +- Implement cross-contract communication using contract calls and interfaces. +- Use Starknet's messaging system for L1-L2 communication. +- Implement account abstraction features for enhanced user experience. +- Utilize Starknet's cryptographic primitives for secure operations. + +Dojo Framework + +- Use Sozo for project scaffolding, building, and deployment. +- Leverage Katana for local development and testing of Starknet contracts. +- Utilize Torii for efficient indexing and querying of on-chain data. +- Implement and use actions for game state transitions. +- Use Dojo's authorization system for secure contract interactions. + +Testing and Deployment + +- Write unit tests for Cairo contracts using the `#[test]` attribute. +- Use Dojo's testing utilities for simulating game scenarios. +- Implement integration tests to validate contract interactions and game logic. +- Use Katana for local testing and Starknet's testnet for pre-production deployment. +- Leverage Sozo for managing contract migrations and upgrades. + +Performance Optimization + +- Minimize storage reads and writes in smart contracts. +- Use efficient data structures and algorithms for on-chain computations. +- Implement off-chain computations where possible, using on-chain verification. +- Optimize gas usage by batching transactions and using calldata efficiently. + Ï + Key Conventions + +1. Structure the application into modules: separate concerns like game logic, smart contracts, and off-chain components. +2. Use environment variables for configuration management in off-chain components. +3. Ensure code is well-documented with inline comments and Cairo-doc. + +Ecosystem + +- Use Cairo for smart contract development on Starknet. +- Leverage Scarb for package management and build processes. +- Use Dojo for game development on Starknet. +- Utilize Katana for local Starknet development environment. +- Implement off-chain components using languages like Rust or TypeScript for optimal performance. + +Refer to the Cairo Book, Starknet documentation, and Dojo documentation for in-depth information on best practices and advanced features.Ï diff --git a/.github/workflows/ci-contracts.yml b/.github/workflows/ci-contracts.yml new file mode 100644 index 0000000..8ca8257 --- /dev/null +++ b/.github/workflows/ci-contracts.yml @@ -0,0 +1,33 @@ +name: ci-contracts + +on: + push: + branches: [main] + + pull_request: + branches: [main] + +env: + CARGO_TERM_COLOR: always + RUST_VERSION: 1.80.1 + +jobs: + cairofmt: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: "2.7.0" + - run: | + scarb fmt --check + core-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: asdf-vm/actions/setup@v3 + - run: | + asdf plugin add dojo https://github.com/dojoengine/asdf-dojo + asdf install dojo 1.0.0-alpha.11 + asdf global dojo 1.0.0-alpha.11 + sozo test diff --git a/README.md b/README.md index 61a5fc1..57c3166 100644 --- a/README.md +++ b/README.md @@ -1,129 +1,67 @@ + +Dojo logo + + + + + + + + + +[![discord](https://img.shields.io/badge/join-pixelaw-green?logo=discord&logoColor=white)](https://discord.gg/PwDa2mKhR4) + # PixeLAW App Template Contracts written in Cairo using Dojo to showcase a Pixel World with app interoperability. Its interoperability is made possible with core actions. Apps are any other contracts that are deployed to the Pixel World. -## Development - -### Prerequisites +## Prerequisites - [asdf](https://asdf-vm.com/) - [scarb](https://docs.swmansion.com/scarb/) - [dojo](https://github.com/dojoengine/dojo) -### Install asdf +## Install asdf Follow the asdf installation instructions. -### Install dojo +## Install dojo ``` asdf plugin add dojo https://github.com/dojoengine/asdf-dojo asdf install dojo 1.0.0-alpha.11 ``` -### Install scarb +## Install scarb ``` asdf plugin add scarb -asdf install scarb 2.7.0-rc.4 +asdf install scarb 2.7.0 ``` And after moving into contracts directory, the versions for these libs are set in the .tool-versions file. -## Default Apps - -These are apps developed by PixeLAW - -## Paint - -### Overview - -The Paint App is a collection of functions that allow players to manipulate the color of a Pixel. - -### Properties - -None, Paint is just behavior. - -### Behavior - -- public `put_color(color)` - - context: position -- both `put_fading_color(color)` - - context: position -- public `remove_color()` - - context: position - -## Snake - -### Overview +## Running Locally -It it basically the game "snake", but with Pixels not necessarily available to move on/over. It is a player-initialized instance that coordinates pixel's color and text being overriden and reverted (if allowed). -If hitting an unowned Pixel, the snake will move, if Pixel is owned by player, Snake grows, and if Pixel is not owned but it's App allows Snake, it shrinks. In all other cases, Snake dies. +#### Terminal one (Make sure this is running) -### Properties - -- position -- color -- text -- direction - -### Behavior - -- public `spawn(color, text, direction)` - - context: position -- public `turn(snake_id, direction)` - - context: player -- private `move(snake_id)` - -## Rock Paper Scissors - -### Overview - -Each Pixel can contain an instance of the RPS App, where it holds a commitment (rock, paper or scissors) from player1. Any other player can now "join" and submit their move. Player1 can then reveal, the winner is decided then. Winner gains ownership of the losing RPS pixel. In case of a draw, the pixel is reset. -The App is also tracking score for each Player. - -### Global Properties - -- player+wins - -### Game-based Properties - -- player1 -- player2 - -### Behavior - -- create (position, player1, commit1) -- join (position, player2, move2) -- finish (position, move1, salt1) -- reset (position) +```bash +# Run Katana +katana --disable-fee --allowed-origins "*" +``` -## CommitReveal inputs +#### Terminal two -### Param of the action +```bash +# Build the example +sozo build -- (Hashed Commit) - - parametername of action has structure: "PREFIX_TYPE_NAME" - - PREFIX is "cr\_" - - TYPE for now is the name of an int, felt or Enum declared in the manifest - - NAME is a chosen name to refer to the param. -- (Value+Salt reveal) - - parametername of action has structure: "PREFIX_NAME" - - PREFIX shall always be "rv\_" - - NAME is the same name user during sending the commit +# Migrate the example +sozo migrate apply -### Clientside functioning +# Initialize the pixelaw app +scarb run init_auth -- If client finds a param starting with "cr\_" -- It will prompt user for a param with TYPE - - example: - - The game RPS needs player1 to choose one option, but only send the hashedcommit - - Then, during a next stage of the game, the plaintext move and the salt will be requested - - The challenge is that the UI needsto be capable of doing this without knowing about the specific application. Reveal/Commit is a feature of the platform. - - Commit - - RpsMove is an enum with 3 fields, so ui presents user with 3 choices - - UI stores this clientside related to the pixel/app - - UI then hashes this with a salt, and also stores the salt with the choice - - UI then calls the functions with only the hash value - - Reveal - - there will be 2 params: "rv_NAME" (the actual param) and "rs_NAME" (the used salt) +# Start Torii +torii --world 0x263ae44e5414519a5c5a135cccaf3d9d7ee196d37e8de47a178da91f3de9b34 --allowed-origins "*" +``` diff --git a/Scarb.lock b/Scarb.lock index 544bc90..ca7dd89 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -18,12 +18,14 @@ source = "git+https://github.com/dojoengine/dojo?rev=f15def33#f15def330c0d099e79 name = "myapp" version = "0.0.0" dependencies = [ + "dojo", "pixelaw", ] [[package]] name = "pixelaw" version = "0.3.50" +source = "git+https://github.com/pixelaw/core?tag=v0.3.50#78abcff1835740411f785b65e84941c3f7ee59b6" dependencies = [ "dojo", ] diff --git a/Scarb.toml b/Scarb.toml index b8b21b9..dbeef9d 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -7,11 +7,35 @@ version = "0.0.0" sierra-replace-ids = true [dependencies] -pixelaw = { path = "/Users/asumayamada/Private/pixelaw/core/contracts" } -# pixelaw = { git = "https://github.com/pixelaw/core", tag = "v0.3.50" } +pixelaw = { git = "https://github.com/pixelaw/core", tag = "v0.3.50" } +# Added explicitly for https://github.com/dojoengine/dojo/issues/2430 +dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-alpha.11" } [[target.dojo]] -build-external-contracts = [] +build-external-contracts = [ + "pixelaw::core::models::pixel::pixel", + "pixelaw::core::models::pixel::Pixel", + "pixelaw::core::models::pixel::PixelUpdate", + "pixelaw::core::models::queue::queue_item", + "pixelaw::core::models::registry::app", + "pixelaw::core::models::registry::app_name", + "pixelaw::core::models::registry::app_user", + "pixelaw::core::models::registry::app_instruction", + "pixelaw::core::models::registry::instruction", + "pixelaw::core::models::registry::core_actions_address", + "pixelaw::core::models::permissions::permissions", + "pixelaw::core::utils::get_core_actions", + "pixelaw::core::utils::Direction", + "pixelaw::core::utils::Position", + "pixelaw::core::utils::DefaultParameters", + "pixelaw::core::actions::actions", + "pixelaw::core::actions::IActionsDispatcher", + "pixelaw::core::actions::IActionsDispatcherTrait", +] [tool.fmt] -sort-module-level-items = true \ No newline at end of file +sort-module-level-items = true + + +[scripts] +init_auth = "./scripts/init_auth.sh" \ No newline at end of file diff --git a/scripts/default_auth.sh b/scripts/default_auth.sh deleted file mode 100644 index 8541c33..0000000 --- a/scripts/default_auth.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash -set -euo pipefail -pushd $(dirname "$0")/.. - - -export APP_NAME=$(grep "^name" Scarb.toml | awk -F' = ' '{print $2}' | tr -d '"') -# export ACTIONS_ADDRESS=$(cat ./target/$SCARB_PROFILE/manifest.json | jq -r '.contracts | first | .address') -export ACTIONS_ADDRESS=$(cat ./manifests/dev/manifest.json | jq -r '.contracts | first | .address') - -echo "---------------------------------------------------------------------------" -echo app : $APP_NAME -echo " " -echo actions : $ACTIONS_ADDRESS -echo "---------------------------------------------------------------------------" - -# enable system -> component authorizations -# COMPONENTS=($(jq -r --arg APP_NAME "$APP_NAME" '.models[] | select(.name | contains($APP_NAME)) | .name' ./target/dev/manifest.json)) -COMPONENTS=($(jq -r --arg APP_NAME "$APP_NAME" '.models[] | select(.name | contains($APP_NAME)) | .name' ./manifests/dev/manifest.json)) - -for index in "${!COMPONENTS[@]}"; do - IFS='::' read -ra NAMES <<< "${COMPONENTS[index]}" - LAST_INDEX=${#NAMES[@]}-1 - NEW_NAME=`echo ${NAMES[LAST_INDEX]} | sed -r 's/_/ /g' | awk '{for(j=1;j<=NF;j++){ $j=toupper(substr($j,1,1)) substr($j,2) }}1' | sed -r 's/ //g'` - COMPONENTS[index]=$NEW_NAME -done - -# if #COMPONENTS is 0, then there are no models in the manifest. This might be error, -echo "Write permissions for ACTIONS" -if [ ${#COMPONENTS[@]} -eq 0 ]; then - echo "Warning: No models found in manifest.json. Are you sure you don't have new any components?" -else - for component in ${COMPONENTS[@]}; do - echo "For $component" - # sozo --profile $SCARB_PROFILE auth grant writer $component,$ACTIONS_ADDRESS - sozo --profile dev auth grant writer $component,$ACTIONS_ADDRESS - done -fi -echo "Write permissions for ACTIONS: Done" - -# echo "Initialize ACTIONS: (sozo --profile $SCARB_PROFILE execute $ACTIONS_ADDRESS init)" -echo "Initialize ACTIONS: (sozo --profile dev execute $ACTIONS_ADDRESS init)" - -sleep 0.1 -# sozo --profile $SCARB_PROFILE execute $ACTIONS_ADDRESS init -sozo --profile dev execute $ACTIONS_ADDRESS init -echo "Initialize ACTIONS: Done" - - -echo "Default authorizations have been successfully set." diff --git a/scripts/init_auth.sh b/scripts/init_auth.sh new file mode 100755 index 0000000..609de55 --- /dev/null +++ b/scripts/init_auth.sh @@ -0,0 +1,52 @@ +#!/bin/bash +set -euo pipefail +pushd $(dirname "$0")/.. + +echo $SCARB_PROFILE + +# Get the profile from $SCARB_PROFILE +profile=${SCARB_PROFILE:-"dev"} + +# Read values from dojo_${profile}.toml +config_file="dojo_${profile}.toml" + +if [ ! -f "$config_file" ]; then + echo "Error: $config_file not found" + exit 1 +fi + +# Extract values using grep and cut +account_address=$(grep "account_address" "$config_file" | cut -d'"' -f2) +private_key=$(grep "private_key" "$config_file" | cut -d'"' -f2) +world_address=$(grep "world_address" "$config_file" | cut -d'"' -f2) + +declare "CORE_ACTIONS"="pixelaw-actions" +declare "MYAPP_ACTIONS"="pixelaw-myapp_actions" + +## Set RPC_URL with default value +#RPC_URL="http://localhost:5050" + +# Check if a command line argument is supplied +if [ $# -gt 0 ]; then + # If an argument is supplied, use it as the RPC_URL + RPC_URL=$1 +fi + +# make sure all components/systems are deployed +CORE_MODELS=("pixelaw-App" "pixelaw-AppName" "pixelaw-CoreActionsAddress" "pixelaw-Pixel" "pixelaw-Permissions" "pixelaw-QueueItem" "pixelaw-Instruction") + +echo "Write permissions for CORE_ACTIONS" +for model in ${CORE_MODELS[@]}; do + sleep 0.1 + sozo --profile $SCARB_PROFILE auth grant writer model:$model,$CORE_ACTIONS +done +echo "Write permissions for CORE_ACTIONS: Done" + +echo "Initialize CORE_ACTIONS : $CORE_ACTIONS" +sleep 0.1 +sozo --profile $SCARB_PROFILE execute $CORE_ACTIONS init +echo "Initialize CORE_ACTIONS: Done" + +sleep 0.1 +sozo --profile $SCARB_PROFILE execute $MYAPP_ACTIONS init +echo "Initialize MYAPP_ACTIONS: Done" diff --git a/scripts/ready_for_deployment.sh b/scripts/ready_for_deployment.sh deleted file mode 100644 index 363b100..0000000 --- a/scripts/ready_for_deployment.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -while true; do - response=$(curl -s http://localhost:3000/manifests/core) - if [[ $response != *"Not Found"* ]]; then - echo "Ready for app deployment" - break - fi - sleep 1 -done diff --git a/scripts/upload_manifest.sh b/scripts/upload_manifest.sh deleted file mode 100644 index 9ea3363..0000000 --- a/scripts/upload_manifest.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -APP_NAME=$(grep "^name" ./Scarb.toml | awk -F' = ' '{print $2}' | tr -d '"') -echo "APP_NAME : $APP_NAME" -SYSTEMS=("core" "paint" "snake" "$APP_NAME") - -DEFAULT_BASE_URL="http://localhost:3000/manifests" -# JSON_FILE="./target/dev/manifest.json" -JSON_FILE="./manifests/dev/manifest.json" - -# Check if a command line argument is provided -if [ "$#" -ne 0 ]; then - BASE_URL="$1" -else - BASE_URL="$DEFAULT_BASE_URL" -fi - -echo "---------------------------------------------------------------------------" -echo BASE_URL : $BASE_URL -echo "---------------------------------------------------------------------------" - -echo "Uploading manifests for system" -echo " " -for system in ${SYSTEMS[@]}; do - echo "Uploading manifest for" $system - URL="${BASE_URL}/${system}" - curl -X POST -H "Content-Type: application/json" -d @"$JSON_FILE" "$URL" - echo " " - echo "Uploading manifest for" $system ": DONE" - echo " " -done diff --git a/src/app.cairo b/src/app.cairo index dff85f2..1327364 100644 --- a/src/app.cairo +++ b/src/app.cairo @@ -4,7 +4,7 @@ use pixelaw::core::utils::{get_core_actions, Direction, Position, DefaultParamet use starknet::{get_caller_address, get_contract_address, get_execution_info, ContractAddress}; #[dojo::interface] -trait IMyAppActions { +pub trait IMyAppActions { fn init(ref world: IWorldDispatcher); fn interact(ref world: IWorldDispatcher, default_params: DefaultParameters); } @@ -20,7 +20,7 @@ const APP_MANIFEST: felt252 = 'BASE/manifests/myapp'; /// contracts must be named as such (APP_KEY + underscore + "actions") #[dojo::contract(namespace: "pixelaw", nomapping: true)] -mod myapp_actions { +pub mod myapp_actions { use debug::PrintTrait; use pixelaw::core::actions::{ IActionsDispatcher as ICoreActionsDispatcher, @@ -45,20 +45,6 @@ mod myapp_actions { let core_actions = pixelaw::core::utils::get_core_actions(world); core_actions.update_app(APP_KEY, APP_ICON, APP_MANIFEST); - - //Grant permission to the snake App - core_actions - .update_permission( - 'snake', - Permission { - app: false, - color: true, - owner: false, - text: true, - timestamp: false, - action: true - } - ); } /// Put color on a certain position diff --git a/src/lib.cairo b/src/lib.cairo index c241698..5c5d798 100644 --- a/src/lib.cairo +++ b/src/lib.cairo @@ -1,2 +1,2 @@ -mod app; +pub mod app; mod tests; From 188eba4a020a8587ec3ad0848f3791e1f41b655e Mon Sep 17 00:00:00 2001 From: Asuma Yamada Date: Sun, 15 Sep 2024 20:57:07 -0400 Subject: [PATCH 5/8] fix: dark mode --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 57c3166..377b3f5 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ + Dojo logo From 82898576a2c58e73b8b65e144e3c29bde214be0b Mon Sep 17 00:00:00 2001 From: Asuma Yamada Date: Sun, 15 Sep 2024 21:22:37 -0400 Subject: [PATCH 6/8] fix: test --- README.md | 10 ++++++++++ Scarb.toml | 4 +++- dojo_release.toml | 1 - src/tests.cairo | 12 +++++------- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 377b3f5..098072c 100644 --- a/README.md +++ b/README.md @@ -66,3 +66,13 @@ scarb run init_auth # Start Torii torii --world 0x263ae44e5414519a5c5a135cccaf3d9d7ee196d37e8de47a178da91f3de9b34 --allowed-origins "*" ``` + +### How to deploy + +you can deploy your app to the our katana testnet by running the following commands: + +```bash +# Deploy the pixelaw app +sozo build -P release +sozo migrate apply -P release +``` diff --git a/Scarb.toml b/Scarb.toml index dbeef9d..2a13064 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -13,6 +13,8 @@ dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-alpha.11" } [[target.dojo]] build-external-contracts = [ + "pixelaw::apps::snake::app::snake", + "pixelaw::apps::snake::app::snake_segment", "pixelaw::core::models::pixel::pixel", "pixelaw::core::models::pixel::Pixel", "pixelaw::core::models::pixel::PixelUpdate", @@ -38,4 +40,4 @@ sort-module-level-items = true [scripts] -init_auth = "./scripts/init_auth.sh" \ No newline at end of file +init_auth = "./scripts/init_auth.sh" diff --git a/dojo_release.toml b/dojo_release.toml index 4637002..0b70e80 100644 --- a/dojo_release.toml +++ b/dojo_release.toml @@ -15,4 +15,3 @@ mappings = {} rpc_url = "https://api.cartridge.gg/x/pixelaw-dev/katana/" account_address = "0x5233cfca86bfa18af0bdef2fd09ac4c1d7c8da71303eb7fc9997fc6d0914d0d" private_key = "0xf0e37335d0c020789dd02c0460d99637ac23bd2df3d1d25002fd15621542d" -world_address = "0x99b8dbc71926673405f5dfff9e4900ee4d9249798cc5e7ac6f3c3a07907399" diff --git a/src/tests.cairo b/src/tests.cairo index 9cb5363..b2492f2 100644 --- a/src/tests.cairo +++ b/src/tests.cairo @@ -1,7 +1,6 @@ #[cfg(test)] mod tests { use debug::PrintTrait; - use dojo::utils::test::{spawn_test_world}; use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; @@ -22,7 +21,6 @@ mod tests { // Helper function: deploys world and actions fn deploy_world() -> (IWorldDispatcher, IActionsDispatcher, IMyAppActionsDispatcher) { - // Deploy World and models let mut models = array![ pixel::TEST_CLASS_HASH, app::TEST_CLASS_HASH, @@ -43,11 +41,11 @@ mod tests { let myapp_actions = IMyAppActionsDispatcher { contract_address: myapp_actions_address }; // Setup dojo auth - world.grant_writer('Pixel', core_actions_address); - world.grant_writer('App', core_actions_address); - world.grant_writer('AppName', core_actions_address); - world.grant_writer('CoreActionsAddress', core_actions_address); - world.grant_writer('Permissions', core_actions_address); + world.grant_writer(selector_from_tag!("pixelaw-Pixel"), core_actions_address); + world.grant_writer(selector_from_tag!("pixelaw-App"), core_actions_address); + world.grant_writer(selector_from_tag!("pixelaw-AppName"), core_actions_address); + world.grant_writer(selector_from_tag!("pixelaw-Permissions"), core_actions_address); + world.grant_writer(selector_from_tag!("pixelaw-CoreActionsAddress"), core_actions_address); // PLEASE ADD YOUR APP PERMISSIONS HERE From 91868e72db07379cd3c5312f463cfb09680ae3ad Mon Sep 17 00:00:00 2001 From: Asuma Yamada Date: Sun, 15 Sep 2024 21:26:35 -0400 Subject: [PATCH 7/8] fix: link --- README.md | 6 +++--- dojo_release.toml | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 098072c..9e6007f 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,14 @@ Dojo logo - + -[![discord](https://img.shields.io/badge/join-pixelaw-green?logo=discord&logoColor=white)](https://discord.gg/PwDa2mKhR4) +[![discord](https://img.shields.io/badge/join-PixeLAW-green?logo=discord&logoColor=white)](https://t.co/jKDjNbFdZ5) # PixeLAW App Template @@ -69,7 +69,7 @@ torii --world 0x263ae44e5414519a5c5a135cccaf3d9d7ee196d37e8de47a178da91f3de9b34 ### How to deploy -you can deploy your app to the our katana testnet by running the following commands: +you can deploy your app to our katana testnet by running the following commands: ```bash # Deploy the pixelaw app diff --git a/dojo_release.toml b/dojo_release.toml index 0b70e80..3c43c4a 100644 --- a/dojo_release.toml +++ b/dojo_release.toml @@ -4,7 +4,7 @@ name = "pixelaw" seed = "pixelaw" [world.socials] -x = "https://x.com/pixelaw" +x = "https://x.com/0xpixelaw" github = "https://github.com/pixelaw" [namespace] From 9c5f186691675ab65f5e3c3e5489d0962ec73e68 Mon Sep 17 00:00:00 2001 From: Asuma Yamada Date: Sun, 15 Sep 2024 21:30:54 -0400 Subject: [PATCH 8/8] update readme --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 9e6007f..51de244 100644 --- a/README.md +++ b/README.md @@ -76,3 +76,30 @@ you can deploy your app to our katana testnet by running the following commands: sozo build -P release sozo migrate apply -P release ``` + + +## Troubleshooting + +If you want to use latest dojo version, you need to clone core by yourself and modify the path in `Scarb.toml` file. + +1. Clone core repo +```bash +git clone https://github.com/pixelaw/core +``` + +2. Modify the path in `Scarb.toml` file +```Scarb.toml +pixelaw = { path = "../pixelaw/core/contracts" } +``` + +3. Modify version in `Scarb.toml` file in core repo +```Scarb.toml +dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.0-alpha.11" } +``` + +4. Build and run core +```bash +cd contracts +sozo build +sozo migrate apply +``` \ No newline at end of file