Browse Source

Merge branch 'feat_dojo_xpub_import_status' into 'develop'

add new /xpub/import/status endpoint

See merge request dojo/samourai-dojo!154
use-env-var-docker
kenshin-samourai 4 years ago
parent
commit
ae0993b0ac
  1. 43
      accounts/xpub-rest-api.js
  2. 37
      doc/GET_xpub_import_status.md
  3. 10
      lib/bitcoin/hd-accounts-service.js
  4. 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

37
doc/GET_xpub_import_status.md

@ -0,0 +1,37 @@
# Get import status for a HD Account
Check if an import or a rescan is currently processed by Dojo for a given HD Account.
```
GET /xpub/:xpub/import/status
```
## Parameters
* **:xpub** - `string` - The extended public key for the HD Account
* **at** - `string` (optional) - Access Token (json web token). Required if authentication is activated. Alternatively, the access token can be passed through the `Authorization` HTTP header (with the `Bearer` scheme).
### Example
```
GET /xpub/xpub0123456789/import/status
```
#### Success
Status code 200 with JSON response:
```json
{
"status": "ok",
"data": {
"import_in_progress": false
}
}
```
#### Failure
Status code 400 with JSON response:
```json
{
"status": "error",
"error": "<error message>"
}
```

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