[accelerator] proxy acceleration api to prod
This commit is contained in:
		
							parent
							
								
									ead7613579
								
							
						
					
					
						commit
						60040c3914
					
				
							
								
								
									
										63
									
								
								backend/src/api/acceleration/acceleration.routes.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								backend/src/api/acceleration/acceleration.routes.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,63 @@ | ||||
| import { Application, Request, Response } from "express"; | ||||
| import config from "../../config"; | ||||
| import axios from "axios"; | ||||
| import logger from "../../logger"; | ||||
| 
 | ||||
| class AccelerationRoutes { | ||||
|   private tag = 'Accelerator'; | ||||
| 
 | ||||
|   public initRoutes(app: Application) { | ||||
|     app | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'services/accelerator/accelerations', this.$getAcceleratorAccelerations.bind(this)) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'services/accelerator/accelerations/history', this.$getAcceleratorAccelerationsHistory.bind(this)) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'services/accelerator/accelerations/history/aggregated', this.$getAcceleratorAccelerationsHistoryAggregated.bind(this)) | ||||
|       .get(config.MEMPOOL.API_URL_PREFIX + 'services/accelerator/accelerations/stats', this.$getAcceleratorAccelerationsStats.bind(this)) | ||||
|     ; | ||||
|   } | ||||
| 
 | ||||
|   private async $getAcceleratorAccelerations(req: Request, res: Response) { | ||||
|     const url = `https://mempool.space${req.originalUrl}`; | ||||
|     try { | ||||
|       const response = await axios.get(url, { responseType: 'stream', timeout: 10000 }); | ||||
|       response.data.pipe(res); | ||||
|     } catch (e) { | ||||
|       logger.err(`Unable to get current accelerations from ${url} in $getAcceleratorAccelerations(), ${e}`, this.tag); | ||||
|       res.status(500).end(); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   private async $getAcceleratorAccelerationsHistory(req: Request, res: Response) { | ||||
|     const url = `https://mempool.space${req.originalUrl}`; | ||||
|     try { | ||||
|       const response = await axios.get(url, { responseType: 'stream', timeout: 10000 }); | ||||
|       response.data.pipe(res); | ||||
|     } catch (e) { | ||||
|       logger.err(`Unable to get acceleration history from ${url} in $getAcceleratorAccelerationsHistory(), ${e}`, this.tag); | ||||
|       res.status(500).end(); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   private async $getAcceleratorAccelerationsHistoryAggregated(req: Request, res: Response) { | ||||
|     const url = `https://mempool.space${req.originalUrl}`; | ||||
|     try { | ||||
|       const response = await axios.get(url, { responseType: 'stream', timeout: 10000 }); | ||||
|       response.data.pipe(res); | ||||
|     } catch (e) { | ||||
|       logger.err(`Unable to get aggregated acceleration history from ${url} in $getAcceleratorAccelerationsHistoryAggregated(), ${e}`, this.tag); | ||||
|       res.status(500).end(); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   private async $getAcceleratorAccelerationsStats(req: Request, res: Response) { | ||||
|     const url = `https://mempool.space${req.originalUrl}`; | ||||
|     try { | ||||
|       const response = await axios.get(url, { responseType: 'stream', timeout: 10000 }); | ||||
|       response.data.pipe(res); | ||||
|     } catch (e) { | ||||
|       logger.err(`Unable to get acceleration stats from ${url} in $getAcceleratorAccelerationsStats(), ${e}`, this.tag); | ||||
|       res.status(500).end(); | ||||
|     } | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| export default new AccelerationRoutes(); | ||||
| @ -1,6 +1,6 @@ | ||||
| import logger from '../logger'; | ||||
| import { MempoolTransactionExtended } from '../mempool.interfaces'; | ||||
| import { IEsploraApi } from './bitcoin/esplora-api.interface'; | ||||
| import logger from '../../logger'; | ||||
| import { MempoolTransactionExtended } from '../../mempool.interfaces'; | ||||
| import { IEsploraApi } from '../bitcoin/esplora-api.interface'; | ||||
| 
 | ||||
| const BLOCK_WEIGHT_UNITS = 4_000_000; | ||||
| const BLOCK_SIGOPS = 80_000; | ||||
| @ -43,6 +43,7 @@ import redisCache from './api/redis-cache'; | ||||
| import accelerationApi from './api/services/acceleration'; | ||||
| import bitcoinCoreRoutes from './api/bitcoin/bitcoin-core.routes'; | ||||
| import bitcoinSecondClient from './api/bitcoin/bitcoin-second-client'; | ||||
| import accelerationRoutes from './api/acceleration/acceleration.routes'; | ||||
| 
 | ||||
| class Server { | ||||
|   private wss: WebSocket.Server | undefined; | ||||
| @ -305,6 +306,9 @@ class Server { | ||||
|       nodesRoutes.initRoutes(this.app); | ||||
|       channelsRoutes.initRoutes(this.app); | ||||
|     } | ||||
|     if (config.MEMPOOL_SERVICES.ACCELERATIONS) { | ||||
|       accelerationRoutes.initRoutes(this.app); | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|   healthCheck(): void { | ||||
|  | ||||
| @ -1,4 +1,4 @@ | ||||
| import { AccelerationInfo, makeBlockTemplate } from '../api/acceleration'; | ||||
| import { AccelerationInfo, makeBlockTemplate } from '../api/acceleration/acceleration'; | ||||
| import { RowDataPacket } from 'mysql2'; | ||||
| import DB from '../database'; | ||||
| import logger from '../logger'; | ||||
| @ -7,7 +7,7 @@ import { Common } from '../api/common'; | ||||
| import config from '../config'; | ||||
| import blocks from '../api/blocks'; | ||||
| import accelerationApi, { Acceleration } from '../api/services/acceleration'; | ||||
| import accelerationCosts from '../api/acceleration'; | ||||
| import accelerationCosts from '../api/acceleration/acceleration'; | ||||
| import bitcoinApi from '../api/bitcoin/bitcoin-api-factory'; | ||||
| import transactionUtils from '../api/transaction-utils'; | ||||
| import { BlockExtended, MempoolTransactionExtended } from '../mempool.interfaces'; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user