Skip to content

Commit

Permalink
wip: upgrading to dojo 0.6 and improving account/world mgmt. Very bug…
Browse files Browse the repository at this point in the history
…gy and incomplete, currently crashes on gettingEntities
  • Loading branch information
Caspar Oostendorp committed Feb 27, 2024
1 parent dede949 commit 68edbab
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .account
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
account_address=0xb3ff441a68610b30fd5e2abbf3a1548eb6ba6f3559f2862bf2dc757e5828ca
account_address=0x003c4dd268780ef738920c801edc3a75b6337bc17558c74795b530c0ff502486
account_pubkey=0x640466ebd2ce505209d3e5c4494b4276ed8f1cde764d757eb48831961f7cdea
private_key=0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ keiko_data/
.env
deployed.log
last_deployed_world
web/public/assets/placeholder/pixel-state.png
4 changes: 2 additions & 2 deletions bots/QueueBot/processUnlockables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { getProvider } from './utils'
import { queue } from './queue'
import getCoreAddress from './getCoreAddress'

let botPrivateKey = '0x1c9053c053edf324aec366a34c6901b1095b07af69495bffec7d7fe21effb1b'
let botAddress = '0x6b86e40118f29ebe393a75469b4d926c7a44c2e2681b6d319520b7c1156d114'
let botPrivateKey = '0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a'
let botAddress = '0x003c4dd268780ef738920c801edc3a75b6337bc17558c74795b530c0ff502486'

