Skip to content

Commit

Permalink
[DRAFT] Retro PGF API (#323)
Browse files Browse the repository at this point in the history
* make basic auth backend for siwe

* remove graphprotocol package

* yarn

* use jose instead of jsonwebtoken

* wip siwe frontend

* fix es-lint

* try use node util with compatibility flag

* just not import TextEncoder

* add contenet type headers

* update client to call auth server

* update dev DO instance

* add test endpoint

* test cookie

* handle error on nonce

* wrap auth endpoints in try-catch

* add missing response statements

* await on jwt sign

* fix jwt algo

* fix sign out endpoint

* fix proxy

* try resolve bigint ** to Math.pow() errir

* refactor auth api

* set JWT_SECRET as env variable

* update api endpoints on FE

* add error response on absent cookie

* await on response

* fix path split

* do not unwrap payload for get requests

* fix path

* fix proxy

* setup test ennvironment

* add postgres

* add ballot service & get ballot

* save ballot

* set update_at field on ballot save

* add likesService and like

* get likes

* get all likes

* add nullable to serde

* fix bytes type on typechain

* index attestations

* fix followChain init in workers

* remove console.log

* remove console.logs

* add topics filter for local fetch

* add comment on topics filter

* update attestation schema: split into own entities

* update filter defnition

* basic resolver for  attestations

* fix fakeLogProvider types

* fix retroPGF schema

* fix tests

* use prisma instead of pg

* remove postgres query

* run prisma migrate for remote dev db

* set prisma db url dynamically

* configure ballot routes in workers

* log more data in error response

* don't log prisma instance

* log prisma connection

* log prisma connection to sentry

* log more data

* use prisma edge client

* log connection url

* remove unnecessary logs

* add like routes to workers

* remove unused import

* use PostgresSingleton the way it's supposed to

* import Prisma from prisma edge

* fix ballotService init

* remove unused

* add request wrappers

* fix authWrap type

* fix authWrap

* fix path parsing

* handler types

* debug

* cleanup

* cleanup

* fix path parsing

* naming

* fix handlers

* wrap veryfy token block

* remove loser comments

* fix sign on FE after view upgrade

* add signature column to ballots

* add submit ballot endpoint

* get address from the payload

* fix error response

* setup provider in handler

* wrap submit request

* split query
  • Loading branch information
stepandel committed Sep 22, 2023
1 parent 331eb3b commit e24658e
Show file tree
Hide file tree
Showing 54 changed files with 3,031 additions and 465 deletions.
4 changes: 4 additions & 0 deletions packages/backend/codegen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ generates:
Vote: ../governance#VoteModel

DelegateStatement: ../delegateStatement#DelegateStatementModel

RetroPGF: ../retroPGF#RetroPGFModel
Application: ../retroPGF#ApplicationModel
List: ../retroPGF#ListModel
11 changes: 8 additions & 3 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"build-dump-namespace": "esbuild --bundle --platform=node src/bin/scripts/dumpNamespace.ts --outfile=dist/dump.js",
"dump-namespace": "node dist/dump.js",
"check": "tsc --noEmit",
"fetch": "ts-node src/indexer/bin/fetch.ts OptimismGovernorTest && ts-node src/indexer/bin/fetch.ts GovernanceToken",
"fetch-prod": "ts-node src/indexer/bin/fetch.ts OptimismGovernor && ts-node src/indexer/bin/fetch.ts GovernanceToken",
"fetch": "ts-node src/indexer/bin/fetch.ts OptimismGovernorTest && ts-node src/indexer/bin/fetch.ts GovernanceToken && ts-node src/indexer/bin/fetch.ts EAS",
"fetch-prod": "ts-node src/indexer/bin/fetch.ts OptimismGovernor && ts-node src/indexer/bin/fetch.ts GovernanceToken && ts-node src/indexer/bin/fetch.ts EAS",
"backfill": "ts-node src/indexer/bin/backfill.ts dev",
"backfill-prod": "ts-node src/indexer/bin/backfill.ts prod",
"tail": "ts-node src/indexer/bin/tail.ts",
Expand All @@ -21,7 +21,8 @@
"server": "ts-node --require ./scripts/registerGraphQL.ts src/bin/server.ts",
"generate-typechain": "typechain --target ethers-v5 --out-dir src/contracts/generated src/contracts/abis/*.json",
"generate-schema-types": "graphql-codegen",
"generate": "yarn run generate-typechain && yarn run generate-schema-types",
"generate-prisma-types": "prisma generate",
"generate": "yarn run generate-typechain && yarn run generate-schema-types && yarn run generate-prisma-types",
"build-worker": "node scripts/buildWorker.js",
"visualize-worker-bundle": "esbuild-visualizer ---metadata ./dist/meta.json",
"stream": "ts-node src/indexer/ops/bin/stream.ts",
Expand All @@ -48,6 +49,7 @@
"@graphql-tools/merge": "^8.3.4",
"@graphql-tools/stitch": "^8.7.7",
"@graphql-yoga/node": "^2.13.12",
"@prisma/client": "^5.3.1",
"@sentry/integrations": "7.28.1",
"@types/seedrandom": "^3.0.5",
"alchemy-sdk": "^2.2.5",
Expand All @@ -58,6 +60,7 @@
"get-graphql-schema": "^2.1.2",
"graphql": "^16.6.0",
"heap": "^0.2.7",
"jose": "^4.14.6",
"level": "^8.0.0",
"limiter": "^2.1.0",
"lmdb": "^2.7.7",
Expand All @@ -68,6 +71,7 @@
"toucan-js": "^3.1.0",
"uuid": "^9.0.0",
"web3": "^1.8.1",
"siwe": "^2.1.4",
"wrangler": "^2.9.0",
"ws": "^8.12.0",
"zod": "3.14.2"
Expand Down Expand Up @@ -96,6 +100,7 @@
"graphql-request": "^5.0.0",
"jest": "^29.0.3",
"jest-junit": "^14.0.1",
"prisma": "^5.3.1",
"ts-jest": "^29.0.0",
"ts-node": "^10.9.1",
"typechain": "^8.1.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- CreateTable
CREATE TABLE "ballots" (
"address" TEXT NOT NULL,
"created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updated_at" TIMESTAMP(3),
"published_at" TIMESTAMP(3),
"votes" JSONB NOT NULL DEFAULT '[]',

CONSTRAINT "ballots_pkey" PRIMARY KEY ("address")
);

-- CreateTable
CREATE TABLE "likes" (
"id" TEXT NOT NULL,
"addresses" TEXT[] DEFAULT ARRAY[]::TEXT[],
"last_updated" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "likes_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "ballots_address_key" ON "ballots"("address");

-- CreateIndex
CREATE UNIQUE INDEX "likes_id_key" ON "likes"("id");
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "ballots" ADD COLUMN "signature" TEXT;
3 changes: 3 additions & 0 deletions packages/backend/prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "postgresql"
27 changes: 27 additions & 0 deletions packages/backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

generator client {
provider = "prisma-client-js"
}

model Ballot {
address String @id @unique
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime? @map("updated_at")
publishedAt DateTime? @map("published_at")
votes Json @default("[]") @db.JsonB
signature String? @map("signature")
@@map("ballots")
}

model Like {
id String @id @unique
addresses String[] @default([])
lastUpdated DateTime @default(now()) @map("last_updated")
@@map("likes")
}
23 changes: 23 additions & 0 deletions packages/backend/src/bin/proxyServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import express from "express";
import { createProxyMiddleware } from "http-proxy-middleware";

export function startProxyServer() {
const app = express();

app.use(
"/graphql",
createProxyMiddleware({
target: "http://0.0.0.0:4002/",
changeOrigin: true,
})
);
app.use(
"/api",
createProxyMiddleware({
target: "http://0.0.0.0:4003/",
changeOrigin: true,
})
);

app.listen(4001);
}
Loading

0 comments on commit e24658e

Please sign in to comment.