-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from Samourai-Wallet/feat_blocks_rescan
add support of blocks rescans in the maintenance tool
- Loading branch information
Showing
12 changed files
with
178 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,7 @@ services: | |
expose: | ||
- "8080" | ||
- "8081" | ||
- "8082" | ||
volumes: | ||
- data-nodejs:/data | ||
depends_on: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/*! | ||
* tracker/tracker-rest-api.js | ||
* Copyright (c) 2016-2019, Samourai Wallet (CC BY-NC-ND 4.0 License). | ||
*/ | ||
'use strict' | ||
|
||
const qs = require('querystring') | ||
const validator = require('validator') | ||
const bodyParser = require('body-parser') | ||
const Logger = require('../lib/logger') | ||
const errors = require('../lib/errors') | ||
const authMgr = require('../lib/auth/authorizations-manager') | ||
const HttpServer = require('../lib/http-server/http-server') | ||
const network = require('../lib/bitcoin/network') | ||
const keys = require('../keys')[network.key] | ||
|
||
|
||
/** | ||
* Tracker API endpoints | ||
*/ | ||
class TrackerRestApi { | ||
|
||
/** | ||
* Constructor | ||
* @param {pushtx.HttpServer} httpServer - HTTP server | ||
* @param {tracker.Tracker} tracker - tracker | ||
*/ | ||
constructor(httpServer, tracker) { | ||
this.httpServer = httpServer | ||
this.tracker = tracker | ||
|
||
const urlencodedParser = bodyParser.urlencoded({ extended: true }) | ||
|
||
// Establish routes. Proxy server strips /pushtx | ||
this.httpServer.app.get( | ||
`/${keys.prefixes.support}/rescan`, | ||
authMgr.checkHasAdminProfile.bind(authMgr), | ||
this.getBlocksRescan.bind(this), | ||
HttpServer.sendAuthError | ||
) | ||
} | ||
|
||
/** | ||
* Rescan a range of blocks | ||
*/ | ||
async getBlocksRescan(req, res) { | ||
// Check request arguments | ||
if (!req.query) | ||
return HttpServer.sendError(res, errors.body.INVDATA) | ||
|
||
if (!req.query.fromHeight || !validator.isInt(req.query.fromHeight)) | ||
return HttpServer.sendError(res, errors.body.INVDATA) | ||
|
||
if (req.query.toHeight && !validator.isInt(req.query.toHeight)) | ||
return HttpServer.sendError(res, errors.body.INVDATA) | ||
|
||
// Retrieve the request arguments | ||
const fromHeight = parseInt(req.query.fromHeight) | ||
const toHeight = req.query.toHeight ? parseInt(req.query.toHeight) : fromHeight | ||
|
||
if (req.query.toHeight && (toHeight < fromHeight)) | ||
return HttpServer.sendError(res, errors.body.INVDATA) | ||
|
||
try { | ||
await this.tracker.blockchainProcessor.rescanBlocks(fromHeight, toHeight) | ||
const ret = { | ||
status: 'Rescan complete', | ||
fromHeight: fromHeight, | ||
toHeight: toHeight | ||
} | ||
HttpServer.sendRawData(res, JSON.stringify(ret, null, 2)) | ||
} catch(e) { | ||
return HttpServer.sendError(res, e) | ||
} | ||
} | ||
|
||
} | ||
|
||
module.exports = TrackerRestApi |