From 3fa4f96240feb35a59686781dbd99dd5f6261863 Mon Sep 17 00:00:00 2001 From: kenshin-samourai Date: Fri, 8 Jan 2021 16:05:42 +0100 Subject: [PATCH] add new /support/xpub/delete api endpoint --- accounts/support-rest-api.js | 55 ++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/accounts/support-rest-api.js b/accounts/support-rest-api.js index 1e4010c..5bd293d 100644 --- a/accounts/support-rest-api.js +++ b/accounts/support-rest-api.js @@ -69,6 +69,14 @@ class SupportRestApi { HttpServer.sendAuthError ) + this.httpServer.app.get( + `/${keys.prefixes.support}/xpub/:xpub/delete`, + authMgr.checkHasAdminProfile.bind(authMgr), + this.validateArgsGetXpubDelete.bind(this), + this.getXpubDelete.bind(this), + HttpServer.sendAuthError + ) + this.httpServer.app.get( `/${keys.prefixes.support}/pairing/explorer`, authMgr.checkHasAdminProfile.bind(authMgr), @@ -246,6 +254,36 @@ class SupportRestApi { } } + /** + * Delete all data related to a hd account + * @param {object} req - http request object + * @param {object} res - http response object + */ + async getXpubDelete(req, res) { + try { + // Parse the entities passed as url params + const entities = apiHelper.parseEntities(req.params.xpub).xpubs + if (entities.length == 0) + return HttpServer.sendError(res, errors.xpub.INVALID) + + const xpub = entities[0] + + try { + await hdaService.deleteHdAccount(xpub) + HttpServer.sendOk(res) + } catch(e) { + HttpServer.sendError(res, e) + } + + } catch(e) { + HttpServer.sendError(res, errors.generic.GEN) + + } finally { + debugApi && Logger.info(`API : Completed GET /support/xpub/${req.params.xpub}/delete`) + } + } + + /** * Get pairing info */ @@ -329,6 +367,23 @@ class SupportRestApi { } } + /** + * Validate arguments related to GET xpub delete requests + * @param {object} req - http request object + * @param {object} res - http response object + * @param {function} next - next express middleware + */ + validateArgsGetXpubDelete(req, res, next) { + const isValidXpub = validator.isAlphanumeric(req.params.xpub) + + if (!isValidXpub) { + HttpServer.sendError(res, errors.body.INVDATA) + Logger.error(null, `API : SupportRestApi.validateArgsGetXpubDelete() : Invalid xpub ${req.params.xpub}`) + } else { + next() + } + } + /** * Validate arguments related to addresses requests * @param {object} req - http request object