From 926ef6ad4ff6ea1b694d679480439c3a09bd3f40 Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Sat, 4 Jan 2025 21:52:05 +0000 Subject: [PATCH 01/25] feat: docker --- Dockerfile | 60 +++++++++++++++++++++++++++++++++++++++++++++ docker-compose.yml | 25 +++++++++++++++++++ ecosystem.config.js | 8 +++--- 3 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..17cc04f2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,60 @@ +# Use the official Bun image +FROM --platform=linux/amd64 oven/bun:1.0.21 + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + curl \ + build-essential \ + python3 \ + make \ + tar + +# Install Rust and Nargo dependencies - Updated for ARM compatibility +RUN apt-get update && apt-get install -y curl build-essential && \ + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \ + . "$HOME/.cargo/env" && \ + # Install Nargo v0.38.0 with architecture detection + ARCH=$(uname -m) && \ + if [ "$ARCH" = "aarch64" ]; then \ + GITHUB_URL="https://github.com/noir-lang/noir/releases/download/v0.38.0/nargo-aarch64-apple-darwin.tar.gz"; \ + else \ + GITHUB_URL="https://github.com/noir-lang/noir/releases/download/v0.38.0/nargo-x86_64-unknown-linux-gnu.tar.gz"; \ + fi && \ + curl -L "${GITHUB_URL}" -o nargo.tar.gz && \ + tar -xzf nargo.tar.gz && \ + mv nargo /usr/local/bin/ && \ + chmod +x /usr/local/bin/nargo && \ + rm nargo.tar.gz + +# Add Rust to PATH +ENV PATH="/root/.cargo/bin:${PATH}" + +# Set working directory +WORKDIR /app + +# Copy package files +COPY package.json . +COPY bun.lockb . +COPY tsconfig.json . +COPY tsconfig.base.json . + +# Copy workspace packages +COPY packages ./packages +COPY apps ./apps + +# Clear Bun's cache and install dependencies +RUN mkdir -p ~/.bun/install/cache && \ + chmod -R 777 ~/.bun && \ + bun install --no-cache + +# Set environment variables +ENV NODE_ENV=production +ENV PORT=3001 +ENV HOST=0.0.0.0 +ENV PATH="/usr/local/bin:${PATH}" + +# Expose the port +EXPOSE 3001 + +# The actual command will be specified in docker-compose.yml +CMD ["bun", "run", "api:start"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..629ec993 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +# docker-compose.yml +services: + api: + build: . + command: ["bun", "run", "api:start"] + ports: + - "3001:3001" + env_file: + - .env + networks: + - app_network + volumes: + - ./packages/api:/app/packages/api + - /app/packages/api/node_modules + restart: unless-stopped + + updates: + build: . + command: ["bun", "run", "updates"] + env_file: + - .env + +networks: + app_network: + driver: bridge diff --git a/ecosystem.config.js b/ecosystem.config.js index 1c302720..40a9a64f 100644 --- a/ecosystem.config.js +++ b/ecosystem.config.js @@ -9,9 +9,9 @@ module.exports = { apps: [ { name: "rumourcast-api", - script: "/root/.bun/bin/bun", + script: "bun", args: "run packages/api/src/index.ts", - cwd: "/root/rumourcast", + cwd: "/app", watch: false, env: { NODE_ENV: "production", @@ -21,9 +21,9 @@ module.exports = { }, { name: "rumourcast-updates", - script: "/root/.bun/bin/bun", + script: "bun", args: "run packages/api/scripts/updates.ts", - cwd: "/root/rumourcast", + cwd: "/app", watch: false, env: { NODE_ENV: "production", From 926390678b841a7be242b0963d4a5cd5a3474add Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 11:21:24 +0000 Subject: [PATCH 02/25] fix: update run start --- Dockerfile | 2 +- package.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 17cc04f2..d9e72963 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,4 +57,4 @@ ENV PATH="/usr/local/bin:${PATH}" EXPOSE 3001 # The actual command will be specified in docker-compose.yml -CMD ["bun", "run", "api:start"] +CMD ["bun", "run", "start"] diff --git a/package.json b/package.json index b54ff9d9..847e7be1 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "farcaster": "bun run --filter farcaster dev", "api:dev": "bun run --filter @anonworld/api dev", "api:start": "bun run --filter @anonworld/api start", + "start": "bun run api:start", "zk:build": "bun run --filter @anonworld/zk build-circuits", "zk:test": "bun run --filter @anonworld/zk test-proofs", "db:push": "bun run --filter @anonworld/db push", From 053cafd1a10730f23c421852ddf253ba14ce014b Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 11:28:35 +0000 Subject: [PATCH 03/25] fix: update run start --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 629ec993..99d1db2d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ services: api: build: . - command: ["bun", "run", "api:start"] + command: ["bun", "run", "start"] ports: - "3001:3001" env_file: From 72e5de33c4fd73f158ae7719d792b0e8a2dc1f56 Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 11:41:47 +0000 Subject: [PATCH 04/25] fix: update run start --- Dockerfile | 2 +- package.json | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d9e72963..17cc04f2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -57,4 +57,4 @@ ENV PATH="/usr/local/bin:${PATH}" EXPOSE 3001 # The actual command will be specified in docker-compose.yml -CMD ["bun", "run", "start"] +CMD ["bun", "run", "api:start"] diff --git a/package.json b/package.json index 847e7be1..b54ff9d9 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,6 @@ "farcaster": "bun run --filter farcaster dev", "api:dev": "bun run --filter @anonworld/api dev", "api:start": "bun run --filter @anonworld/api start", - "start": "bun run api:start", "zk:build": "bun run --filter @anonworld/zk build-circuits", "zk:test": "bun run --filter @anonworld/zk test-proofs", "db:push": "bun run --filter @anonworld/db push", From 2425f522e3830d470efd639d1354b991c268c968 Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 11:49:14 +0000 Subject: [PATCH 05/25] fix: update dockerfile --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 17cc04f2..8a19d524 100644 --- a/Dockerfile +++ b/Dockerfile @@ -56,5 +56,5 @@ ENV PATH="/usr/local/bin:${PATH}" # Expose the port EXPOSE 3001 -# The actual command will be specified in docker-compose.yml -CMD ["bun", "run", "api:start"] +WORKDIR /app/packages/api # Change working directory to the API app +CMD ["bun", "run", "start"] # Run the start script directly From 5a1742ce1c2b9678fd9c68140373e51096e4f8e2 Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 12:05:52 +0000 Subject: [PATCH 06/25] fix: update dockerfile --- .dockerignore | 7 +++++++ Dockerfile | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..b7776142 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,7 @@ +**/node_modules +**/.next +**/.turbo +**/dist +**/.git +**/.env* +**/coverage diff --git a/Dockerfile b/Dockerfile index 8a19d524..aafe15d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -56,5 +56,5 @@ ENV PATH="/usr/local/bin:${PATH}" # Expose the port EXPOSE 3001 -WORKDIR /app/packages/api # Change working directory to the API app -CMD ["bun", "run", "start"] # Run the start script directly +WORKDIR /app/apps/api # Change working directory to the API app +CMD bun run start # Run the start script directly From 55248e057c4b741578c52ccf572e93cb68996dda Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 12:36:02 +0000 Subject: [PATCH 07/25] fix: update dockerfile --- Dockerfile | 5 ++--- docker-compose.yml | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index aafe15d9..7178bb13 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # Use the official Bun image -FROM --platform=linux/amd64 oven/bun:1.0.21 +FROM --platform=linux/amd64 oven/bun:1.1.38 # Install system dependencies RUN apt-get update && apt-get install -y \ @@ -56,5 +56,4 @@ ENV PATH="/usr/local/bin:${PATH}" # Expose the port EXPOSE 3001 -WORKDIR /app/apps/api # Change working directory to the API app -CMD bun run start # Run the start script directly +CMD ["bun", "run", "api:start"] diff --git a/docker-compose.yml b/docker-compose.yml index 99d1db2d..629ec993 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ services: api: build: . - command: ["bun", "run", "start"] + command: ["bun", "run", "api:start"] ports: - "3001:3001" env_file: From 5d372f364895d7ef6128e940654e61699cffad0b Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 12:59:51 +0000 Subject: [PATCH 08/25] fix: add hostname --- packages/api/src/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index bfc90b0b..356db3aa 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -14,6 +14,9 @@ const app = createElysia() .use(uploadRoutes) .use(farcasterRoutes) -app.listen(3001) +app.listen({ + port: process.env.PORT || 3001, + hostname: '0.0.0.0', +}) console.log(`🦊 Elysia is running at ${app.server?.hostname}:${app.server?.port}`) From c9e69401fa1240cbff56c0a86dc5c71eb2f27617 Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 15:20:34 +0000 Subject: [PATCH 09/25] fix: cors --- packages/api/src/utils.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/api/src/utils.ts b/packages/api/src/utils.ts index 7800259d..8239765e 100644 --- a/packages/api/src/utils.ts +++ b/packages/api/src/utils.ts @@ -11,7 +11,18 @@ import { getBulkPosts } from '@anonworld/db' export const createElysia = (config?: ConstructorParameters[0]) => new Elysia(config) - .use(cors()) + .use( + cors({ + origin: [ + 'https://rumourcast.xyz', + 'http://localhost:3000', // For local development + /\.rumourcast\.xyz$/, // Allow all subdomains + ], + methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], + credentials: true, // If you need to send cookies/auth headers + allowedHeaders: ['Content-Type', 'Authorization'], + }) + ) .use(Logestic.preset('common')) .onError(({ server, error, path }) => { console.error(path, error) From a38153bb86cd6e18c9afae3c0ef7c19bbdb773a9 Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 15:52:01 +0000 Subject: [PATCH 10/25] fix: cors and add build zk --- Dockerfile | 2 +- packages/api/src/index.ts | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7178bb13..d9f381c3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -56,4 +56,4 @@ ENV PATH="/usr/local/bin:${PATH}" # Expose the port EXPOSE 3001 -CMD ["bun", "run", "api:start"] +CMD bun run zk:build && bun run api:start diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index 356db3aa..998b064a 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -1,3 +1,4 @@ +import { Elysia, cors } from 'elysia' import { createElysia } from './utils' import { actionsRoutes } from './routes/actions' import { merkleTreeRoutes } from './routes/merkle-tree' @@ -6,7 +7,29 @@ import { feedsRoutes } from './routes/feeds' import { uploadRoutes } from './routes/upload' import { farcasterRoutes } from './routes/farcaster' -const app = createElysia() +const app = new Elysia() + .use( + cors({ + origin: [ + 'https://rumourcast.xyz', + 'http://localhost:3000', + 'https://www.rumourcast.xyz', + 'http://rumourcast.xyz', + 'https://rumourcast.xyz', + /\.rumourcast\.xyz$/, // This will match all subdomains + ], + methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH'], + credentials: true, + allowHeaders: [ + 'Content-Type', + 'Authorization', + 'Access-Control-Allow-Origin', + 'Access-Control-Allow-Credentials', + ], + exposedHeaders: ['*'], + preflight: true, + }) + ) .use(actionsRoutes) .use(merkleTreeRoutes) .use(postsRoutes) From 0d98f7371b79ab09cc8e40bcd1aa487f7ec565ee Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 15:56:34 +0000 Subject: [PATCH 11/25] fix: cors and add build zk --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index d9f381c3..8517243c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,8 @@ RUN apt-get update && apt-get install -y \ build-essential \ python3 \ make \ - tar + tar \ + git # Install Rust and Nargo dependencies - Updated for ARM compatibility RUN apt-get update && apt-get install -y curl build-essential && \ From 07b4483b2b483f33adb56078ae4c6dc422ce0e3e Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 16:01:21 +0000 Subject: [PATCH 12/25] fix: update noir version --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 8517243c..165cf21e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,12 +14,12 @@ RUN apt-get update && apt-get install -y \ RUN apt-get update && apt-get install -y curl build-essential && \ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \ . "$HOME/.cargo/env" && \ - # Install Nargo v0.38.0 with architecture detection + # Install Nargo v0.39.0 with architecture detection ARCH=$(uname -m) && \ if [ "$ARCH" = "aarch64" ]; then \ - GITHUB_URL="https://github.com/noir-lang/noir/releases/download/v0.38.0/nargo-aarch64-apple-darwin.tar.gz"; \ + GITHUB_URL="https://github.com/noir-lang/noir/releases/download/v0.39.0/nargo-aarch64-apple-darwin.tar.gz"; \ else \ - GITHUB_URL="https://github.com/noir-lang/noir/releases/download/v0.38.0/nargo-x86_64-unknown-linux-gnu.tar.gz"; \ + GITHUB_URL="https://github.com/noir-lang/noir/releases/download/v0.39.0/nargo-x86_64-unknown-linux-gnu.tar.gz"; \ fi && \ curl -L "${GITHUB_URL}" -o nargo.tar.gz && \ tar -xzf nargo.tar.gz && \ From 63e609569f6a7ae1f841537f5b572462d00c4cb5 Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 16:06:48 +0000 Subject: [PATCH 13/25] fix: cors --- packages/api/src/utils.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/api/src/utils.ts b/packages/api/src/utils.ts index 8239765e..94790f01 100644 --- a/packages/api/src/utils.ts +++ b/packages/api/src/utils.ts @@ -15,12 +15,15 @@ export const createElysia = (config?: ConstructorParameters[0]) = cors({ origin: [ 'https://rumourcast.xyz', + 'https://api-new.rumourcast.xyz', 'http://localhost:3000', // For local development /\.rumourcast\.xyz$/, // Allow all subdomains ], methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], credentials: true, // If you need to send cookies/auth headers allowedHeaders: ['Content-Type', 'Authorization'], + exposeHeaders: ['Access-Control-Allow-Origin'], + preflight: true, }) ) .use(Logestic.preset('common')) From a46993db9297a3068ccab87abbc4aa6de519b659 Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 16:08:13 +0000 Subject: [PATCH 14/25] fix: cors --- packages/api/src/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/api/src/utils.ts b/packages/api/src/utils.ts index 94790f01..3e528754 100644 --- a/packages/api/src/utils.ts +++ b/packages/api/src/utils.ts @@ -1,4 +1,4 @@ -import cors from '@elysiajs/cors' +import { cors } from '@elysiajs/cors' import { Elysia } from 'elysia' import { Logestic } from 'logestic' import { Cast } from './services/neynar/types' From 431a49f164ce409f4b6200b398bbd04e1bd4e7c0 Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 16:12:52 +0000 Subject: [PATCH 15/25] fix: cors --- packages/api/src/utils.ts | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/packages/api/src/utils.ts b/packages/api/src/utils.ts index 3e528754..4aa248ff 100644 --- a/packages/api/src/utils.ts +++ b/packages/api/src/utils.ts @@ -13,16 +13,29 @@ export const createElysia = (config?: ConstructorParameters[0]) = new Elysia(config) .use( cors({ - origin: [ - 'https://rumourcast.xyz', - 'https://api-new.rumourcast.xyz', - 'http://localhost:3000', // For local development - /\.rumourcast\.xyz$/, // Allow all subdomains + origin: (request: Request): boolean => { + const origin = request.headers.get('origin') + return ( + origin === 'https://rumourcast.xyz' || + origin === 'https://api-new.rumourcast.xyz' || + origin === 'http://localhost:3000' || + (origin?.endsWith('.rumourcast.xyz') ?? false) + ) + }, + methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH', 'HEAD'], + credentials: true, + allowedHeaders: [ + 'Content-Type', + 'Authorization', + 'Accept', + 'Origin', + 'X-Requested-With', ], - methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], - credentials: true, // If you need to send cookies/auth headers - allowedHeaders: ['Content-Type', 'Authorization'], - exposeHeaders: ['Access-Control-Allow-Origin'], + exposeHeaders: [ + 'Access-Control-Allow-Origin', + 'Access-Control-Allow-Credentials', + ], + maxAge: 86400, // 24 hours preflight: true, }) ) From a2ec8c426aabcddf6b9c008232ef6ea0c89c4a33 Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 16:22:33 +0000 Subject: [PATCH 16/25] fix: cors --- packages/api/src/index.ts | 29 ++++++++++++++++------------- packages/api/src/utils.ts | 31 ++----------------------------- 2 files changed, 18 insertions(+), 42 deletions(-) diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index 998b064a..424d003e 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -10,23 +10,26 @@ import { farcasterRoutes } from './routes/farcaster' const app = new Elysia() .use( cors({ - origin: [ - 'https://rumourcast.xyz', - 'http://localhost:3000', - 'https://www.rumourcast.xyz', - 'http://rumourcast.xyz', - 'https://rumourcast.xyz', - /\.rumourcast\.xyz$/, // This will match all subdomains - ], - methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH'], + origin: (request: Request): boolean => { + const origin = request.headers.get('origin') + return ( + origin === 'https://rumourcast.xyz' || + origin === 'https://api-new.rumourcast.xyz' || + origin === 'http://localhost:3000' || + (origin?.endsWith('.rumourcast.xyz') ?? false) + ) + }, + methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH', 'HEAD'], credentials: true, - allowHeaders: [ + allowedHeaders: [ 'Content-Type', 'Authorization', - 'Access-Control-Allow-Origin', - 'Access-Control-Allow-Credentials', + 'Accept', + 'Origin', + 'X-Requested-With', ], - exposedHeaders: ['*'], + exposeHeaders: ['Access-Control-Allow-Origin', 'Access-Control-Allow-Credentials'], + maxAge: 86400, // 24 hours preflight: true, }) ) diff --git a/packages/api/src/utils.ts b/packages/api/src/utils.ts index 4aa248ff..7800259d 100644 --- a/packages/api/src/utils.ts +++ b/packages/api/src/utils.ts @@ -1,4 +1,4 @@ -import { cors } from '@elysiajs/cors' +import cors from '@elysiajs/cors' import { Elysia } from 'elysia' import { Logestic } from 'logestic' import { Cast } from './services/neynar/types' @@ -11,34 +11,7 @@ import { getBulkPosts } from '@anonworld/db' export const createElysia = (config?: ConstructorParameters[0]) => new Elysia(config) - .use( - cors({ - origin: (request: Request): boolean => { - const origin = request.headers.get('origin') - return ( - origin === 'https://rumourcast.xyz' || - origin === 'https://api-new.rumourcast.xyz' || - origin === 'http://localhost:3000' || - (origin?.endsWith('.rumourcast.xyz') ?? false) - ) - }, - methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH', 'HEAD'], - credentials: true, - allowedHeaders: [ - 'Content-Type', - 'Authorization', - 'Accept', - 'Origin', - 'X-Requested-With', - ], - exposeHeaders: [ - 'Access-Control-Allow-Origin', - 'Access-Control-Allow-Credentials', - ], - maxAge: 86400, // 24 hours - preflight: true, - }) - ) + .use(cors()) .use(Logestic.preset('common')) .onError(({ server, error, path }) => { console.error(path, error) From e9364bda9835ab3073efdcb92e732d866bdd8fcc Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 16:27:27 +0000 Subject: [PATCH 17/25] fix: cors --- packages/api/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index 424d003e..19ff117c 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -1,5 +1,5 @@ -import { Elysia, cors } from 'elysia' -import { createElysia } from './utils' +import { Elysia } from 'elysia' +import cors from '@elysiajs/cors' import { actionsRoutes } from './routes/actions' import { merkleTreeRoutes } from './routes/merkle-tree' import { postsRoutes } from './routes/posts' From 40e3e1a40fa70e9803efee42ad229af36e275870 Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 16:32:56 +0000 Subject: [PATCH 18/25] fix: cors --- packages/api/src/utils.ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/packages/api/src/utils.ts b/packages/api/src/utils.ts index 7800259d..cc427db7 100644 --- a/packages/api/src/utils.ts +++ b/packages/api/src/utils.ts @@ -11,7 +11,34 @@ import { getBulkPosts } from '@anonworld/db' export const createElysia = (config?: ConstructorParameters[0]) => new Elysia(config) - .use(cors()) + .use( + cors({ + origin: (request: Request): boolean => { + const origin = request.headers.get('origin') + return ( + origin === 'https://rumourcast.xyz' || + origin === 'https://api-new.rumourcast.xyz' || + origin === 'http://localhost:3000' || + (origin?.endsWith('.rumourcast.xyz') ?? false) + ) + }, + methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH', 'HEAD'], + credentials: true, + allowedHeaders: [ + 'Content-Type', + 'Authorization', + 'Accept', + 'Origin', + 'X-Requested-With', + ], + exposeHeaders: [ + 'Access-Control-Allow-Origin', + 'Access-Control-Allow-Credentials', + ], + maxAge: 86400, // 24 hours + preflight: true, + }) + ) .use(Logestic.preset('common')) .onError(({ server, error, path }) => { console.error(path, error) From 6d5e96037595cfcaadcb4f13c885bd85d2c38b13 Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 16:38:03 +0000 Subject: [PATCH 19/25] fix: cors --- packages/api/src/utils.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/api/src/utils.ts b/packages/api/src/utils.ts index cc427db7..797bc15c 100644 --- a/packages/api/src/utils.ts +++ b/packages/api/src/utils.ts @@ -17,6 +17,7 @@ export const createElysia = (config?: ConstructorParameters[0]) = const origin = request.headers.get('origin') return ( origin === 'https://rumourcast.xyz' || + origin === 'https://www.rumourcast.xyz' || // Added www subdomain origin === 'https://api-new.rumourcast.xyz' || origin === 'http://localhost:3000' || (origin?.endsWith('.rumourcast.xyz') ?? false) @@ -34,6 +35,8 @@ export const createElysia = (config?: ConstructorParameters[0]) = exposeHeaders: [ 'Access-Control-Allow-Origin', 'Access-Control-Allow-Credentials', + 'Access-Control-Allow-Methods', // Added this + 'Access-Control-Allow-Headers', // Added this ], maxAge: 86400, // 24 hours preflight: true, From 6bd2a0f852b032d1f26822066e802c79500cdf5a Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 16:44:35 +0000 Subject: [PATCH 20/25] fix: cors --- packages/api/src/utils.ts | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/packages/api/src/utils.ts b/packages/api/src/utils.ts index 797bc15c..7800259d 100644 --- a/packages/api/src/utils.ts +++ b/packages/api/src/utils.ts @@ -11,37 +11,7 @@ import { getBulkPosts } from '@anonworld/db' export const createElysia = (config?: ConstructorParameters[0]) => new Elysia(config) - .use( - cors({ - origin: (request: Request): boolean => { - const origin = request.headers.get('origin') - return ( - origin === 'https://rumourcast.xyz' || - origin === 'https://www.rumourcast.xyz' || // Added www subdomain - origin === 'https://api-new.rumourcast.xyz' || - origin === 'http://localhost:3000' || - (origin?.endsWith('.rumourcast.xyz') ?? false) - ) - }, - methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH', 'HEAD'], - credentials: true, - allowedHeaders: [ - 'Content-Type', - 'Authorization', - 'Accept', - 'Origin', - 'X-Requested-With', - ], - exposeHeaders: [ - 'Access-Control-Allow-Origin', - 'Access-Control-Allow-Credentials', - 'Access-Control-Allow-Methods', // Added this - 'Access-Control-Allow-Headers', // Added this - ], - maxAge: 86400, // 24 hours - preflight: true, - }) - ) + .use(cors()) .use(Logestic.preset('common')) .onError(({ server, error, path }) => { console.error(path, error) From bfb69a190e769d83f2e31fefacae61b3ece57cbf Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 16:57:35 +0000 Subject: [PATCH 21/25] fix: cors --- packages/api/src/index.ts | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/packages/api/src/index.ts b/packages/api/src/index.ts index 19ff117c..dbda2c77 100644 --- a/packages/api/src/index.ts +++ b/packages/api/src/index.ts @@ -8,31 +8,7 @@ import { uploadRoutes } from './routes/upload' import { farcasterRoutes } from './routes/farcaster' const app = new Elysia() - .use( - cors({ - origin: (request: Request): boolean => { - const origin = request.headers.get('origin') - return ( - origin === 'https://rumourcast.xyz' || - origin === 'https://api-new.rumourcast.xyz' || - origin === 'http://localhost:3000' || - (origin?.endsWith('.rumourcast.xyz') ?? false) - ) - }, - methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH', 'HEAD'], - credentials: true, - allowedHeaders: [ - 'Content-Type', - 'Authorization', - 'Accept', - 'Origin', - 'X-Requested-With', - ], - exposeHeaders: ['Access-Control-Allow-Origin', 'Access-Control-Allow-Credentials'], - maxAge: 86400, // 24 hours - preflight: true, - }) - ) + .use(cors()) .use(actionsRoutes) .use(merkleTreeRoutes) .use(postsRoutes) From 50e762c9595b6d440187fbb0c58f943f0059e414 Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 17:14:02 +0000 Subject: [PATCH 22/25] fix: cors --- packages/api/src/utils.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/packages/api/src/utils.ts b/packages/api/src/utils.ts index 7800259d..4058b209 100644 --- a/packages/api/src/utils.ts +++ b/packages/api/src/utils.ts @@ -10,16 +10,13 @@ import { import { getBulkPosts } from '@anonworld/db' export const createElysia = (config?: ConstructorParameters[0]) => - new Elysia(config) - .use(cors()) - .use(Logestic.preset('common')) - .onError(({ server, error, path }) => { - console.error(path, error) - if (error.message.includes('Out of memory')) { - server?.stop() - process.exit(1) - } - }) + new Elysia(config).use(Logestic.preset('common')).onError(({ server, error, path }) => { + console.error(path, error) + if (error.message.includes('Out of memory')) { + server?.stop() + process.exit(1) + } + }) export const augmentCasts = async (casts: Cast[]) => { const hashes = casts.map((cast) => cast.hash) From 5a11de2221ece4330dd74560390857c6a2b69823 Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 17:22:03 +0000 Subject: [PATCH 23/25] fix: moved getaction --- packages/api/src/routes/actions.ts | 3 ++- packages/api/src/utils.ts | 17 ++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/packages/api/src/routes/actions.ts b/packages/api/src/routes/actions.ts index 2de8496c..95154f81 100644 --- a/packages/api/src/routes/actions.ts +++ b/packages/api/src/routes/actions.ts @@ -12,9 +12,10 @@ export const actionsRoutes = createElysia({ prefix: '/actions' }).post( proof: new Uint8Array(proof.proof), publicInputs: proof.publicInputs, })) - const action = await getAction(body.actionId, proofs, body.data) try { + const action = await getAction(body.actionId, proofs, body.data) + const response = await action.execute() await logActionExecution({ diff --git a/packages/api/src/utils.ts b/packages/api/src/utils.ts index 4058b209..7800259d 100644 --- a/packages/api/src/utils.ts +++ b/packages/api/src/utils.ts @@ -10,13 +10,16 @@ import { import { getBulkPosts } from '@anonworld/db' export const createElysia = (config?: ConstructorParameters[0]) => - new Elysia(config).use(Logestic.preset('common')).onError(({ server, error, path }) => { - console.error(path, error) - if (error.message.includes('Out of memory')) { - server?.stop() - process.exit(1) - } - }) + new Elysia(config) + .use(cors()) + .use(Logestic.preset('common')) + .onError(({ server, error, path }) => { + console.error(path, error) + if (error.message.includes('Out of memory')) { + server?.stop() + process.exit(1) + } + }) export const augmentCasts = async (casts: Cast[]) => { const hashes = casts.map((cast) => cast.hash) From 12bbb627c8f8ca2008c556ef082870957c6e8e16 Mon Sep 17 00:00:00 2001 From: Christian Ray Leovido <18484997+leovido@users.noreply.github.com> Date: Wed, 22 Jan 2025 17:37:46 +0000 Subject: [PATCH 24/25] fix: add invalid proof --- packages/api/src/actions/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/api/src/actions/index.ts b/packages/api/src/actions/index.ts index 88ba3cd4..ed402e05 100644 --- a/packages/api/src/actions/index.ts +++ b/packages/api/src/actions/index.ts @@ -17,9 +17,9 @@ export const getAction = async (actionId: string, proofs: ProofData[], data: any const roots = [] for (const proof of proofs) { const verified = await merkleMembership.verify(proof) - // if (!verified) { - // throw new Error('Invalid proof') - // } + if (!verified) { + throw new Error('Invalid proof') + } roots.push(proof.publicInputs[0]) } From 61e1a3d66fdafccb8a08a21543335a0c8a891db8 Mon Sep 17 00:00:00 2001 From: Samuel Huber Date: Tue, 4 Feb 2025 18:05:01 +0100 Subject: [PATCH 25/25] fix: always using cache and never updating the holders as result --- packages/api/src/actions/create-post.ts | 3 +++ packages/api/src/services/redis.ts | 4 ++-- packages/api/src/services/simplehash.ts | 13 ++++++++++++- packages/react/src/hooks/use-credentials.ts | 13 ++++++++++++- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/api/src/actions/create-post.ts b/packages/api/src/actions/create-post.ts index 70bb754e..56dc8da2 100644 --- a/packages/api/src/actions/create-post.ts +++ b/packages/api/src/actions/create-post.ts @@ -26,6 +26,7 @@ export class CreatePostAction { async execute() { const { text, embeds, quote, channel, parent, revealHash } = this.data + console.log('api/src/actions/create-post execute:', this.data) const response = await neynar.createCast({ fid: this.metadata.fid, @@ -36,6 +37,7 @@ export class CreatePostAction { parent, }) + console.log('api/src/actions/create-post execute: neynarResponse', response) if (!response.success) { throw new Error('Failed to create cast') } @@ -47,6 +49,7 @@ export class CreatePostAction { reveal_hash: this.data.revealHash, }) + console.log('api/src/actions/create-post execute: trying createPostCredentials', this.data.roots) await createPostCredentials(response.cast.hash, this.data.roots) return { diff --git a/packages/api/src/services/redis.ts b/packages/api/src/services/redis.ts index 06729983..6208287b 100644 --- a/packages/api/src/services/redis.ts +++ b/packages/api/src/services/redis.ts @@ -40,7 +40,7 @@ export class RedisService { } async setMerkleTree(key: string, tree: string) { - await this.client.set(key, tree) + await this.client.setex(key, 600, tree) } async getMerkleTreeForCredential(credentialId: string) { @@ -49,7 +49,7 @@ export class RedisService { async setMerkleTreeForCredential(credentialId: string, tree: string) { const key = `merkle-tree:credential:${credentialId}` - await this.client.set(key, tree) + await this.client.setex(key, 600, tree) } async actionOccurred(actionId: string, hash: string) { diff --git a/packages/api/src/services/simplehash.ts b/packages/api/src/services/simplehash.ts index 12201948..a08c2d35 100644 --- a/packages/api/src/services/simplehash.ts +++ b/packages/api/src/services/simplehash.ts @@ -83,15 +83,26 @@ class SimplehashService { minBalance, }: { chainId: number; tokenAddress: string; minBalance: bigint }) { const owners: `0x${string}`[] = [] + console.log(`[SimplehashService] Fetching token owners for:`, { + chainId, + tokenAddress, + minBalance: minBalance.toString() + }) let cursor = '' + let totalFetched = 0 while (true) { const data = await this.getTopWalletsForFungible(chainId, tokenAddress, cursor) + totalFetched += data.owners.length + + console.log(`[SimplehashService] Fetched ${data.owners.length} owners (total: ${totalFetched})`) for (const owner of data.owners) { - if (BigInt(owner.quantity_string) >= minBalance) { + const balance = BigInt(owner.quantity_string) + if (balance >= minBalance) { owners.push(owner.owner_address.toLowerCase() as `0x${string}`) } else { + console.log(`[SimplehashService] Stopping at ${owners.length} qualifying holders (min balance: ${minBalance.toString()})`) return owners } } diff --git a/packages/react/src/hooks/use-credentials.ts b/packages/react/src/hooks/use-credentials.ts index 4aca22bc..6e90dfa3 100644 --- a/packages/react/src/hooks/use-credentials.ts +++ b/packages/react/src/hooks/use-credentials.ts @@ -40,7 +40,18 @@ export function useCredentials(sdk: AnonWorldSDK) { if (!address) return try { - const signature = await signMessageAsync({ message: credentialId }) + console.log('Requesting signature for credential:', credentialId) + const signature = await signMessageAsync({ + message: credentialId + }).catch(error => { + console.error('Signature request failed:', error) + throw new Error('Failed to get wallet signature') + }) + if (!signature) { + throw new Error('No signature received') + } + + console.log('Got signature, verifying credential...') const proof = await sdk.verifyCredential(credentialId, { address, signature,