From f13fc5660c6ba054f89f5eb042908fca71a703b5 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Fri, 20 Mar 2015 16:46:33 -0300 Subject: [PATCH 1/5] change tests --- test/integration/server.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/test/integration/server.js b/test/integration/server.js index 433615f..e85dfb8 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -2347,34 +2347,42 @@ describe('Copay server', function() { }); it('should get various paginated tx history', function(done) { var testCases = [{ + opts: {}, + expected: [50, 40, 30, 20, 10], + }, { opts: { - minTs: 15, - maxTs: 45, + skip: 1, + limit: 3, }, expected: [40, 30, 20], }, { opts: { - minTs: 15, - maxTs: 45, + skip: 1, limit: 2, }, expected: [40, 30], }, { opts: { - maxTs: 35, + skip: 2, }, expected: [30, 20, 10], }, { opts: { - minTs: 15, + limit: 4, }, expected: [50, 40, 30, 20], }, { opts: { - minTs: 15, + skip: 0, limit: 3, }, expected: [50, 40, 30], + }, { + opts: { + skip: 0, + limit: 0, + }, + expected: [], }]; server._normalizeTxHistory = sinon.stub().returnsArg(0); From 330c399c07bfd334db415526c6c667a11c945991 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Fri, 20 Mar 2015 16:58:54 -0300 Subject: [PATCH 2/5] implement pagination using skip & limit --- lib/server.js | 18 +++++++----------- test/integration/server.js | 12 ++++++++++++ 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/server.js b/lib/server.js index 6aa9293..eb081e3 100644 --- a/lib/server.js +++ b/lib/server.js @@ -913,12 +913,11 @@ WalletService.prototype._normalizeTxHistory = function(txs) { }; /** - * Retrieves all transactions (incoming & outgoing) in the range (maxTs-minTs) + * Retrieves all transactions (incoming & outgoing) * Times are in UNIX EPOCH * * @param {Object} opts - * @param {Number} opts.minTs (defaults to 0) - * @param {Number} opts.maxTs (defaults to now) + * @param {Number} opts.skip (defaults to 0) * @param {Number} opts.limit * @returns {TxProposal[]} Transaction proposals, first newer */ @@ -1003,17 +1002,14 @@ WalletService.prototype.getTxHistory = function(opts, cb) { }; function paginate(txs) { - var limited = opts.limit && opts.limit != -1; - var minTs = opts.minTs || 0; - var maxTs = opts.maxTs || Math.ceil(Date.now() / 1000); + var skip = opts.skip || 0; + var limited = _.isNumber(opts.limit) && opts.limit != -1; - var filtered = _.sortBy(_.filter(txs, function(tx) { - return tx.time >= minTs && tx.time <= maxTs; - }), function(tx) { + var sliced = _.slice(_.sortBy(txs, function(tx) { return -tx.time; - }); + }), skip); - return limited ? _.take(filtered, opts.limit) : filtered; + return limited ? _.take(sliced, opts.limit) : sliced; }; // Get addresses for this wallet diff --git a/test/integration/server.js b/test/integration/server.js index e85dfb8..ef7369d 100644 --- a/test/integration/server.js +++ b/test/integration/server.js @@ -2383,6 +2383,18 @@ describe('Copay server', function() { limit: 0, }, expected: [], + }, { + opts: { + skip: 4, + limit: 20, + }, + expected: [10], + }, { + opts: { + skip: 20, + limit: 1, + }, + expected: [], }]; server._normalizeTxHistory = sinon.stub().returnsArg(0); From 916a2a8ea725d7605660b9f18c0d374c50557ac4 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Fri, 20 Mar 2015 17:02:59 -0300 Subject: [PATCH 3/5] update readme --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a73c312..678a810 100644 --- a/README.md +++ b/README.md @@ -46,11 +46,19 @@ Returns: * Wallet object. (see [fields on the source code](https://github.com/bitpay/bitcore-wallet-service/blob/master/lib/model/wallet.js)). `/v1/txhistory/`: Get Wallet's transaction history - + + Optional Arguments: + * skip: Records to skip from the result (defaults to 0) + * limit: Total number of records to return (return all available records if not sepcified) Returns: - * History of incomming and outgoing transactions of the wallet. The list is returned complete (Pagination and filter are [ToDos](https://github.com/bitpay/bitcore-wallet-service/issues/121)) + * History of incomming and outgoing transactions of the wallet. The list is paginated using the `skip` & `limit` params. Each item has the following fields: -https://github.com/bitpay/bitcore-wallet-service/issues/121 + * action ('sent', 'received', 'moved') + * amount + * fees + * time + * addressTo + * confirmations * proposalId * creatorName * message From 7b1b4d74d5eda86578885a557da44687ed83df01 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Fri, 20 Mar 2015 17:03:05 -0300 Subject: [PATCH 4/5] v0.0.11 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3e14898..d9bd122 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "bitcore-wallet-service", "description": "A service for Mutisig HD Bitcoin Wallets", "author": "BitPay Inc", - "version": "0.0.10", + "version": "0.0.11", "keywords": [ "bitcoin", "copay", From 04941fed1e0fe6e5a2536a0ad92e239f02e0cf1e Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Fri, 20 Mar 2015 17:04:06 -0300 Subject: [PATCH 5/5] fix readme --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 678a810..219048b 100644 --- a/README.md +++ b/README.md @@ -47,22 +47,22 @@ Returns: `/v1/txhistory/`: Get Wallet's transaction history - Optional Arguments: +Optional Arguments: * skip: Records to skip from the result (defaults to 0) - * limit: Total number of records to return (return all available records if not sepcified) + * limit: Total number of records to return (return all available records if not specified). + Returns: - * History of incomming and outgoing transactions of the wallet. The list is paginated using the `skip` & `limit` params. -Each item has the following fields: - * action ('sent', 'received', 'moved') - * amount - * fees - * time - * addressTo - * confirmations - * proposalId - * creatorName - * message - * actions array ['createdOn', 'type', 'copayerId', 'copayerName', 'comment'] + * History of incomming and outgoing transactions of the wallet. The list is paginated using the `skip` & `limit` params. Each item has the following fields: + * action ('sent', 'received', 'moved') + * amount + * fees + * time + * addressTo + * confirmations + * proposalId + * creatorName + * message + * actions array ['createdOn', 'type', 'copayerId', 'copayerName', 'comment'] `/v1/txproposals/`: Get Wallet's pending transaction proposals and their status