Skip to content

Commit

Permalink
Merge pull request #188 from luxfi/fix/server-compile-issues
Browse files Browse the repository at this point in the history
Fix/server compile issues
  • Loading branch information
venuswhispers authored Nov 11, 2024
2 parents e47473a + fa73df2 commit e068938
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 103 deletions.
167 changes: 118 additions & 49 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion server/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ yarn-error.log*
*.tsbuildinfo
next-env.d.ts

prisma/
prisma/client/
prisma/dev.sqlite
12 changes: 8 additions & 4 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"db": "node dist/db.js",
"nodes": "node dist/nodes.js",
"tc": "tsc",
"build": "tsc && tsc-alias && npx prisma generate",
"prisma:gen": "pnpx prisma generate",
"build": "tsc && tsc-alias && pnpx prisma generate",
"start": "ts-node src/server.ts",
"lint": "eslint src/**/*.ts",
"format": "eslint src/**/*.ts --fix",
Expand All @@ -32,7 +33,8 @@
"devDependencies": {
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/node": "^22.4.1",
"@types/multicoin-address-validator": "^0.5.3",
"@types/node": "^20.11.0",
"@typescript-eslint/eslint-plugin": "^8.2.0",
"@typescript-eslint/parser": "^8.2.0",
"eslint": "^8.57.0",
Expand All @@ -48,13 +50,15 @@
},
"dependencies": {
"@prisma/client": "^5.22.0",
"@solana/web3.js": "^1.95.4",
"@solana/addresses": "2.0.0-preview.1.20240323014038.94f2053250ed5d78cd55951bdec72ef7795e528e",
"axios": "^1.7.4",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"ethers": "^6.13.4",
"express": "^4.19.2",
"express-validator": "^7.2.0",
"multicoin-address-validator": "^0.5.22"
"module-alias": "^2.2.3",
"multicoin-address-validator": "^0.5.22",
"prisma-client-91ed9af6366cdee33d6f3efcfe3929e8a5eb9f021d6e86a20189872a17e5b7eb": "link:prisma/client"
}
}
8 changes: 3 additions & 5 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

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

