Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Art-Peace Indexer & Backend #194

Merged
merged 38 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ddf690a
feat: add Railway Dockerfile
EjembiEmmanuel Oct 18, 2024
8605d9d
refac: modify Dockerfile.railway
EjembiEmmanuel Oct 19, 2024
0dc149d
refac: modify Dockerfile.railway
EjembiEmmanuel Oct 19, 2024
ba37394
refac: modify Dockerfile.railway
EjembiEmmanuel Oct 19, 2024
54e540d
refac: modify Dockerfile.railway
EjembiEmmanuel Oct 19, 2024
1802b6b
refac: modify Dockerfile.railway
EjembiEmmanuel Oct 19, 2024
c8450f2
refac: modify Dockerfile.railway
EjembiEmmanuel Oct 19, 2024
2dd0419
feat: add railway config
EjembiEmmanuel Oct 19, 2024
6583a26
fix: fix railway build environment
EjembiEmmanuel Oct 19, 2024
d7d64c4
fix: fix railway config
EjembiEmmanuel Oct 19, 2024
62a091a
fix: fix railway config
EjembiEmmanuel Oct 19, 2024
4c078fd
fix: fix railway config
EjembiEmmanuel Oct 19, 2024
0090256
doc: add Railway deployment guide to README.md
EjembiEmmanuel Oct 19, 2024
30517dc
chore: remove unused file
EjembiEmmanuel Oct 19, 2024
542936d
fix: fix data-backend
EjembiEmmanuel Oct 20, 2024
759a279
fix: fix indexer-prisma
EjembiEmmanuel Oct 20, 2024
f7dbf13
fix: fix indexer prisma import
EjembiEmmanuel Oct 21, 2024
c085809
feat: setup indexer railway deploy config
EjembiEmmanuel Oct 23, 2024
01c8d89
chore: delete redundant files
EjembiEmmanuel Oct 23, 2024
3ce5238
feat: setup railway deploy config for backend
EjembiEmmanuel Oct 23, 2024
95fd032
fix: fix railway.json
EjembiEmmanuel Oct 23, 2024
d3c3b62
fix: add env variables to railway Dockerfile
EjembiEmmanuel Oct 23, 2024
206f940
feat: add log statement
EjembiEmmanuel Oct 23, 2024
cc294b3
refac: modify log statement
EjembiEmmanuel Oct 23, 2024
e80ee9a
refac: modify log statement
EjembiEmmanuel Oct 23, 2024
2e5b5c2
chore: clean code
EjembiEmmanuel Oct 23, 2024
b79abc7
refac: fallback to default env if no .env file
EjembiEmmanuel Oct 23, 2024
1a06fb7
feat: delete railway config
EjembiEmmanuel Oct 23, 2024
e8db6b0
feat: setup backend & consumer railway Dockerfiles
EjembiEmmanuel Oct 23, 2024
77086f1
feat: add backend railway config
EjembiEmmanuel Oct 23, 2024
e5631b7
feat: remove admin flag
EjembiEmmanuel Oct 23, 2024
8a041f6
feat: setup consumer railway config
EjembiEmmanuel Oct 23, 2024
be955ed
fix: fix file name typo
EjembiEmmanuel Oct 23, 2024
aafcef1
refac: modify docker start command
EjembiEmmanuel Oct 23, 2024
e468071
feat: add backend url env variable to Dockerfile
EjembiEmmanuel Oct 23, 2024
c223632
Merge branch 'main' into main
EjembiEmmanuel Oct 23, 2024
804974e
refac: clean code
EjembiEmmanuel Oct 23, 2024
932df9d
Merge branch 'main' of github.com:EjembiEmmanuel/afk_monorepo
EjembiEmmanuel Oct 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Backend.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ ARG INDEXER_DATABASE_URL
# Set the environment variable
ENV INDEXER_DATABASE_URL=${INDEXER_DATABASE_URL}

# Add an argument for th Backend postgres url
ARG BACKEND_DATABASE_URL

# Set the environment variable
ENV BACKEND_DATABASE_URL=${BACKEND_DATABASE_URL}

# Add an argument for Telegram webapp
ARG TELEGRAM_WEB_APP
Expand All @@ -38,10 +43,8 @@ COPY . .
# Build the indexer-prisma package
RUN pnpm --filter indexer-prisma build


# Build the data-backend package
RUN pnpm --filter data-backend build

RUN pnpm --filter data-backend build:all

# Use a smaller production base image
FROM node:18-alpine AS production
Expand Down
6 changes: 3 additions & 3 deletions apps/data-backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
TELEGRAM_WEB_APP="https://tg.afk-community.xyz"

INDEXER_DATABASE_URL="postgresql://postgres"
TELEGRAM_BOT_TOKEN=TG_BOT_FATHER
INDEXER_DATABASE_URL="postgresql://postgres:postgres@localhost:5434/indexer"
TELEGRAM_BOT_TOKEN="TG_BOT_FATHER"
TG_ADMIN_CHAT_ID=
WEBHOOK_DOMAIN="https://data-backend.xyz"

