Browse Source

add new /xpub/import/status endpoint

use-env-var-docker
kenshin-samourai 5 years ago
parent
commit
824662b724
  1. 43
      accounts/xpub-rest-api.js
  2. 10
      lib/bitcoin/hd-accounts-service.js
  3. 10
      lib/remote-importer/remote-importer.js

43
accounts/xpub-rest-api.js

@ -48,6 +48,14 @@ class XPubRestApi {
HttpServer.sendAuthError
)
this.httpServer.app.get(
'/xpub/:xpub/import/status',
authMgr.checkAuthentication.bind(authMgr),
this.validateArgsGetXpub.bind(this),
this.getXpubImportStatus.bind(this),
HttpServer.sendAuthError
)
this.httpServer.app.get(
'/xpub/:xpub',
authMgr.checkAuthentication.bind(authMgr),
@ -202,6 +210,41 @@ class XPubRestApi {
}
}
/**
* Handle xPub/import/status GET request
* @param {object} req - http request object
* @param {object} res - http response object
*/
async getXpubImportStatus(req, res) {
try {
let xpub
// Extracts arguments
const argXpub = req.params.xpub
// Translate xpub if needed
try {
const xlatXpub = this.xlatHdAccount(argXpub)
xpub = xlatXpub.xpub
} catch(e) {
return HttpServer.sendError(res, e)
}
const ret = {
import_in_progress: hdaService.importInProgress(xpub)
}
HttpServer.sendOkData(res, ret)
} catch(e) {
Logger.error(e, 'API : XpubRestApi.getXpubImportStatus()')
HttpServer.sendError(res, e)
} finally {
debugApi && Logger.info(`API : Completed GET /xpub/${req.params.xpub}/import/status`)
}
}
/**
* Handle Lock XPub POST request
* @param {object} req - http request object

10
lib/bitcoin/hd-accounts-service.js

@ -171,6 +171,16 @@ class HDAccountsService {
}
}
/**
* Check if a xpub is currently being imported or rescanned by Dojo
* Returns true if import/rescan is in progress, otherwise returns false
* @param {string} xpub - xpub
* @returns {Promise}
*/
importInProgress(xpub) {
return remote.importInProgress(xpub)
}
/**
* Check if we try to override an existing xpub
* Delete the old xpub from db if it's the case

10
lib/remote-importer/remote-importer.js

@ -48,6 +48,16 @@ class RemoteImporter {
delete this.importing[xpub]
}
/**
* Check if a xpub is currently being imported or rescanned by Dojo
* Returns true if import/rescan is in progress, otherwise returns false
* @param {string} xpub - xpub
* @returns {boolean}
*/
importInProgress(xpub) {
return this.importing[xpub] ? true : false
}
/**
* Process the relations between a list of transactions
* @param {object[]} txs - array of transaction objects

Loading…
Cancel
Save