From e7f88eed642f4ccd1b619002266c4a3ff266fdcf Mon Sep 17 00:00:00 2001 From: DogLooksGood Date: Mon, 25 Dec 2023 13:07:57 +0800 Subject: [PATCH] Update dev scripts --- Justfile | 4 +- dev/Justfile | 14 +++ dev/README.md | 110 +--------------------- dev/flake.lock | 61 ++++++++++++ dev/flake.nix | 27 ++++++ dev/game-specs/holdem-cash.json | 13 +++ dev/{ => layouts}/demo-app.kdl | 14 +-- dev/{ => layouts}/durak-simple.kdl | 8 +- dev/{ => layouts}/holdem-multi.kdl | 12 +-- dev/{ => layouts}/holdem-simple.kdl | 9 +- dev/{ => layouts}/mtt-simple.kdl | 8 +- dev/prepare.sh | 133 --------------------------- dev/{ => scripts}/create-mtt-game.sh | 2 +- dev/server-confs/server1.toml | 12 +++ dev/server-confs/server2.toml | 12 +++ flake.nix | 5 +- 16 files changed, 173 insertions(+), 271 deletions(-) create mode 100644 dev/Justfile create mode 100644 dev/flake.lock create mode 100644 dev/flake.nix create mode 100644 dev/game-specs/holdem-cash.json rename dev/{ => layouts}/demo-app.kdl (70%) rename dev/{ => layouts}/durak-simple.kdl (66%) rename dev/{ => layouts}/holdem-multi.kdl (62%) rename dev/{ => layouts}/holdem-simple.kdl (68%) rename dev/{ => layouts}/mtt-simple.kdl (72%) delete mode 100755 dev/prepare.sh rename dev/{ => scripts}/create-mtt-game.sh (86%) create mode 100644 dev/server-confs/server1.toml create mode 100644 dev/server-confs/server2.toml diff --git a/Justfile b/Justfile index 8026d5f2..6114541f 100644 --- a/Justfile +++ b/Justfile @@ -73,9 +73,11 @@ dev-facade *ARGS: dev-reg-transactor conf: cargo run -p race-transactor -- -c {{conf}} reg -dev-transactor conf: +dev-run-transactor conf: cargo run -p race-transactor -- -c {{conf}} run +dev-transactor conf: (dev-reg-transactor conf) (dev-run-transactor conf) + facade-transactor num: cargo run -p race-transactor -- -c examples/conf/server{{num}}.toml reg cargo run -p race-transactor -- -c examples/conf/server{{num}}.toml run diff --git a/dev/Justfile b/dev/Justfile new file mode 100644 index 00000000..43fcaf41 --- /dev/null +++ b/dev/Justfile @@ -0,0 +1,14 @@ +holdem-simple: + zellij --layout layouts/holdem-simple.kdl + +holdem-multi: + zellij --layout layouts/holdem-multi.kdl + +durak-simple: + zellij --layout layouts/durak-simple.kdl + +demo-app: + zellij --layout layouts/demo-app.kdl + +mtt-simple: + zellij --layout layouts/mtt-simple.kdl diff --git a/dev/README.md b/dev/README.md index 3f5350fe..ab730aa0 100644 --- a/dev/README.md +++ b/dev/README.md @@ -1,109 +1,3 @@ -# Prepare Solana development environment +# Dev Scripts for Race Development -## Load Metaplex into local test validator - -```bash -solana program dump -u m metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s token_metadata_program.so - -# This will reset the test-ledger -solana-test-validator --bpf-program metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s token_metadata_program.so --reset -``` - -## Create a token for testing - -```bash -spl-token create-token - -spl-token create-account - -spl-token mint -``` -We use this token for following tests. - -## Deploy RACE contract to solana localnet - -``` shell -just solana -``` - - -## Publish game bundle - -Uploaded NFT metadata on Arweave: - -- Chat: https://arweave.net/6SOGM007lgaeBH1SOJ-Ifm9eUUNz4kCdRqVJe-yl9_g -- Raffle: https://arweave.net/hTlRRw2tZ2q_RpklixjRIzrR3PgAChBujAKzp6wknHs - -```shell -just publish Chat https://arweave.net/6SOGM007lgaeBH1SOJ-Ifm9eUUNz4kCdRqVJe-yl9_g -just publish Raffle https://arweave.net/hTlRRw2tZ2q_RpklixjRIzrR3PgAChBujAKzp6wknHs -``` - -NFT addresses will be returned when upload succeed. Later we will use this NFT token address as **bundle address**. - -## Create game registration - -```shell -just create-reg -``` - -## Create game accounts - -To create games, a spec file in JSON is required. Replace the addresses with what you have, and save it as `spec.json`. - -```json -{ - "title": "", - "reg_addr": "", - "bundle_addr": "", - "token_addr": "", - "max_players": 10, - "min_deposit": 10, - "max_deposit": 20, - "data": [] -} -``` - -Create the game account with command line tool. - -```shell -just create-game spec.json -``` - -Game account address will be returned. - -## Generate a keypair for transactor - -```shell -solana-keygen new -o transactor.json - -# Transfer some SOL to this new account -solana transfer --allow-unfunded-recipient 2 -``` - -## Create transactor configuration file - -```toml -[transactor] -port = 12003 -endpoint = "ws://localhost:12003" -chain = "solana" -address = "" -reg_addresses = [""] - -[solana] -keyfile = /path/to/transactor.json -rpc = "http://localhost:8899" -``` - -## Register server - -``` shell -just dev-reg-transactor /path/to/transactor.toml -``` - -## Start transactor - -```shell -just dev-transactor /path/to/transactor.toml -``` +This folder contains the scripts and configurations for local development on Race Protocol. diff --git a/dev/flake.lock b/dev/flake.lock new file mode 100644 index 00000000..a372141a --- /dev/null +++ b/dev/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1687709756, + "narHash": "sha256-Y5wKlQSkgEK2weWdOu4J3riRd+kV/VCgHsqLNTTWQ/0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1703034876, + "narHash": "sha256-4bMPFv/bs5g1nEsXQwXlrAGJgjv1Ilr0ejdaTkBwQLs=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "312ab59e8ade69e6083017bd9b98a2919f1fb86a", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/dev/flake.nix b/dev/flake.nix new file mode 100644 index 00000000..39c28430 --- /dev/null +++ b/dev/flake.nix @@ -0,0 +1,27 @@ +{ + description = "Dev scripts for Race Protocol"; + + inputs = { + nixpkgs = { url = "github:NixOS/nixpkgs/nixos-23.05"; }; + flake-utils = { url = "github:numtide/flake-utils"; }; + }; + + outputs = { self, nixpkgs, flake-utils }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; }; + in + { + devShell = pkgs.mkShell { + buildInputs = with pkgs; [ + just + zellij + ]; + }; + } + ); + + nixConfig = { + bash-prompt-prefix = "[flake]"; + }; +} diff --git a/dev/game-specs/holdem-cash.json b/dev/game-specs/holdem-cash.json new file mode 100644 index 00000000..67ab62df --- /dev/null +++ b/dev/game-specs/holdem-cash.json @@ -0,0 +1,13 @@ +{ + "title": "Cash Table", + "bundle": "../race-holdem/target/race_holdem_cash.wasm", + "token": "FACADE_USDC", + "maxPlayers": 6, + "entryType": { + "cash": { + "minDeposit": 1000000, + "maxDeposit": 3000000 + } + }, + "data": [16,39,0,0,0,0,0,0,32,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0] +} diff --git a/dev/demo-app.kdl b/dev/layouts/demo-app.kdl similarity index 70% rename from dev/demo-app.kdl rename to dev/layouts/demo-app.kdl index 958ee67c..048377ec 100644 --- a/dev/demo-app.kdl +++ b/dev/layouts/demo-app.kdl @@ -6,15 +6,15 @@ layout { pane { name "Facade" focus true - cwd "./" + cwd "../" command "just" - args "dev-facade" "examples/draw-card/facade.json" + args "dev-facade" "-g" "examples/draw-card/facade.json" start_suspended true } pane { name "Vite" focus true - cwd "./" + cwd "../" command "just" args "dev-demo-app" } @@ -24,15 +24,15 @@ layout { pane { name "Transactor" command "just" - cwd "./" - args "facade-transactor" "1" + cwd "../" + args "dev-transactor" "dev/server-confs/server1.toml" start_suspended true } pane { name "Transactor" command "just" - cwd "./" - args "facade-transactor" "2" + cwd "../" + args "dev-transactor" "dev/server-confs/server2.toml" start_suspended true } } diff --git a/dev/durak-simple.kdl b/dev/layouts/durak-simple.kdl similarity index 66% rename from dev/durak-simple.kdl rename to dev/layouts/durak-simple.kdl index 07ffa970..2b6a43c9 100644 --- a/dev/durak-simple.kdl +++ b/dev/layouts/durak-simple.kdl @@ -5,17 +5,17 @@ layout { pane { name "Facade" focus true - cwd "./" + cwd "../" command "just" - args "dev-facade" "../durak/conf/heads_up.json" "../durak/conf/3players.json" + args "dev-facade" "-g" "../durak/conf/heads_up.json" "-g" "../durak/conf/3players.json" start_suspended true } pane split_direction="horizontal" { pane { name "Transactor" command "just" - cwd "./" - args "facade-transactor" "1" + cwd "../" + args "dev-transactor" "dev/server-confs/server1.toml" start_suspended true } pane diff --git a/dev/holdem-multi.kdl b/dev/layouts/holdem-multi.kdl similarity index 62% rename from dev/holdem-multi.kdl rename to dev/layouts/holdem-multi.kdl index 14dfb8c3..92d77b19 100644 --- a/dev/holdem-multi.kdl +++ b/dev/layouts/holdem-multi.kdl @@ -4,24 +4,24 @@ layout { pane { name "Facade" focus true - cwd "./" + cwd "../" command "just" - args "dev-facade" "../race-holdem/cash/facade.json" + args "dev-facade" "-g" "../race-holdem/cash/facade.json" start_suspended true } pane split_direction="vertical" { pane { name "Transactor 1" command "just" - cwd "./" - args "facade-transactor" "1" + cwd "../" + args "dev-transactor" "dev/server-confs/server1.toml" start_suspended true } pane { name "Transactor 2" command "just" - cwd "./" - args "facade-transactor" "2" + cwd "../" + args "dev-transactor" "dev/server-confs/server2.toml" start_suspended true } } diff --git a/dev/holdem-simple.kdl b/dev/layouts/holdem-simple.kdl similarity index 68% rename from dev/holdem-simple.kdl rename to dev/layouts/holdem-simple.kdl index 7dc584ff..57c77f42 100644 --- a/dev/holdem-simple.kdl +++ b/dev/layouts/holdem-simple.kdl @@ -5,17 +5,16 @@ layout { pane { name "Facade" focus true - cwd "./" + cwd "../" command "just" - args "dev-facade" "../race-holdem/cash/facade.json" - start_suspended true + args "dev-facade" "-g" "dev/game-specs/holdem-cash.json" } pane split_direction="horizontal" { pane { name "Transactor" command "just" - cwd "./" - args "facade-transactor" "1" + cwd "../" + args "dev-transactor" "dev/server-confs/server1.toml" start_suspended true } pane diff --git a/dev/mtt-simple.kdl b/dev/layouts/mtt-simple.kdl similarity index 72% rename from dev/mtt-simple.kdl rename to dev/layouts/mtt-simple.kdl index 9efb057d..53105b4d 100644 --- a/dev/mtt-simple.kdl +++ b/dev/layouts/mtt-simple.kdl @@ -5,17 +5,17 @@ layout { pane { name "Facade" focus true - cwd "./" + cwd "../" command "bash" - args "dev/create-mtt-game.sh" + args "dev/scripts/create-mtt-game.sh" start_suspended true } pane split_direction="horizontal" { pane { name "Transactor" command "just" - cwd "./" - args "facade-transactor" "1" + cwd "../" + args "facade-transactor" "dev/server-confs/server1.toml" start_suspended true } pane diff --git a/dev/prepare.sh b/dev/prepare.sh deleted file mode 100755 index 15ea079d..00000000 --- a/dev/prepare.sh +++ /dev/null @@ -1,133 +0,0 @@ -#!/bin/bash - -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) - -set -e - -echo "Preparing the local environment..." -echo "The keypair at $HOME/.config/solana/id.json will be used" -echo "Create a SPL token for testing..." - - -if solana config get | grep 'RPC URL: http://localhost:8899'; -then - echo "Confirmed LOCAL network is used" -else - echo "Exit due to mainnet is used" - exit 1 -fi - -echo "Airdrop 10SOL..." -solana airdrop 10 - -TOKEN=$(spl-token create-token --decimals 0 | grep 'Address' | awk '{print $2}') -echo "Token: $TOKEN will be used for games" -spl-token create-account "$TOKEN" -spl-token mint $TOKEN 1000000 - -mkdir -p dist -echo "Generate game bundle NFT metadata..." -cat < dist/race_example_raffle_metadata.json -{ - "name": "RACE Example Raffle", - "symbol": "RACE", - "description": "Example raffle game", - "seller_fee_basis_points": 0, - "image": "https://arweave.net/OQx85OOqT0oawKjCS9f5PowBF_5Y8hkJ8DI5fvMjd-s", - "external_url": "", - "attributes": [], - "properties": { - "files": [ - { - "uri": "https://arweave.net/OQx85OOqT0oawKjCS9f5PowBF_5Y8hkJ8DI5fvMjd-s", - "type": "image/png" - }, - { - "uri": "http://127.0.0.1:8000/race_example_raffle.wasm", - "type": "application/wasm" - } - ], - "category": "image", - "creators": [ - { - "address": "J22ir2nLxVRqUrcpwMDBM47HpFCLLRrKFroF6LjK7DEA", - "share": 100 - } - ] - } -} -EOF - -echo "Compile Raffle example..." -just example-raffle -cp ../target/race_example_raffle.wasm dist/ - -echo "Publishing WASM as game bundle NFT" -BUNDLE=$(just publish Raffle 'http://127.0.0.1:8000/race_example_raffle_metadata.json' | grep 'Address' | awk '{print $2}') -echo "Raffle is published as NFT at $BUNDLE" - -echo "Create registration center..." -REG=$(just create-reg | grep 'Address' | awk '{print $2}') -echo "Registration: $REG will be used" - -echo "Generate game spec..." -cat < dist/raffle.spec.json -{ - "title": "My Raffle", - "reg_addr": "$REG", - "bundle_addr": "$BUNDLE", - "token_addr": "$TOKEN", - "max_players": 10, - "min_deposit": 1, - "max_deposit": 2, - "data": [] -} -EOF - -echo "Create game..." -GAME=$(just create-game $SCRIPT_DIR/dist/raffle.spec.json | grep 'Address' | awk '{print $2}') -echo "A game of raffle is created at $GAME" - -echo "Generate a keypair for transactor..." -solana-keygen new -o dist/transactor-keypair.json --no-bip39-passphrase -s -f -# solana airdrop 10 dist/transactor-keypair.json -TRANSACTOR=$(solana-keygen pubkey dist/transactor-keypair.json) -solana airdrop 10 dist/transactor-keypair.json --commitment finalized - -echo "Generate server configuration..." -TX_PATH=$SCRIPT_DIR/dist/transactor-keypair.json -cat < dist/transactor.toml -[transactor] -port = 12003 -endpoint = "ws://localhost:12003" -chain = "solana" -address = "$TRANSACTOR" -reg_addresses = ["$REG"] - -[solana] -keyfile = "$TX_PATH" -rpc = "http://localhost:8899" -EOF - -echo "Create server account..." -just dev-reg-transactor $SCRIPT_DIR/dist/transactor.toml - -echo "Generate demo-app-data..." -cat < dist/demo-app-data.json -{ - "CHAIN_TO_REG_ADDR": { - "solana-local": "$REG" - }, - "CHAIN_ADDR_GAME_MAPPING": { - "solana-local": { - "$BUNDLE": "raffle" - } - } -} -EOF - -echo "That's it! -Start a server to simulate AR storage and provide data for demo-app: simple-http-server --cors -- dist -Now you can start the transactor with: just dev-transactor ${SCRIPT_DIR}/dist/transactor.toml -And open the demo app with: just ts-sdk dev-sdk dev-demo-app -" diff --git a/dev/create-mtt-game.sh b/dev/scripts/create-mtt-game.sh similarity index 86% rename from dev/create-mtt-game.sh rename to dev/scripts/create-mtt-game.sh index ba54322b..b1c52f3e 100644 --- a/dev/create-mtt-game.sh +++ b/dev/scripts/create-mtt-game.sh @@ -29,4 +29,4 @@ EOF echo "$JSON" echo "$JSON" > /tmp/race-mtt-facade.json -just dev-facade /tmp/race-mtt-facade.json +just dev-facade -g /tmp/race-mtt-facade.json -b ../race-holdem/target/race_holdem_mtt_table.wasm diff --git a/dev/server-confs/server1.toml b/dev/server-confs/server1.toml new file mode 100644 index 00000000..8ca83997 --- /dev/null +++ b/dev/server-confs/server1.toml @@ -0,0 +1,12 @@ +[transactor] +port = 12003 +endpoint = "ws://localhost:12003" +chain = "facade" +address = "Server 1" +reg_addresses = ["DEFAULT_REGISTRATION_ADDRESS"] +disable_blacklist = true + +[facade] +host = "http://localhost:12002" +registration_address = "DEFAULT_REGISTRATION_ADDRESS" +address = "Server 1" diff --git a/dev/server-confs/server2.toml b/dev/server-confs/server2.toml new file mode 100644 index 00000000..c40260f7 --- /dev/null +++ b/dev/server-confs/server2.toml @@ -0,0 +1,12 @@ +[transactor] +port = 12004 +endpoint = "ws://localhost:12004" +chain = "facade" +address = "Server 2" +reg_addresses = ["DEFAULT_REGISTRATION_ADDRESS"] +disable_blacklist = true + +[facade] +host = "http://localhost:12002" +registration_address = "DEFAULT_REGISTRATION_ADDRESS" +address = "Server 2" diff --git a/flake.nix b/flake.nix index ec6d8ce9..0ca9a0d9 100644 --- a/flake.nix +++ b/flake.nix @@ -36,12 +36,13 @@ cargo openssl pkg-config - rust-analyzer - simple-http-server nodejs_18 just binaryen + # For development + rust-analyzer nodePackages.typescript-language-server + zellij ]; RUST_LOG = "info,wasmer_compiler_cranelift=info,solana_rpc_client=debug,solana_client=debug,jsonrpsee_server=info"; RUST_BACKTRACE = 1;