datasource db {
provider = "postgresql"
// provider = "sqlite"
// provider = "postgresql"
provider = "sqlite"
url = env("POSTGRESQL_URL") // uses connection pooling
directUrl = env("POSTGRESQL_URL") // uses a direct connection
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const main = async () => {
networksCount: networks.length,
currenciesCount: currenciesCount
})
} catch (error) {
} catch (error: any) {
console.error("Error in updating networks", error)
}
}
Expand Down
34 changes: 15 additions & 19 deletions server/src/lib/swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export async function handleSwapCreation(data: SwapData) {
reward: null
}
return result
} catch (error) {
} catch (error: any) {
console.log(error)
//catchPrismaKnowError(error)
throw new Error(`Error creating swap and related entities: ${error?.message}`)
Expand Down Expand Up @@ -232,7 +232,7 @@ export async function handlerGetSwap(id: string) {
destination_network: swap?.destination_network?.internal_name,
destination_asset: swap?.destination_asset?.asset
}
} catch (error) {
} catch (error: any) {
//catchPrismaKnowError(error)
throw new Error(`Error getting swap: ${error?.message}`)
}
Expand Down Expand Up @@ -291,7 +291,7 @@ export async function handlerUpdateUserTransferAction(id: string, txHash: string
return {
...swap
}
} catch (error) {
} catch (error: any) {
console.log(error)
//catchPrismaKnowError(error)
throw new Error(`Error getting swap: ${error?.message}`)
Expand Down Expand Up @@ -351,7 +351,7 @@ export async function handlerUpdatePayoutAction(id: string, txHash: string, amou
return {
...swap
}
} catch (error) {
} catch (error: any) {
console.log(error)
//catchPrismaKnowError(error)
throw new Error(`Error getting swap: ${error?.message}`)
Expand Down Expand Up @@ -411,17 +411,15 @@ export async function handlerUpdateMpcSignAction(id: string, txHash: string, amo
return {
...swap
}
} catch (error) {
} catch (error: any) {
console.log(error)
//catchPrismaKnowError(error)
throw new Error(`Error getting swap: ${error?.message}`)
}
}

export async function handlerGetSwaps(address: string, isDeleted: boolean | undefined) {
export async function handlerGetSwaps(address: string, isDeleted: boolean | undefined, isMainnet: boolean = false) {
try {
const isMainnet = process.env.NEXT_PUBLIC_API_VERSION === "mainnet"

const swaps = await prisma.swap.findMany({
orderBy: {
created_date: "desc"
Expand Down Expand Up @@ -451,16 +449,14 @@ export async function handlerGetSwaps(address: string, isDeleted: boolean | unde
}
})

console.log(swaps)

return swaps.map((s) => ({
return swaps.map((s: any) => ({
...s,
source_network: s?.source_network?.internal_name,
source_asset: s?.source_asset?.asset,
destination_network: s?.destination_network?.internal_name,
destination_asset: s?.destination_asset?.asset
}))
} catch (error) {
} catch (error: any) {
//catchPrismaKnowError(error)
throw new Error(`Error getting swap: ${error?.message}`)
}
Expand Down Expand Up @@ -499,15 +495,15 @@ export async function handlerGetHasBySwaps(address: string) {

return [{ ...transaction.swap }]
}
} catch (error) {
} catch (error: any) {
//catchPrismaKnowError(error)
throw new Error(`Error getting swap: ${error?.message}`)
}
}

export async function handlerGetExplorer(status: string[]) {
console.time()
const statuses = status.map((number) => statusMapping[number])
const statuses = status.map((numberStr: string) => statusMapping[Number(numberStr)])
console.log("🚀 ~ handlerGetExplorer ~ statuses:", statuses)

try {
Expand Down Expand Up @@ -540,14 +536,14 @@ export async function handlerGetExplorer(status: string[]) {
})

console.timeEnd()
return swaps.map((s) => ({
return swaps.map((s: any) => ({
...s,
source_network: s?.source_network?.internal_name,
source_asset: s?.source_asset?.asset,
destination_network: s?.destination_network?.internal_name,
destination_asset: s?.destination_asset?.asset
}))
} catch (error) {
} catch (error: any) {
//catchPrismaKnowError(error)
throw new Error(`Error getting swap: ${error?.message}`)
}
Expand All @@ -560,7 +556,7 @@ export async function handlerUpdateSwaps(swapData: { id: string }) {
data: { ...swapData }
})
return "success"
} catch (error) {
} catch (error: any) {
//catchPrismaKnowError(error)
throw new Error(`Error deleting swaps: ${error?.message}`)
}
Expand Down Expand Up @@ -622,7 +618,7 @@ export async function handlerUpdateSwap(swapData: UpdateSwapData) {
} else {
return "failed"
}
} catch (error) {
} catch (error: any) {
//catchPrismaKnowError(error)
throw new Error(`Error deleting swaps: ${error?.message}`)
}
Expand All @@ -635,7 +631,7 @@ export async function handlerDelSwap(swapData: { id: string }) {
data: { ...swapData }
})
return "success"
} catch (error) {
} catch (error: any) {
//catchPrismaKnowError(error)
throw new Error(`Error deleting swaps: ${error?.message}`)
}
Expand Down
10 changes: 5 additions & 5 deletions server/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import KnownInternalNames from "@/config/constants"
import WAValidator from "multicoin-address-validator"
import { isAddress } from "ethers"
import { PublicKey } from "@solana/web3.js"
// https://www.npmjs.com/package/@solana/addresses/v/2.0.0-preview.1.20240323014038.94f2053250ed5d78cd55951bdec72ef7795e528e

import { isAddress as isSolanoAddress } from "@solana/addresses"

export function isValidAddress(address?: string, network?: { internal_name: string } | null): boolean {
if (!address) {
Expand Down Expand Up @@ -33,10 +35,8 @@ export function isValidAddress(address?: string, network?: { internal_name: stri
return false
} else if (network?.internal_name === KnownInternalNames.Networks.SolanaMainnet || network?.internal_name === KnownInternalNames.Networks.SolanaTestnet || network?.internal_name === KnownInternalNames.Networks.SolanaDevnet) {
try {
let pubkey = new PublicKey(address)
let isSolana = PublicKey.isOnCurve(pubkey.toBuffer())
return isSolana
} catch (error) {
return isSolanoAddress(address)
} catch (error: any) {
return false
}
} else if (network?.internal_name === KnownInternalNames.Networks.SorareStage) {
Expand Down
10 changes: 5 additions & 5 deletions server/src/models/CryptoNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export enum NetworkType {
Bitocoin = "btc"
}

export class CryptoNetwork {
export type CryptoNetwork = {
display_name: string;
internal_name: string;
transaction_explorer_template: string;
Expand All @@ -26,7 +26,7 @@ export class CryptoNetwork {
img_url?: string
}

export class NetworkCurrency {
export type NetworkCurrency = {
asset: string;
is_refuel_enabled: boolean;
is_native: boolean
Expand All @@ -38,13 +38,13 @@ export class NetworkCurrency {
availableInSource: boolean;
availableInDestination: boolean;
}
export class NetworkNode {
export type NetworkNode = {
url: string;
}
export class ManagedAccount {
export type ManagedAccount = {
address: `0x${string}`;
}
export class Metadata {
export type Metadata = {
multicall3?: {
address: `0x${string}`
blockCreated: number
Expand Down
8 changes: 4 additions & 4 deletions server/src/routes/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ router.get("/", async (req: Request, res: Response) => {
// const { statuses } = req.query
// // Get version from query parameter
// const version = req.query.version
const statuses = []
const result = await handlerGetExplorer(statuses as string[])
const statuses: string[] = []
const result = await handlerGetExplorer(statuses)
console.log("🚀 ~ result:", result)
res.status(200).json({ data: result })
} catch (error) {
} catch (error: any) {
res.status(500).json({ error: error?.message })
}
})
Expand All @@ -33,7 +33,7 @@ router.get("/:transaction_has", async (req: Request, res: Response) => {
} else {
res.status(200).json({ data: [] })
}
} catch (error) {
} catch (error: any) {
res.status(500).json({ error: error?.message })
}
})
Expand Down
2 changes: 1 addition & 1 deletion server/src/routes/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ router.get("/", async (req: Request, res: Response) => {
console.log("🚀 ~ settings:", settings)
res.status(200).json({ data: settings })
}
catch (error) {
catch (error: any) {
res.status(500).json({ error: error?.message })
}
})
Expand Down
16 changes: 9 additions & 7 deletions server/src/routes/swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ const router: Router = Router()
router.get("/", async (req: Request, res: Response) => {
try {
const isDeleted = (req.query.isDeleted && Boolean(Number(req.query.isDeleted))) || undefined
const result = await handlerGetSwaps(req.query.address as string, isDeleted)
const isMainnet = req.query?.version === "mainnet"
console.log({ isDeleted, isMainnet })
const result = await handlerGetSwaps(req.query.address as string, isDeleted, isMainnet)
res.status(200).json({ data: result })
} catch (error) {
} catch (error: any) {
res.status(500).json({ error: error?.message })
}
})
Expand All @@ -27,7 +29,7 @@ router.get("/:swapId", async (req: Request, res: Response) => {
console.log({ swapId })
const result = await handlerGetSwap(swapId as string)
res.status(200).json({ data: result })
} catch (error) {
} catch (error: any) {
res.status(500).json({ error: error?.message })
}
})
Expand Down Expand Up @@ -56,7 +58,7 @@ router.post(
...req.body
})
res.status(200).json({ data: { ...result } })
} catch (error) {
} catch (error: any) {
console.log(error)
res.status(500).json({ error: error?.message })
}
Expand All @@ -78,7 +80,7 @@ router.post(
const { txHash, amount, from, to } = req.body
const result = await handlerUpdateUserTransferAction(swapId as string, txHash, Number(amount), from, to)
res.status(200).json({ data: result })
} catch (error) {
} catch (error: any) {
res.status(500).json({ error: error?.message })
}
}
Expand All @@ -99,7 +101,7 @@ router.post(
const { txHash, amount, from, to } = req.body
const result = await handlerUpdatePayoutAction(swapId as string, txHash, Number(amount), from, to)
res.status(200).json({ data: result })
} catch (error) {
} catch (error: any) {
res.status(500).json({ error: error?.message })
}
}
Expand All @@ -120,7 +122,7 @@ router.post(
const { txHash, amount, from, to } = req.body
const result = await handlerUpdateMpcSignAction(swapId as string, txHash, Number(amount), from, to)
res.status(200).json({ data: result })
} catch (error) {
} catch (error: any) {
res.status(500).json({ error: error?.message })
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/routes/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ router.get("/price/:token_id", async (req: Request, res: Response) => {
price
}})
}
catch (error) {
catch (error: any) {
res.status(500).json({ error: error?.message })
}
})
Expand Down
2 changes: 1 addition & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import express, { Express, Request, Response } from "express"
import express, { Express } from "express"
import cors from "cors"
import dotenv from "dotenv"
//routers
Expand Down
Empty file removed server/src/types/index.ts
Empty file.

0 comments on commit e068938

Please sign in to comment.