Skip to content

Commit

Permalink
Fix error handler, fix eslint config
Browse files Browse the repository at this point in the history
  • Loading branch information
rickyrombo committed May 30, 2024
1 parent 5933946 commit 01229c6
Show file tree
Hide file tree
Showing 22 changed files with 798 additions and 645 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
root: true,
extends: ["custom-server"],
};
extends: ['audius']
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Keypair, PublicKey } from '@solana/web3.js'
import dotenv from 'dotenv'
import { cleanEnv, str, num, json } from 'envalid'

import { logger } from './logger'
import { Keypair, PublicKey } from '@solana/web3.js'

export const ClockProgram = new PublicKey('SysvarC1ock11111111111111111111111111111111')
export const InstructionsProgram = new PublicKey('Sysvar1nstructions1111111111111111111111111')
export const ClockProgram = new PublicKey(
'SysvarC1ock11111111111111111111111111111111'
)
export const InstructionsProgram = new PublicKey(
'Sysvar1nstructions1111111111111111111111111'
)

// reads .env file based on environment
const readDotEnv = () => {
Expand Down Expand Up @@ -35,7 +40,7 @@ type Config = {
usdcMintAddress: string
waudioMintAddress: string
solanaFeePayerWallets: Keypair[]
delegatePrivateKey: Buffer,
delegatePrivateKey: Buffer
ipdataApiKey: string | null
listensValidSigner: string
solanaSignerPrivateKey: string
Expand Down Expand Up @@ -104,13 +109,14 @@ const readConfig = (): Config => {
default: '01b633611c0b57babd56a6fdf7400b21340956e1840da6dd788f9c37'
}),
audius_solana_eth_registry_program: str({
default: 'testBgRfFcage1hN7zmTsktdQCJZkHEhM1eguYPaeKg',
default: 'testBgRfFcage1hN7zmTsktdQCJZkHEhM1eguYPaeKg'
}),
audius_solana_listens_valid_signer: str({
default: 'yM9adjwKaRbYxQzLPF6zvZMSAfKUNte5xvK4B3iGbkL',
default: 'yM9adjwKaRbYxQzLPF6zvZMSAfKUNte5xvK4B3iGbkL'
}),
audius_solana_signer_private_key: str({
default: 'd242765e718801781440d77572b9dafcdc9baadf0269eff24cf61510ddbf1003',
default:
'd242765e718801781440d77572b9dafcdc9baadf0269eff24cf61510ddbf1003'
})
})
const solanaFeePayerWalletsParsed = env.audius_solana_fee_payer_wallets
Expand All @@ -125,26 +131,27 @@ const readConfig = (): Config => {
: Buffer.from([])

cachedConfig = {
endpoint: env.audius_discprov_url,
discoveryDbConnectionString: env.audius_db_url,
redisUrl: env.audius_redis_url,
serverHost: env.solana_relay_server_host,
serverPort: env.solana_relay_server_port,
solanaEndpoints: env.audius_solana_endpoint.split(','),
rewardsManagerProgramId: env.audius_solana_rewards_manager_program_address,
rewardsManagerAccountAddress: env.audius_solana_rewards_manager_account,
claimableTokenProgramId: env.audius_solana_user_bank_program_address,
paymentRouterProgramId: env.audius_solana_payment_router_program_address,
trackListenCountProgramId: env.audius_solana_track_listen_count_address,
usdcMintAddress: env.audius_solana_usdc_mint,
waudioMintAddress: env.audius_solana_waudio_mint,
solanaFeePayerWallets,
delegatePrivateKey,
ipdataApiKey: env.audius_ipdata_api_key === "" ? null : env.audius_ipdata_api_key,
listensValidSigner: env.audius_solana_listens_valid_signer,
ethRegistryProgramId: env.audius_solana_eth_registry_program,
solanaSignerPrivateKey: env.audius_solana_signer_private_key
}
endpoint: env.audius_discprov_url,
discoveryDbConnectionString: env.audius_db_url,
redisUrl: env.audius_redis_url,
serverHost: env.solana_relay_server_host,
serverPort: env.solana_relay_server_port,
solanaEndpoints: env.audius_solana_endpoint.split(','),
rewardsManagerProgramId: env.audius_solana_rewards_manager_program_address,
rewardsManagerAccountAddress: env.audius_solana_rewards_manager_account,
claimableTokenProgramId: env.audius_solana_user_bank_program_address,
paymentRouterProgramId: env.audius_solana_payment_router_program_address,
trackListenCountProgramId: env.audius_solana_track_listen_count_address,
usdcMintAddress: env.audius_solana_usdc_mint,
waudioMintAddress: env.audius_solana_waudio_mint,
solanaFeePayerWallets,
delegatePrivateKey,
ipdataApiKey:
env.audius_ipdata_api_key === '' ? null : env.audius_ipdata_api_key,
listensValidSigner: env.audius_solana_listens_valid_signer,
ethRegistryProgramId: env.audius_solana_eth_registry_program,
solanaSignerPrivateKey: env.audius_solana_signer_private_key
}
return readConfig()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import express from 'express'
import { json } from 'body-parser'
import cors from 'cors'
import express from 'express'