BACKEND_DATABASE_URL=
BACKEND_DATABASE_URL="postgresql://postgres:postgres@localhost:5433/data-backend"
APP_URL_WEB="http://localhost:8081"

FUNKIT_API_KEY=
Expand Down
3 changes: 3 additions & 0 deletions apps/data-backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,6 @@ dist
# next
.next
next-env.d.ts

# prisma
.prisma
46 changes: 0 additions & 46 deletions apps/data-backend/Dockerfile

This file was deleted.

6 changes: 6 additions & 0 deletions apps/data-backend/README.Md → apps/data-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ Telegram bot answers for AFK Mini app.
sudo lsof -t -i:5050

sudo kill -9 [ID_RECEIVED_BEFORE]
```

## Run Backend Postgres database

```
docker run --name afk-data-backend -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=postgres -e POSTGRES_DB=data-backend -d -p 5433:5432 postgres
```
5 changes: 3 additions & 2 deletions apps/data-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"scripts": {
"build": "tsc",
"build:index": "tsc",
"build:all":"pnpm run build:indexer-prisma && cd ../../apps/data-backend tsc",
"build:all_repo": "pnpm run build:indexer-prisma && cd ../../apps/data-backend && pnpm prisma:setup && tsc",
"build:all_repo": "pnpm run build:indexer-prisma && cd ../../apps/data-backend tsc",
"build:all": "pnpm run prisma:setup && tsc",
"start": "ts-node src/index.ts",
"start:dev": "ts-node-dev src/index.ts",
"start:prod": "ts-node dist/index.js",
Expand Down Expand Up @@ -41,6 +41,7 @@
"nodemailer": "^6.9.15",
"pg": "^8.12.0",
"pg-promise": "^11.9.1",
"stripe": "^17.2.1",
"telegraf": "^4.16.3",
"twilio": "^5.3.3",
"typescript": "^5.5.4"
Expand Down
129 changes: 16 additions & 113 deletions apps/data-backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,124 +1,27 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
provider = "prisma-client-js"
output = ".prisma/client"
}

datasource db {
provider = "postgresql"
url = env("BACKEND_DATABASE_URL")
}

model token_deploy {
memecoin_address String?
network String?
block_hash String?
block_number BigInt?
block_timestamp DateTime? @db.Timestamp(6)
transaction_hash String @id
owner_address String?
name String?
symbol String?
initial_supply String?
total_supply String?
created_at DateTime? @default(now()) @db.Timestamp(6)
cursor BigInt? @map("_cursor")
time_stamp String?
}

model token_launch {
memecoin_address String?
network String?
block_hash String?
block_number BigInt?
block_timestamp DateTime? @db.Timestamp(6)
transaction_hash String @id
quote_token String?
exchange_name String?
created_at DateTime? @default(now()) @db.Timestamp(6)
total_supply String?
current_supply String?
liquidity_raised String?
price String?
cursor BigInt? @map("_cursor")
time_stamp String?
}

/// This table contains check constraints and requires additional setup for migrations. Visit https://pris.ly/d/check-constraints for more info.
model token_transactions {
transfer_id String @id
network String?
block_hash String?
block_number BigInt?
block_timestamp DateTime? @db.Timestamp(6)
transaction_hash String?
memecoin_address String?
owner_address String?
last_price String?
quote_amount String?
coin_received String?
initial_supply String?
created_at DateTime? @default(now()) @db.Timestamp(6)
total_supply String?
current_supply String?
liquidity_raised String?
price String?
protocol_fee String?
amount Decimal? @db.Decimal
cursor BigInt? @map("_cursor")
transaction_type String
time_stamp String?
}

model unrugmeme_deploy {
network String?
block_hash String?
block_number BigInt?
block_timestamp DateTime? @db.Timestamp(6)
transaction_hash String?
memecoin_address String @id
owner_address String?
name String?
symbol String?
initial_supply String?
created_at DateTime? @default(now()) @db.Timestamp(6)
cursor BigInt? @map("_cursor")
}

model unrugmeme_launch {
network String?
block_hash String?
block_number BigInt?
block_timestamp DateTime? @db.Timestamp(6)
transaction_hash String?
memecoin_address String @id
quote_token String?
exchange_name String?
created_at DateTime? @default(now()) @db.Timestamp(6)
cursor BigInt? @map("_cursor")
}

model unrugmeme_transfers {
network String?
block_hash String?
block_number BigInt?
block_timestamp DateTime? @db.Timestamp(6)
transaction_hash String?
transfer_id String @id
from_address String?
to_address String?
memecoin_address String?
amount String?
created_at DateTime? @default(now()) @db.Timestamp(6)
cursor BigInt? @map("_cursor")
}

model registration {
contract_address String @id
nickname String?
created_at DateTime? @default(now()) @db.Timestamp(6)
is_confirmed Boolean? @default(false)
phoneNumber String?
email String?
starknetAddress String?
evmAddress String?

id Int @id() @default(autoincrement())
contract_address String?
nickname String?
created_at DateTime? @default(now()) @db.Timestamp(6)
is_confirmed Boolean? @default(false)
phone_number String?
email String?
starknet_address String?
evm_address String?
}
4 changes: 1 addition & 3 deletions apps/data-backend/src/constants/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ export const VAULT_FACTORY_ADDRESSES: AddressesMap = {
"0x33498f0d9e6ebef71b3d8dfa56501388cfe5ce96cba81503cd8572be92bd77c",
};

export const DEFAULT_NETWORK_NAME = constants.NetworkName.SN_SEPOLIA;

// eslint-disable-next-line import/no-unused-modules
export const SN_CHAIN_ID = (constants.StarknetChainId[
(process.env.SN_NETWORK ?? "") as constants.NetworkName
] ?? constants.StarknetChainId[DEFAULT_NETWORK_NAME]) as SupportedChainId;
] ?? constants.StarknetChainId[constants.NetworkName.SN_SEPOLIA]) as SupportedChainId;

// const NODE_URLS = {
// [constants.StarknetChainId.SN_MAIN]: (apiKey: string) => `https://rpc.nethermind.io/mainnet-juno/?apikey=${apiKey}`,
Expand Down
2 changes: 1 addition & 1 deletion apps/data-backend/src/routes/indexer/all-transactions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FastifyInstance, RouteOptions } from "fastify";
import { prisma } from "indexer-prisma";
import prisma from "indexer-prisma"
import { HTTPStatus } from "../../utils/http";
import { isValidStarknetAddress } from "../../utils/starknet";