type AccountType = {
address: string,
Expand Down
3 changes: 2 additions & 1 deletion contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,12 @@ update_scarb = "bash ./scripts/update_scarb.sh"

[tool.dojo.env]
#rpc_url = "http://localhost:5050/"
#world_address = "0x47864d08a1b86cf0dd52ea2785f8bc93b5f48edca8380bbb3057d158521e12d"
world_address = "0x608cc3b3f4cf88e180bd3222dbf4af8afc1f0dbe93b2c30cd58f86ea6ccdbbf"

# World Owner account
account_address = "0x003c4dd268780ef738920c801edc3a75b6337bc17558c74795b530c0ff502486"
#account_pubkey = "0x640466ebd2ce505209d3e5c4494b4276ed8f1cde764d757eb48831961f7cdea"
#private_key = "0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a"

keystore_path = "dev-keystore.json"
keystore_password = "hellopixelaw"
12 changes: 12 additions & 0 deletions contracts/scripts/init_auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ pushd $(dirname "$0")/..
# Now using a copy until that is fixed
cp target/dev/manifest.json target/dev/manifest.copy.json

export TARGET=${1:-"target/dev"}
export STARKNET_RPC="http://localhost:5050/"

GENESIS_TEMPLATE=genesis_template.json
GENESIS_OUT=genesis.json
KATANA_LOG=katana.log
MANIFEST=$TARGET/manifest.json
TORII_DB=torii.sqlite
TORII_LOG=torii.log

declare "WORLD_ADDRESS"=$(cat $MANIFEST | jq -r '.world.address')

source scripts/update_contracts.sh

# Set RPC_URL with default value
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ services:
- "127.0.0.1:3000:3000"
- "127.0.0.1:5050:5050"
- "127.0.0.1:8080:8080"
- "127.0.0.1:9090:9090/tcp"
- "127.0.0.1:9090:9090/udp"
- "127.0.0.1:9091:9091/tcp"
- "127.0.0.1:9091:9091/udp"
restart: unless-stopped
volumes:
- ./contracts/genesis_template.json:/keiko/config/genesis.json
Expand All @@ -18,6 +22,7 @@ services:
environment:
- PUBLIC_NODE_URL=http://localhost:5050
- PUBLIC_TORII=http://localhost:8080
- RUST_LOG=info

networks:
pixelaw:
Expand Down
11 changes: 6 additions & 5 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
"type": "module",
"license": "MIT",
"scripts": {
"dev": "PUBLIC_NODE_URL=http://localhost:5050 PUBLIC_TORII=http://localhost:8080 vite",
"dev": "rm -rf node_modules/.vite && PUBLIC_NODE_URL=http://localhost:5050 PUBLIC_TORII=http://localhost:8080 vite",
"build": "tsc && vite build",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"codegen": "graphql-codegen",
"fix-codegen": "node src/fixGeneratedGraphql.cjs",
"postinstall": "patch-package",
"create-components": "npx @dojoengine/core ../contracts/target/dev/manifest.json src/dojo/contractComponents.ts http://localhost:5050 0x47864d08a1b86cf0dd52ea2785f8bc93b5f48edca8380bbb3057d158521e12d"
},
"dependencies": {
Expand All @@ -29,13 +28,13 @@
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-toast": "^1.1.5",
"@tanstack/react-query": "^5.0.0",
"@types/lodash": "^4.14.200",
"@types/react-color": "^3.0.7",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"dotenv": "^16.4.5",
"events": "^3.3.0",
"graphql": "^16.8.1",
"graphql-request": "^6.1.0",
"graphql-tag": "^2.12.6",
"graphql-ws": "^5.14.2",
"jotai": "^2.4.3",
"lodash": "^4.17.21",
Expand All @@ -52,10 +51,13 @@
"starknet": "^5.19.5",
"tailwind-merge": "^1.14.0",
"tailwindcss-animate": "^1.0.7",
"type-fest": "^2.14.0",
"vite-plugin-top-level-await": "^1.3.1",
"vite-plugin-wasm": "^3.3.0"
},
"devDependencies": {
"@types/lodash": "^4.14.200",
"@types/react-color": "^3.0.7",
"@graphql-codegen/cli": "^5.0.0",
"@graphql-codegen/typescript": "^4.0.1",
"@graphql-codegen/typescript-graphql-request": "^6.0.0",
Expand All @@ -72,7 +74,6 @@
"eslint": "^8.51.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"patch-package": "^8.0.0",
"postcss": "^8.4.31",
"postinstall-postinstall": "^2.1.0",
"tailwindcss": "^3.3.3",
Expand Down
8 changes: 5 additions & 3 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ function App() {
return setup(
createDojoConfig({
manifest: checkManifests.data,
masterAddress: '0x6b86e40118f29ebe393a75469b4d926c7a44c2e2681b6d319520b7c1156d114',
masterPrivateKey: '0x1c9053c053edf324aec366a34c6901b1095b07af69495bffec7d7fe21effb1b'
masterAddress: '0x003c4dd268780ef738920c801edc3a75b6337bc17558c74795b530c0ff502486',
masterPrivateKey: '0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a'
})
)
},
retry: false,
retryDelay: attemptIndex => Math.min(1000 * 2 ** attemptIndex, DO_NOT_EXCEED_MS),
enabled: checkManifests.isSuccess
}
Expand All @@ -82,7 +83,7 @@ function App() {
}

if (setupQuery.isLoading) {
return <Loading />
return <Loading >Loading setupQuery</Loading>
}

if (setupQuery.data) {
Expand All @@ -99,6 +100,7 @@ function App() {
let errorMessage = ''

console.log({ setupQuery, checkManifests })
if(setupQuery.error) console.error(setupQuery.error)

if (checkRpcUrl.isError) {
errorMessage = `PUBLIC_NODE_URL error: ${checkRpcUrl.error.message}. If this is happening in your local environment, Katana might not be up.`
Expand Down
12 changes: 1 addition & 11 deletions web/src/dojo/createSystemCalls.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Account, Event, num, TransactionStatus } from 'starknet'
import { getEvents, hexToAscii, setComponentsFromEvents } from '@dojoengine/utils'
import { Account, num, TransactionStatus } from 'starknet'
import { ZERO_ADDRESS } from '@/global/constants'
import { IWorld } from '@/dojo/generated'
import { ContractComponents } from '@/dojo/contractComponents'
Expand Down Expand Up @@ -61,15 +60,6 @@ export function createSystemCalls(
else throw new Error('transaction rejected')
}

// these events could contain custom components not just core components so filtering out non-core components
const events: Event[] = getEvents(receipt)
const filteredEvents = events.filter(event => {
const componentName = hexToAscii(event.data?.[0] ?? '0x0')
const component = contractComponents[componentName as keyof typeof contractComponents]
return !!component
})

setComponentsFromEvents(contractComponents, filteredEvents)

} catch (e) {
console.error(e)
Expand Down
10 changes: 10 additions & 0 deletions web/src/dojo/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,35 @@ import { PUBLIC_TORII } from '@/global/constants'
export type SetupResult = Awaited<ReturnType<typeof setup>>;

export async function setup({ ...config }: DojoConfig) {
console.log("setup: createClient")
// torii client
const toriiClient = await torii.createClient([], {
rpcUrl: config.rpcUrl,
toriiUrl: config.toriiUrl,
worldAddress: config.manifest.world.address || "",
});

console.log("setup: defineContractComponents")

// create contract components
const contractComponents = defineContractComponents(world);

console.log("setup: createClientComponents")

// create client components
const clientComponents = createClientComponents({ contractComponents });

console.log("getting entities")
// fetch all existing entities from torii
await getSyncEntities(toriiClient, contractComponents as any);

console.log("getting entities: new DojoProvider")

// create dojo provider
const dojoProvider = new DojoProvider(config.manifest, config.rpcUrl);

console.log("getting entities: setupWorld")

// setup world
const client = await setupWorld(dojoProvider);

Expand Down
4 changes: 4 additions & 0 deletions web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import wasm from 'vite-plugin-wasm'
import topLevelAwait from "vite-plugin-top-level-await";

export default defineConfig({
build: {
sourcemap: true
},
plugins: [
react(),
wasm(),
Expand Down Expand Up @@ -35,4 +38,5 @@ export default defineConfig({
"@": path.resolve(__dirname, "./src"),
},
},

})
Loading

0 comments on commit 68edbab

Please sign in to comment.