Alex Xu 7 months ago
parent
commit
09fc79ff1e
5 changed files with 235 additions and 374 deletions
  1. 2 0
      src/constants/index.ts
  2. 20 8
      src/controllers/bn/index.ts
  3. 10 2
      src/db/index.ts
  4. 4 2
      src/monitor/bnTaskMonitor.ts
  5. 199 362
      yarn.lock

+ 2 - 0
src/constants/index.ts

@@ -6,6 +6,8 @@ export const DB_PORT = process.env.DB_PORT
 export const DB_NAME = process.env.DB_NAME
 export const DB_USER = process.env.DB_USER
 export const DB_PASS = process.env.DB_PASS
+export const DB_DIALECT = process.env.DB_DIALECT ?? 'mysql'
+export const BSC_RPC = process.env.BSC_RPC ?? 'https://binance.llamarpc.com'
 export const TG_BOT_TOKEN = process.env.TG_BOT_TOKEN
 export const DATA_SERVICR_BASE_URL = process.env.DATA_SERVICR_BASE_URL!
 export const DATA_SERVICR_USERNAME = process.env.DATA_SERVICR_USERNAME!

+ 20 - 8
src/controllers/bn/index.ts

@@ -1,4 +1,10 @@
-import { Request, RequestHandler, NextFunction, Router } from 'express'
+import {
+  Request,
+  RequestHandler,
+  NextFunction,
+  Router,
+  Response,
+} from 'express'
 import { Controller } from '../types'
 import jsonResponseMiddleware, {
   JsonResponse,
@@ -13,8 +19,10 @@ import { TiktokData } from '../../db/models/Tiktok'
 import { PaginationData } from '../../services/types'
 import bnService, { BnData, BnRequest } from '../../services/bnService'
 
+// https://developers.binance.com/docs/w3w_task_verification_api/apis#general-api-information
+// 特殊化,直接从根开始/v1
 export default class BnTask implements Controller {
-  public path = '/api/v1'
+  public path = '/v1'
   public router = Router()
 
   constructor() {
@@ -25,7 +33,7 @@ export default class BnTask implements Controller {
     this.router.get(
       '/task/completion',
       // apiKeyMiddleware(),
-      jsonResponseMiddleware,
+      // jsonResponseMiddleware,
       this.searchAddress as RequestHandler
     )
     this.router.get(
@@ -38,11 +46,11 @@ export default class BnTask implements Controller {
 
   private time(
     request: Request<any, any, any, { after?: string }>,
-    response: JsonResponse<BnData>,
+    response: Response,
     next: NextFunction
   ): void {
     const currentTimestamp = Date.now()
-    response.status(200).jsonSuccess({
+    response.status(200).json({
       code: '000000',
       message: 'success',
       data: currentTimestamp.toString(),
@@ -51,16 +59,20 @@ export default class BnTask implements Controller {
 
   private searchAddress(
     request: Request<any, any, any, { after?: string }>,
-    response: JsonResponse<BnData>,
+    response: Response<BnData>,
     next: NextFunction
   ): void {
     bnService
       .searchStatus(request.query as BnRequest)
       .then((bnData) => {
-        response.status(200).jsonSuccess(bnData)
+        response.status(200).json(bnData)
       })
       .catch((e) => {
-        response.status(500).jsonError('Server Error', 1010)
+        response.status(500).json({
+          code: '000007',
+          message: e.message,
+          data: null,
+        })
       })
   }
 }

+ 10 - 2
src/db/index.ts

@@ -1,7 +1,15 @@
 import { Sequelize } from 'sequelize-typescript'
 import * as Models from './models'
 import { RPC } from '../utils/EVMHelper/dbModels'
-import { DB_HOST, DB_NAME, DB_PASS, DB_PORT, DB_USER } from '../constants'
+import {
+  DB_DIALECT,
+  DB_HOST,
+  DB_NAME,
+  DB_PASS,
+  DB_PORT,
+  DB_USER,
+} from '../constants'
+import { Dialect } from 'sequelize'
 // import { promisify } from 'util'
 
 const {
@@ -20,7 +28,7 @@ const sequelize = new Sequelize({
   host: DB_HOST,
   port: DB_PORT ? Number.parseInt(DB_PORT) : 3306,
   database: DB_NAME,
-  dialect: 'mysql',
+  dialect: DB_DIALECT as Dialect,
   username: DB_USER,
   password: DB_PASS,
   dialectOptions: {

+ 4 - 2
src/monitor/bnTaskMonitor.ts

@@ -6,10 +6,11 @@ import BnMonitor from '../db/models/BnMonitor'
 import BnWhiteList from '../db/models/BnWhiteList'
 import sequelize from '../db'
 import BnTransaction from '../db/models/TransferInfo'
+import { BSC_RPC } from '../constants'
 
 dotenv.config()
 let networkInfo: ethers.Network
-const provider = new ethers.JsonRpcProvider('https://binance.llamarpc.com')
+const provider = new ethers.JsonRpcProvider(BSC_RPC)
 let monitorRunning = false
 export async function bnMonitor(): Promise<void> {
   await initMonitor()
@@ -94,7 +95,8 @@ async function startMonitor() {
             type: 1,
           }
         }
-        return null      })
+        return null
+      })
       .filter((tx) => tx !== null)
     if (transferInfo.length > 0) {
       await sequelize.transaction(async (tx) => {

File diff suppressed because it is too large
+ 199 - 362
yarn.lock


Some files were not shown because too many files changed in this diff