Expand Down
2 changes: 1 addition & 1 deletion apps/data-backend/src/routes/indexer/buy-coin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FastifyInstance, RouteOptions } from "fastify";
import { prisma } from "indexer-prisma";
import prisma from "indexer-prisma"
import { HTTPStatus } from "../../utils/http";

async function buyCoinRoute(fastify: FastifyInstance, options: RouteOptions) {
Expand Down
2 changes: 1 addition & 1 deletion apps/data-backend/src/routes/indexer/deploy-launch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FastifyInstance, RouteOptions } from "fastify";
import { prisma } from "indexer-prisma";
import prisma from "indexer-prisma"
import { HTTPStatus } from "../../utils/http";
import { isValidStarknetAddress } from "../../utils/starknet";

Expand Down
2 changes: 1 addition & 1 deletion apps/data-backend/src/routes/indexer/deploy-token.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FastifyInstance, RouteOptions } from "fastify";
import { prisma } from "indexer-prisma";
import prisma from "indexer-prisma"
import { HTTPStatus } from "../../utils/http";
import { isValidStarknetAddress } from "../../utils/starknet";

Expand Down
2 changes: 1 addition & 1 deletion apps/data-backend/src/routes/indexer/graph.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FastifyInstance, RouteOptions } from "fastify";
import { prisma } from "indexer-prisma";
import prisma from "indexer-prisma"
import { HTTPStatus } from "../../utils/http";
import { isValidStarknetAddress } from "../../utils/starknet";

Expand Down
2 changes: 1 addition & 1 deletion apps/data-backend/src/routes/indexer/holdings.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FastifyInstance, RouteOptions } from "fastify";
import { prisma } from "indexer-prisma";
import prisma from "indexer-prisma"
import { HTTPStatus } from "../../utils/http";
import { isValidStarknetAddress } from "../../utils/starknet";

Expand Down
2 changes: 1 addition & 1 deletion apps/data-backend/src/routes/indexer/token_stats.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FastifyInstance, RouteOptions } from "fastify";
import { prisma } from "indexer-prisma";
import prisma from "indexer-prisma"
import { HTTPStatus } from "../../utils/http";
import { isValidStarknetAddress } from "../../utils/starknet";

Expand Down
2 changes: 1 addition & 1 deletion apps/data-backend/src/routes/indexer/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { FastifyInstance, RouteOptions } from "fastify";
import { prisma } from "indexer-prisma";
import prisma from "indexer-prisma"
import { HTTPStatus } from "../../utils/http";
import { isValidStarknetAddress } from "../../utils/starknet";

Expand Down
9 changes: 5 additions & 4 deletions apps/data-backend/src/routes/otp/getOtp.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { FastifyInstance } from "fastify";
import { VerificationListInstance } from "twilio/lib/rest/verify/v2/service/verification";
import { prisma } from "@prisma/client";
import { PrismaClient } from "../../../prisma/.prisma/client";

interface GetOtpRequestBody {
phone_number: string;
Expand Down Expand Up @@ -32,19 +32,20 @@ async function getOtp(
const { phone_number, nickname } = request.body;

// validating if phone number exists in db
const prisma = new PrismaClient();

const record_by_phone_number = await prisma.registration.findFirst({
where: {
phoneNumber: phone_number,
phone_number: phone_number,
},
orderBy: { created_at: "desc" },
});

if (!record_by_phone_number.length) {
if (!record_by_phone_number) {
try {
await prisma.registration.create({
data: {
phoneNumber: phone_number,
phone_number: phone_number,
nickname,
},
});
Expand Down
Loading
Loading