diff --git a/backend/src/api/mempool-blocks.ts b/backend/src/api/mempool-blocks.ts index a39330d5e..ad32bfc57 100644 --- a/backend/src/api/mempool-blocks.ts +++ b/backend/src/api/mempool-blocks.ts @@ -26,23 +26,23 @@ class MempoolBlocks { private calculateMempoolBlocks(transactionsSorted: TransactionExtended[]): MempoolBlock[] { const mempoolBlocks: MempoolBlock[] = []; - let blockWeight = 0; + let blockVSize = 0; let blockSize = 0; let transactions: TransactionExtended[] = []; transactionsSorted.forEach((tx) => { - if (blockWeight + tx.vsize < 1000000 || mempoolBlocks.length === config.DEFAULT_PROJECTED_BLOCKS_AMOUNT - 1) { - blockWeight += tx.vsize; + if (blockVSize + tx.vsize <= 1000000 || mempoolBlocks.length === config.DEFAULT_PROJECTED_BLOCKS_AMOUNT - 1) { + blockVSize += tx.vsize; blockSize += tx.size; transactions.push(tx); } else { - mempoolBlocks.push(this.dataToMempoolBlocks(transactions, blockSize, blockWeight, mempoolBlocks.length)); - blockWeight = 0; + mempoolBlocks.push(this.dataToMempoolBlocks(transactions, blockSize, blockVSize, mempoolBlocks.length)); + blockVSize = 0; blockSize = 0; transactions = []; } }); if (transactions.length) { - mempoolBlocks.push(this.dataToMempoolBlocks(transactions, blockSize, blockWeight, mempoolBlocks.length)); + mempoolBlocks.push(this.dataToMempoolBlocks(transactions, blockSize, blockVSize, mempoolBlocks.length)); } return mempoolBlocks; } diff --git a/backend/src/api/mempool.ts b/backend/src/api/mempool.ts index b150c9738..abc6a5c46 100644 --- a/backend/src/api/mempool.ts +++ b/backend/src/api/mempool.ts @@ -4,7 +4,7 @@ import { MempoolInfo, TransactionExtended, Transaction } from '../interfaces'; class Mempool { private inSync: boolean = false; - private mempoolCache: any = {}; + private mempoolCache: { [txId: string]: TransactionExtended } = {}; private mempoolInfo: MempoolInfo = { size: 0, bytes: 0 }; private mempoolChangedCallback: Function | undefined; @@ -30,7 +30,7 @@ class Mempool { return this.mempoolCache; } - public setMempool(mempoolData: any) { + public setMempool(mempoolData: { [txId: string]: TransactionExtended }) { this.mempoolCache = mempoolData; if (this.mempoolChangedCallback && mempoolData) { this.mempoolChangedCallback(mempoolData); diff --git a/backend/src/api/websocket-handler.ts b/backend/src/api/websocket-handler.ts index 339e8efd5..1f58b7d20 100644 --- a/backend/src/api/websocket-handler.ts +++ b/backend/src/api/websocket-handler.ts @@ -25,7 +25,7 @@ class WebsocketHandler { } this.wss.on('connection', (client: WebSocket) => { - client.on('message', (message: any) => { + client.on('message', (message: string) => { try { const parsedMessage: WebsocketResponse = JSON.parse(message); const response = {}; diff --git a/backend/src/index.ts b/backend/src/index.ts index ffb23bfaa..ab72d260b 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -1,4 +1,5 @@ const config = require('../mempool-config.json'); +import { Express, Request, Response, NextFunction } from 'express'; import * as fs from 'fs'; import * as express from 'express'; import * as compression from 'compression'; @@ -17,13 +18,13 @@ import fiatConversion from './api/fiat-conversion'; class Server { wss: WebSocket.Server; server: https.Server | http.Server; - app: any; + app: Express; constructor() { this.app = express(); this.app - .use((req, res, next) => { + .use((req: Request, res: Response, next: NextFunction) => { res.setHeader('Access-Control-Allow-Origin', '*'); next(); }) diff --git a/backend/src/routes.ts b/backend/src/routes.ts index 20df6ca87..3240489fe 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -1,3 +1,4 @@ +import { Request, Response } from 'express'; import statistics from './api/statistics'; import feeApi from './api/fee-api'; import backendInfo from './api/backend-info'; @@ -22,60 +23,66 @@ class Routes { console.log('Statistics cache created'); } - public async get2HStatistics(req, res) { + public async get2HStatistics(req: Request, res: Response) { const result = await statistics.$list2H(); res.send(result); } - public get24HStatistics(req, res) { + public get24HStatistics(req: Request, res: Response) { res.send(this.cache['24h']); } - public get1WHStatistics(req, res) { + public get1WHStatistics(req: Request, res: Response) { res.send(this.cache['1w']); } - public get1MStatistics(req, res) { + public get1MStatistics(req: Request, res: Response) { res.send(this.cache['1m']); } - public get3MStatistics(req, res) { + public get3MStatistics(req: Request, res: Response) { res.send(this.cache['3m']); } - public get6MStatistics(req, res) { + public get6MStatistics(req: Request, res: Response) { res.send(this.cache['6m']); } - public get1YStatistics(req, res) { + public get1YStatistics(req: Request, res: Response) { res.send(this.cache['1y']); } - public async getRecommendedFees(req, res) { + public async getRecommendedFees(req: Request, res: Response) { const result = feeApi.getRecommendedFee(); res.send(result); } - public async getMempoolBlocks(req, res) { + public getMempoolBlocks(req: Request, res: Response) { try { - const result = await mempoolBlocks.getMempoolBlocks(); + const result = mempoolBlocks.getMempoolBlocks(); res.send(result); } catch (e) { res.status(500).send(e.message); } } - public getTransactionTimes(req, res) { + public getTransactionTimes(req: Request, res: Response) { if (!Array.isArray(req.query.txId)) { res.status(500).send('Not an array'); return; } - const txIds = req.query.txId; + const txIds: string[] = []; + for (const _txId in req.query.txId) { + if (typeof req.query.txId[_txId] === 'string') { + txIds.push(req.query.txId[_txId].toString()); + } + } + const times = mempool.getFirstSeenForTransactions(txIds); res.send(times); } - public getBackendInfo(req, res) { + public getBackendInfo(req: Request, res: Response) { res.send(backendInfo.getBackendInfo()); } } diff --git a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html index b0d859abf..00828f356 100644 --- a/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html +++ b/frontend/src/app/components/mempool-blocks/mempool-blocks.component.html @@ -9,7 +9,7 @@
{{ projectedBlock.blockSize | bytes: 2 }}
{{ projectedBlock.nTx | number }} transactions
-
+
In < {{ 1 * i + 1 }} minute @@ -17,8 +17,8 @@ In ~{{ 10 * i + 10 }} minutes
- -
+{{ projectedBlock.blockVSize / 1000000 | ceil }} blocks
+ +
({{ projectedBlock.blockVSize / 1000000 | ceil }} blocks)