diff --git a/backend/src/api/websocket-handler.ts b/backend/src/api/websocket-handler.ts index e6401f508..b7f8b167e 100644 --- a/backend/src/api/websocket-handler.ts +++ b/backend/src/api/websocket-handler.ts @@ -81,18 +81,7 @@ class WebsocketHandler { if (!_blocks) { return; } - client.send(JSON.stringify({ - 'mempoolInfo': memPool.getMempoolInfo(), - 'vBytesPerSecond': memPool.getVBytesPerSecond(), - 'lastDifficultyAdjustment': blocks.getLastDifficultyAdjustmentTime(), - 'blocks': _blocks, - 'conversions': fiatConversion.getConversionRates(), - 'mempool-blocks': mempoolBlocks.getMempoolBlocks(), - 'transactions': memPool.getLatestTransactions(), - 'git-commit': backendInfo.gitCommitHash, - 'hostname': backendInfo.hostname, - ...this.extraInitProperties - })); + client.send(JSON.stringify(this.getInitData(_blocks))); } if (parsedMessage.action === 'ping') { @@ -128,6 +117,24 @@ class WebsocketHandler { }); } + getInitData(_blocks?: Block[]) { + if (!_blocks) { + _blocks = blocks.getBlocks(); + } + return { + 'mempoolInfo': memPool.getMempoolInfo(), + 'vBytesPerSecond': memPool.getVBytesPerSecond(), + 'lastDifficultyAdjustment': blocks.getLastDifficultyAdjustmentTime(), + 'blocks': _blocks, + 'conversions': fiatConversion.getTickers()['BTCUSD'], + 'mempool-blocks': mempoolBlocks.getMempoolBlocks(), + 'transactions': memPool.getLatestTransactions(), + 'git-commit': backendInfo.gitCommitHash, + 'hostname': backendInfo.hostname, + ...this.extraInitProperties + }; + } + handleNewStatistic(stats: OptimizedStatistic) { if (!this.wss) { throw new Error('WebSocket.Server is not set'); diff --git a/backend/src/index.ts b/backend/src/index.ts index f7591ecf6..ab50afc36 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -142,6 +142,7 @@ class Server { .get(config.MEMPOOL.API_URL_PREFIX + 'fees/recommended', routes.getRecommendedFees) .get(config.MEMPOOL.API_URL_PREFIX + 'fees/mempool-blocks', routes.getMempoolBlocks) .get(config.MEMPOOL.API_URL_PREFIX + 'backend-info', routes.getBackendInfo) + .get(config.MEMPOOL.API_URL_PREFIX + 'init-data', routes.getInitData) ; if (config.STATISTICS.ENABLED && config.DATABASE.ENABLED) { diff --git a/backend/src/routes.ts b/backend/src/routes.ts index 57ffe960c..3d60f7df2 100644 --- a/backend/src/routes.ts +++ b/backend/src/routes.ts @@ -6,6 +6,7 @@ import backendInfo from './api/backend-info'; import mempoolBlocks from './api/mempool-blocks'; import mempool from './api/mempool'; import bisq from './api/bisq/bisq'; +import websocketHandler from './api/websocket-handler'; import bisqMarket from './api/bisq/markets-api'; import { OptimizedStatistic, RequiredSpec } from './interfaces'; import { MarketsApiError } from './api/bisq/interfaces'; @@ -63,6 +64,15 @@ class Routes { res.json(this.cache['1y']); } + public getInitData(req: Request, res: Response) { + try { + const result = websocketHandler.getInitData(); + res.json(result); + } catch (e) { + res.status(500).send(e.message); + } + } + public async getRecommendedFees(req: Request, res: Response) { if (!mempool.isInSync()) { res.statusCode = 503; diff --git a/production/mempool-upgrade-all b/production/mempool-upgrade-all index 029ff7d79..b8fdac452 100755 --- a/production/mempool-upgrade-all +++ b/production/mempool-upgrade-all @@ -14,21 +14,21 @@ source "$NVM_DIR/nvm.sh" REPO=origin BRANCH=master -TAG="${REPO}/${BRANCH}" +TAG="${BRANCH}" [ ! -z "$1" ] && TAG=$1 echo "upgrading mempool to ${TAG}" | wall cd "$HOME/mempool" git fetch "${REPO}" -git reset --hard "${TAG}" +git reset --hard "${REPO}/${TAG}" cd "$HOME/" for site in mainnet liquid testnet bisq do cd "$HOME/${site}" git fetch "${REPO}" - git reset --hard "${TAG}" + git reset --hard "${REPO}/${TAG}" hash=$(git rev-parse HEAD) if [ "${site}" = "mainnet" ]