diff --git a/accounts/status.js b/accounts/status.js index 5c5fffa..f07e0b0 100644 --- a/accounts/status.js +++ b/accounts/status.js @@ -4,8 +4,12 @@ */ 'use strict' +const network = require('../lib/bitcoin/network') +const keys = require('../keys')[network.key] const util = require('../lib/util') +const Logger = require('../lib/logger') const db = require('../lib/db/mysql-db-wrapper') +const remote = require('../lib/remote-importer/remote-importer') /** @@ -32,8 +36,31 @@ class Status { const memory = `${util.toMb(process.memoryUsage().rss)} MiB` // Get highest block processed by the tracker - const highest = await db.getHighestBlock() - const dbMaxHeight = highest.blockHeight + let dbMaxHeight = null + try { + const highest = await db.getHighestBlock() + dbMaxHeight = highest.blockHeight + } catch(e) { + Logger.error(e, 'API : Status.getCurrent() :') + } + + // Get info about the indexer + const indexerType = keys.indexer.active + let indexerMaxHeight = null + let indexerUrl = null + + if (indexerType == 'third_party_explorer') { + indexerUrl = (network.key == 'bitcoin') + ? keys.indexer.oxt + : keys.indexer.esplora + } + + try { + const chaintip = await remote.getChainTipHeight() + indexerMaxHeight = chaintip['chainTipHeight'] + } catch(e) { + Logger.error(e, 'API : Status.getCurrent() :') + } return { uptime: uptime, @@ -43,7 +70,12 @@ class Status { sessions: this.sessions, max: this.maxConn }, - blocks: dbMaxHeight + blocks: dbMaxHeight, + indexer: { + type: indexerType, + url: indexerUrl, + maxHeight: indexerMaxHeight + } } } diff --git a/lib/remote-importer/oxt-wrapper.js b/lib/remote-importer/oxt-wrapper.js index 894e59d..291f3b6 100644 --- a/lib/remote-importer/oxt-wrapper.js +++ b/lib/remote-importer/oxt-wrapper.js @@ -33,7 +33,10 @@ class OxtWrapper extends Wrapper { url: `${this.base}${route}`, method: 'GET', json: true, - timeout: 15000 + timeout: 15000, + headers: { + 'User-Agent': 'Dojo' + } } // Sets socks proxy agent if required