Skip to content

Commit

Permalink
Merge pull request #7 from pixelaw/chore/update_keiko
Browse files Browse the repository at this point in the history
chore: update keiko
  • Loading branch information
mariz-ov authored Dec 1, 2023
2 parents 4737a9e + 34c503b commit 7f0c8ec
Show file tree
Hide file tree
Showing 21 changed files with 291 additions and 79 deletions.
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,18 @@ RUN yarn build --mode production



FROM oostvoort/keiko:v0.0.7 AS runtime
FROM oostvoort/keiko:v0.0.10 AS runtime

ENV PUBLIC_TORII=http://localhost:8080
ENV VITE_PUBLIC_ETH_CONTRACT_ADDRESS=0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7

HEALTHCHECK CMD (curl --fail http://localhost:3000 && curl --fail http://localhost:5050) || exit 1

WORKDIR /keiko

COPY ./startup.sh ./startup.sh
COPY --from=web_node_builder /app/dist static/
COPY ./web/.env.example .env.core.example


COPY ./bots ./bots
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
REPO = pixelaw/core
CORE_VERSION = v0.0.3
KEIKO_VERSION = v0.0.7
CORE_VERSION = v0.0.8
KEIKO_VERSION = v0.0.10


docker_build:
docker build -t $(REPO):$(CORE_VERSION) -t $(REPO):latest --build-arg KEIKO_VERSION=$(KEIKO_VERSION) --progress=plain .

docker_run:
docker run -p 3000:3000 -p 5050:5050 -p 8080:8080 $(REPO):$(CORE_VERSION)

build:
cd contracts;sozo build;
# cp contracts/target/dev/manifest.json web/src/dojo/manifest.json;
Expand Down
4 changes: 2 additions & 2 deletions bots/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ WORLD_HEIGHT=256
QUEUE_BOT_REFRESH_RATE=1000

# Project Configuration
TORII_URI=http://0.0.0.0:8080/graphql
RPC_URL=http://0.0.0.0:5050
PUBLIC_TORII=http://0.0.0.0:8080
PUBLIC_NODE_URL=http://0.0.0.0:5050
API_URL=http://0.0.0.0:3000
4 changes: 2 additions & 2 deletions bots/PixelBoardBot/getState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { DEFAULT_COLOR, GET_ENTITIES } from './constants'
import getEnv from '../utils/getEnv'
import { shortString } from 'starknet'

const TORII_URI = getEnv<string>("TORII_URI", 'http://0.0.0.0:8080/graphql')
const TORII_URI = getEnv<string>("PUBLIC_TORII", 'http://0.0.0.0:8080')

const client = createClient(TORII_URI)
const client = createClient(`${TORII_URI}/graphql`)

type PixelModelType = {
node: {
Expand Down
13 changes: 1 addition & 12 deletions bots/QueueBot/constants.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import { Provider } from 'starknet'
import getEnv from '../utils/getEnv'

export const QUEUE_STARTED_KEY_EVENT = "0x1c4fa7f75d1ea055adccbf8f86b75224181a3036d672762185805e0b999ad65"
export const QUEUE_FINISHED_KEY_EVENT = "0x16c4dd771da9a5cb32846fbb15c1b614da08fb5267af2fcce902a4c416e76cf"
export const PROCESS_QUEUE_SYSTEM_IN_HEX = "0x70726f636573735f71756575655f73797374656d"
export const RPC_URL = getEnv("RPC_URL", "http://0.0.0.0:5050")

export const MASTER_ACCOUNT_ADDRESS="0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973"
export const MASTER_PRIVATE_KEY="0x1800000000300000180000000000030000000000003006001800006600"

export const provider = new Provider({
rpc: {
nodeUrl: RPC_URL
}
})
export const RPC_URL = getEnv("PUBLIC_NODE_URL", "http://0.0.0.0:5050")
4 changes: 3 additions & 1 deletion bots/QueueBot/indexEvents.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// something to add to torii
import { provider, QUEUE_FINISHED_KEY_EVENT, QUEUE_STARTED_KEY_EVENT } from './constants'
import { QUEUE_FINISHED_KEY_EVENT, QUEUE_STARTED_KEY_EVENT } from './constants'
import { eventsToProcess } from './memory'
import { getProvider } from './utils'

let lastBlockIndexed = 0

async function indexEvents () {
const provider = getProvider()
const currentBlock = await provider.getBlock("latest")

if (lastBlockIndexed === currentBlock.block_number) return
Expand Down
12 changes: 4 additions & 8 deletions bots/QueueBot/processUnlockables.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import fetchApi from '../utils/fetchApi'
import { Account, num } from 'starknet'
import execute from '../utils/execute'
import { MASTER_ACCOUNT_ADDRESS, MASTER_PRIVATE_KEY, PROCESS_QUEUE_SYSTEM_IN_HEX, provider } from './constants'
import { eventsToProcess } from './memory'
import { getProvider } from './utils'

let botPrivateKey = ''
let botAddress = ''
Expand Down Expand Up @@ -34,23 +34,19 @@ const processQueue = async (id: string, timestamp: number, called_system: string
console.log(callData)

if (!botAddress || !botPrivateKey) {
// const accounts = await fetchApi<AccountType[]>("accounts", "json")
const master = {
address: MASTER_ACCOUNT_ADDRESS,
private_key: MASTER_PRIVATE_KEY
}
const [master] = await fetchApi<AccountType[]>("accounts", "json")
botAddress = master.address
botPrivateKey = master.private_key
}

const signer = new Account(provider, botAddress, botPrivateKey)
const signer = new Account(getProvider(), botAddress, botPrivateKey)
return execute(signer, CORE_ACTIONS_ADDRESS, CORE_ACTIONS_SELECTOR, callData)
}

// actual queue processing
const processUnlockables = async () => {
if (!Object.values(eventsToProcess).length) return
const currentBlock = await provider.getBlock("latest")
const currentBlock = await getProvider().getBlock("latest")
const blockTimeStamp = currentBlock.timestamp
const unlockables = Object.values(eventsToProcess)
.filter(eventToProcess => blockTimeStamp >= eventToProcess.timestamp)
Expand Down
10 changes: 10 additions & 0 deletions bots/QueueBot/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Provider } from 'starknet'
import { RPC_URL } from './constants'

export const getProvider = () => {
return new Provider({
rpc: {
nodeUrl: RPC_URL
}
})
}
2 changes: 1 addition & 1 deletion bots/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "wait-port 5050 && nodemon index.ts",
"dev": "nodemon index.ts",
"selector": "tsx utils/selector.ts"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions bots/utils/getEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const ACCEPTED_VARIABLES = [
'WORLD_WIDTH',
'WORLD_HEIGHT',
'QUEUE_BOT_REFRESH_RATE',
'TORII_URI',
'RPC_URL',
'PUBLIC_TORII',
'PUBLIC_NODE_URL',
'API_URL'
] as const

Expand Down
19 changes: 19 additions & 0 deletions contracts/scripts/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -euo pipefail
pushd $(dirname "$0")/..

# Autogenerated file. Do not edit manually.

for row in $(cat target/dev/manifest.json | jq -r '.contracts[] | @base64'); do
_jq() {
echo ${row} | base64 --decode | jq -r ${1}
}

name=$(_jq '.name')
address=$(_jq '.address')

# Convert to uppercase and replace '-' with '_'
var_name=$(echo $name | tr '[:lower:]' '[:upper:]' | tr '-' '_')

declare "${var_name}"=$address
done
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
keiko:
image: oostvoort/keiko:v0.0.7
image: oostvoort/keiko:v0.0.10
container_name: keiko
ports:
- "5050:5050"
Expand Down
8 changes: 7 additions & 1 deletion startup.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
#!/bin/bash

function buildWebApp() {
npx import-meta-env -x .env.core.example -p static/index.html
}

# Define the first function (thread)
function thread1() {
cd bots && npm run dev;
}

# Define the second function (thread)
function thread2() {
./server
./keiko
}

buildWebApp &

# Start the first thread in the background
thread1 &

Expand Down
10 changes: 2 additions & 8 deletions web/.env.development
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# If not supplied by keiko
VITE_MASTER_ACCOUNT_ADDRESS=0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973
VITE_MASTER_PRIVATE_KEY=0x1800000000300000180000000000030000000000003006001800006600
VITE_MASTER_PUBLIC_KEY=0x640466ebd2ce505209d3e5c4494b4276ed8f1cde764d757eb48831961f7cdea
VITE_ACCOUNT_CLASS_HASH=0x4d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27f0bb5bc5f

VITE_PUBLIC_ETH_CONTRACT_ADDRESS=0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
VITE_PUBLIC_NODE_URL=http://localhost:5050
VITE_PUBLIC_TORII=http://localhost:8080/graphql
PUBLIC_NODE_URL=http://localhost:5050
PUBLIC_TORII=http://localhost:8080
10 changes: 2 additions & 8 deletions web/.env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# If not supplied by keiko
VITE_MASTER_ACCOUNT_ADDRESS=0x517ececd29116499f4a1b64b094da79ba08dfd54a3edaa316134c41f8160973
VITE_MASTER_PRIVATE_KEY=0x1800000000300000180000000000030000000000003006001800006600
VITE_MASTER_PUBLIC_KEY=0x640466ebd2ce505209d3e5c4494b4276ed8f1cde764d757eb48831961f7cdea
VITE_ACCOUNT_CLASS_HASH=0x4d07e40e93398ed3c76981e72dd1fd22557a78ce36c0515f679e27f0bb5bc5f

VITE_PUBLIC_ETH_CONTRACT_ADDRESS=0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
VITE_PUBLIC_NODE_URL=http://localhost:5050
VITE_PUBLIC_TORII=http://localhost:8080
PUBLIC_NODE_URL=http://localhost:5050
PUBLIC_TORII=http://localhost:8080
3 changes: 3 additions & 0 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
</head>
<body>
<div id="root"></div>
<script>
globalThis.import_meta_env = JSON.parse('"import_meta_env_placeholder"');
</script>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
2 changes: 2 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
"@graphql-codegen/typescript": "^4.0.1",
"@graphql-codegen/typescript-graphql-request": "^6.0.0",
"@graphql-codegen/typescript-operations": "^4.0.1",
"@import-meta-env/cli": "^0.6.8",
"@import-meta-env/unplugin": "^0.5.1",
"@types/node": "^20.8.6",
"@types/react": "^18.2.28",
"@types/react-dom": "^18.2.13",
Expand Down
6 changes: 2 additions & 4 deletions web/src/global/constants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { getProductionUrl } from '@/global/utils'
export const PUBLIC_TORII: string = import.meta.env.PUBLIC_TORII

export const PUBLIC_TORII: string = import.meta.env.VITE_PUBLIC_TORII ?? getProductionUrl('torii')

export const PUBLIC_NODE_URL: string = import.meta.env.VITE_PUBLIC_NODE_URL ?? getProductionUrl('katana')
export const PUBLIC_NODE_URL: string = import.meta.env.PUBLIC_NODE_URL

export const BLOCK_TIME = 1_000

Expand Down
12 changes: 0 additions & 12 deletions web/src/global/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,3 @@ export const argbToHex = (argb: number) => {
const hexCode = convertToHexadecimalAndLeadWithOx(argb)
return hexCode.replace("0xff", "#")
}

export const getProductionUrl = (type: 'katana' | 'torii') => {
const protocol = window.location.protocol
const hostname = window.location.hostname.replace('www.', '')

if (hostname === 'localhost') {
if (type === 'katana') return 'http://localhost:5050'
else return 'http://localhost:8080'
}

return`${protocol}//${type}.${hostname}`
}
8 changes: 7 additions & 1 deletion web/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import path from "path"
import react from "@vitejs/plugin-react"
import { defineConfig } from "vite"
import ImportMetaEnvPlugin from "@import-meta-env/unplugin";

export default defineConfig({
plugins: [react()],
plugins: [
react(),
ImportMetaEnvPlugin.vite({
example: ".env.example",
}),
],
server: {
proxy: {
'/api': {
Expand Down
Loading

0 comments on commit 7f0c8ec

Please sign in to comment.