From da6e61b7e7146a3708bd4643e3c26332efe15214 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 18 May 2017 11:28:23 -0300 Subject: [PATCH] add REST endpoint --- lib/expressapp.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/expressapp.js b/lib/expressapp.js index aded96e..626847a 100644 --- a/lib/expressapp.js +++ b/lib/expressapp.js @@ -57,7 +57,7 @@ ExpressApp.prototype.start = function(opts, cb) { // handle `abort` https://nodejs.org/api/http.html#http_event_abort - this.app.use(function (req, res, next) { + this.app.use(function(req, res, next) { req.on('abort', function() { log.warn('Request aborted by the client'); }); @@ -711,6 +711,28 @@ ExpressApp.prototype.start = function(opts, cb) { }); }); + + router.post('/v1/txconfirmations/', function(req, res) { + getServerWithAuth(req, res, function(server) { + server.txConfirmationSubscribe(req.body, function(err, response) { + if (err) return returnError(err, res, req); + res.json(response); + }); + }); + }); + + router.delete('/v1/txconfirmations/:txid', function(req, res) { + var opts = { + txid: req.params['txid'], + }; + getServerWithAuth(req, res, function(server) { + server.txConfirmationUnsubscribe(opts, function(err, response) { + if (err) return returnError(err, res, req); + res.json(response); + }); + }); + }); + this.app.use(opts.basePath || '/bws/api', router); WalletService.initialize(opts, cb);