From 60b7daae88ea7823ca0c6421f7aacf280d12109c Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Thu, 18 May 2017 11:52:36 -0300 Subject: [PATCH 1/3] add endpoint for tx confirmations notifications --- lib/api.js | 29 +++++++++++++++++++++++++---- test/client.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/lib/api.js b/lib/api.js index 6e1f64c5..717a97f7 100644 --- a/lib/api.js +++ b/lib/api.js @@ -2375,7 +2375,7 @@ API.prototype.getFiatRate = function(opts, cb) { } /** - * Returns subscription status. + * Subscribe to push notifications. * @param {Object} opts * @param {String} opts.type - Device type (ios or android). * @param {String} opts.token - Device token. @@ -2390,18 +2390,39 @@ API.prototype.pushNotificationsSubscribe = function(opts, cb) { }; /** - * Returns unsubscription status. + * Unsubscribe from push notifications. * @param {String} token - Device token * @return {Callback} cb - Return error if exists */ API.prototype.pushNotificationsUnsubscribe = function(token, cb) { var url = '/v2/pushnotifications/subscriptions/' + token; - this._doDeleteRequest(url, function(err) { + this._doDeleteRequest(url, cb); +}; + +/** + * Listen to a tx for its first confirmation. + * @param {Object} opts + * @param {String} opts.txid - The txid to subscribe to. + * @returns {Object} response - Status of subscription. + */ +API.prototype.txConfirmationSubscribe = function(opts, cb) { + var url = '/v1/txconfirmations/'; + this._doPostRequest(url, opts, function(err, response) { if (err) return cb(err); - return cb(null); + return cb(null, response); }); }; +/** + * Stop listening for a tx confirmation. + * @param {String} txid - The txid to unsubscribe from. + * @return {Callback} cb - Return error if exists + */ +API.prototype.txConfirmationUnsubscribe = function(txid, cb) { + var url = '/v2/txconfirmations/' + txid; + this._doDeleteRequest(url, cb); +}; + /** * Returns send max information. * @param {String} opts diff --git a/test/client.js b/test/client.js index 90477c95..7f0af40f 100644 --- a/test/client.js +++ b/test/client.js @@ -1648,6 +1648,34 @@ describe('client API', function() { }); }); + describe('Tx confirmations', function() { + it('should do a post request', function(done) { + helpers.createAndJoinWallet(clients, 1, 1, function() { + clients[0]._doRequest = sinon.stub().yields(null, { + statusCode: 200, + }); + clients[0].txConfirmationSubscribe({ + txid: '123' + }, function(err, res) { + should.not.exist(err); + should.exist(res); + res.statusCode.should.be.equal(200); + done(); + }); + }); + }); + + it('should do a delete request', function(done) { + helpers.createAndJoinWallet(clients, 1, 1, function() { + clients[0]._doRequest = sinon.stub().yields(null); + clients[0].txConfirmationUnsubscribe('123', function(err) { + should.not.exist(err); + done(); + }); + }); + }); + }); + describe('Get send max information', function() { var balance; beforeEach(function(done) { From 331499a514b8dc5abdbd84447f618db1eb12adec Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 22 May 2017 11:16:15 -0300 Subject: [PATCH 2/3] fix api version --- lib/api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/api.js b/lib/api.js index 717a97f7..2431913f 100644 --- a/lib/api.js +++ b/lib/api.js @@ -2419,7 +2419,7 @@ API.prototype.txConfirmationSubscribe = function(opts, cb) { * @return {Callback} cb - Return error if exists */ API.prototype.txConfirmationUnsubscribe = function(txid, cb) { - var url = '/v2/txconfirmations/' + txid; + var url = '/v1/txconfirmations/' + txid; this._doDeleteRequest(url, cb); }; From c9fa1418a1f4aa6bce9e9c4a1a55bc4e1bcb6e15 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Wed, 24 May 2017 15:11:24 -0300 Subject: [PATCH 3/3] bump bws + v5.2.0 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 6bb24c10..0115d3a5 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "bitcore-wallet-client", "description": "Client for bitcore-wallet-service", "author": "BitPay Inc", - "version": "5.1.2", + "version": "5.2.0", "license": "MIT", "keywords": [ "bitcoin", @@ -36,7 +36,7 @@ "superagent": "^3.4.1" }, "devDependencies": { - "bitcore-wallet-service": "~1.15.0", + "bitcore-wallet-service": "~1.17.0", "browserify": "^13.1.0", "chai": "^1.9.1", "coveralls": "^2.11.2",