import { config } from './config'
import { logger } from './logger'
import { errorHandlerMiddleware } from './middleware/errorHandler'
import {
incomingRequestLogger,
outgoingRequestLogger
} from './middleware/logging'
import { relay } from './routes/relay/relay'
import { errorHandlerMiddleware } from './middleware/errorHandler'
import {
userSignerRecoveryMiddleware,
discoveryNodeSignerRecoveryMiddleware,
discoveryNodeSignerRecoveryMiddleware
} from './middleware/signerRecovery'
import { cache } from './routes/cache'
import { feePayer } from './routes/feePayer'
import { health } from './routes/health/health'
import { listen } from './routes/listen/listen'
import { relay } from './routes/relay/relay'

const main = async () => {
const { serverHost, serverPort } = config
Expand All @@ -39,4 +40,4 @@ const main = async () => {
})
}

main().catch(logger.error.bind(logger))
main().catch((e) => logger.error({ error: e }, 'Fatal error in main!'))
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { Request, Response } from 'express'
import { NextFunction, Request, Response } from 'express'

import { InternalServerError, ResponseError } from '../errors'
import { logger as rootLogger } from '../logger'

export const errorHandlerMiddleware = (
err: unknown,
req: Request,
res: Response
_req: Request,
res: Response,
_next: NextFunction
) => {
const error =
err instanceof ResponseError ? err : new InternalServerError(String(err))
if (!res.writableEnded) {
if (!res.headersSent) {
res.status(error.status).send({ error: error.name })
}
// in milliseconds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-namespace */
import { Users } from '@pedalboard/storage'
import { Logger } from 'pino'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NextFunction, Request, Response } from 'express'
import { v4 as uuidv4 } from 'uuid'

import { logger } from '../logger'

export const incomingRequestLogger = (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { NextFunction, Request, Response } from 'express'
import { recoverPersonalSignature } from 'eth-sig-util'
import { Table, Users } from '@pedalboard/storage'
import { initializeDiscoveryDb } from '@pedalboard/basekit'
import { Table, Users } from '@pedalboard/storage'
import { recoverPersonalSignature } from 'eth-sig-util'
import { NextFunction, Request, Response } from 'express'

import { config } from '../config'
import { getCachedDiscoveryNodes } from '../redis'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createClient, RedisClientType } from 'redis'

import { config } from './config'

let redisClient: RedisClientType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { TransactionResponse } from '@solana/web3.js'
import { NextFunction, Request, Response } from 'express'

import { BadRequestError, UnauthorizedError } from '../errors'
import { cacheTransaction } from '../redis'
import { TransactionResponse } from '@solana/web3.js'

type RequestBody = {
transaction: string
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NextFunction, Request, Response } from 'express'

import { config } from '../config'
import { InternalServerError } from '../errors'

Expand Down
Loading

0 comments on commit 01229c6

Please sign in to comment.