Browse Source

Merge branch 'feat_dojo_status_importer' into 'develop'

add indexer info to /status endpoint

See merge request dojo/samourai-dojo!170
use-env-var-docker
kenshin-samourai 4 years ago
parent
commit
5e520125f1
  1. 38
      accounts/status.js
  2. 5
      lib/remote-importer/oxt-wrapper.js

38
accounts/status.js

@ -4,8 +4,12 @@
*/ */
'use strict' 'use strict'
const network = require('../lib/bitcoin/network')
const keys = require('../keys')[network.key]
const util = require('../lib/util') const util = require('../lib/util')
const Logger = require('../lib/logger')
const db = require('../lib/db/mysql-db-wrapper') 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` const memory = `${util.toMb(process.memoryUsage().rss)} MiB`
// Get highest block processed by the tracker // Get highest block processed by the tracker
const highest = await db.getHighestBlock() let dbMaxHeight = null
const dbMaxHeight = highest.blockHeight 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 { return {
uptime: uptime, uptime: uptime,
@ -43,7 +70,12 @@ class Status {
sessions: this.sessions, sessions: this.sessions,
max: this.maxConn max: this.maxConn
}, },
blocks: dbMaxHeight blocks: dbMaxHeight,
indexer: {
type: indexerType,
url: indexerUrl,
maxHeight: indexerMaxHeight
}
} }
} }

5
lib/remote-importer/oxt-wrapper.js

@ -33,7 +33,10 @@ class OxtWrapper extends Wrapper {
url: `${this.base}${route}`, url: `${this.base}${route}`,
method: 'GET', method: 'GET',
json: true, json: true,
timeout: 15000 timeout: 15000,
headers: {
'User-Agent': 'Dojo'
}
} }
// Sets socks proxy agent if required // Sets socks proxy agent if required

Loading…
Cancel
Save