Merge remote-tracking branch 'origin/master' into simon/update-pricefeed

This commit is contained in:
wiz 2020-11-23 09:56:23 +09:00
commit 9059c0c7e4
No known key found for this signature in database
GPG Key ID: A394E332255A6173
4 changed files with 33 additions and 15 deletions

View File

@ -81,18 +81,7 @@ class WebsocketHandler {
if (!_blocks) { if (!_blocks) {
return; return;
} }
client.send(JSON.stringify({ client.send(JSON.stringify(this.getInitData(_blocks)));
'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
}));
} }
if (parsedMessage.action === 'ping') { 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) { handleNewStatistic(stats: OptimizedStatistic) {
if (!this.wss) { if (!this.wss) {
throw new Error('WebSocket.Server is not set'); throw new Error('WebSocket.Server is not set');

View File

@ -142,6 +142,7 @@ class Server {
.get(config.MEMPOOL.API_URL_PREFIX + 'fees/recommended', routes.getRecommendedFees) .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 + 'fees/mempool-blocks', routes.getMempoolBlocks)
.get(config.MEMPOOL.API_URL_PREFIX + 'backend-info', routes.getBackendInfo) .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) { if (config.STATISTICS.ENABLED && config.DATABASE.ENABLED) {

View File

@ -6,6 +6,7 @@ import backendInfo from './api/backend-info';
import mempoolBlocks from './api/mempool-blocks'; import mempoolBlocks from './api/mempool-blocks';
import mempool from './api/mempool'; import mempool from './api/mempool';
import bisq from './api/bisq/bisq'; import bisq from './api/bisq/bisq';
import websocketHandler from './api/websocket-handler';
import bisqMarket from './api/bisq/markets-api'; import bisqMarket from './api/bisq/markets-api';
import { OptimizedStatistic, RequiredSpec } from './interfaces'; import { OptimizedStatistic, RequiredSpec } from './interfaces';
import { MarketsApiError } from './api/bisq/interfaces'; import { MarketsApiError } from './api/bisq/interfaces';
@ -63,6 +64,15 @@ class Routes {
res.json(this.cache['1y']); 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) { public async getRecommendedFees(req: Request, res: Response) {
if (!mempool.isInSync()) { if (!mempool.isInSync()) {
res.statusCode = 503; res.statusCode = 503;

View File

@ -14,21 +14,21 @@ source "$NVM_DIR/nvm.sh"
REPO=origin REPO=origin
BRANCH=master BRANCH=master
TAG="${REPO}/${BRANCH}" TAG="${BRANCH}"
[ ! -z "$1" ] && TAG=$1 [ ! -z "$1" ] && TAG=$1
echo "upgrading mempool to ${TAG}" | wall echo "upgrading mempool to ${TAG}" | wall
cd "$HOME/mempool" cd "$HOME/mempool"
git fetch "${REPO}" git fetch "${REPO}"
git reset --hard "${TAG}" git reset --hard "${REPO}/${TAG}"
cd "$HOME/" cd "$HOME/"
for site in mainnet liquid testnet bisq for site in mainnet liquid testnet bisq
do do
cd "$HOME/${site}" cd "$HOME/${site}"
git fetch "${REPO}" git fetch "${REPO}"
git reset --hard "${TAG}" git reset --hard "${REPO}/${TAG}"
hash=$(git rev-parse HEAD) hash=$(git rev-parse HEAD)
if [ "${site}" = "mainnet" ] if [ "${site}" = "mainnet" ]