Merge pull request #365 from pnagurny/enhance/history-pagination
address history pagination
This commit is contained in:
commit
83c8f9c5ac
@ -48,12 +48,12 @@ AddressController.prototype.addressHistorySubQuery = function(req, res, param) {
|
|||||||
AddressController.prototype.getAddressHistory = function(address, callback) {
|
AddressController.prototype.getAddressHistory = function(address, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.node.getAddressHistory(address, true, function(err, txinfos) {
|
this.node.getAddressHistory(address, {}, function(err, result) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback(null, self.transformAddressHistory(txinfos, address));
|
callback(null, self.transformAddressHistory(result.items, address));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -184,12 +184,23 @@ AddressController.prototype.transformUtxo = function(utxo) {
|
|||||||
AddressController.prototype.multitxs = function(req, res, next) {
|
AddressController.prototype.multitxs = function(req, res, next) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.node.getAddressHistory(req.addrs, true, function(err, txinfos) {
|
var options = {
|
||||||
|
from: req.query.from || req.body.from || 0
|
||||||
|
};
|
||||||
|
|
||||||
|
options.to = req.query.to || req.body.to || options.from + 10;
|
||||||
|
|
||||||
|
self.node.getAddressHistory(req.addrs, options, function(err, result) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return common.handleErrors(err, res);
|
return common.handleErrors(err, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.jsonp(self.transformAddressHistoryForMultiTxs(txinfos));
|
res.jsonp({
|
||||||
|
totalItems: result.totalCount,
|
||||||
|
from: options.from,
|
||||||
|
to: Math.min(options.to, result.totalCount),
|
||||||
|
items: self.transformAddressHistoryForMultiTxs(result.items)
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -202,16 +213,9 @@ AddressController.prototype.transformAddressHistoryForMultiTxs = function(txinfo
|
|||||||
return self.indexOf(value) === index;
|
return self.indexOf(value) === index;
|
||||||
}).map(function(tx) {
|
}).map(function(tx) {
|
||||||
return self.txController.transformTransaction(tx);
|
return self.txController.transformTransaction(tx);
|
||||||
}).reverse();
|
});
|
||||||
|
|
||||||
var transformed = {
|
return items;
|
||||||
totalItems: items.length,
|
|
||||||
from: 0,
|
|
||||||
to: items.length,
|
|
||||||
items: items
|
|
||||||
};
|
|
||||||
|
|
||||||
return transformed;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -190,7 +190,7 @@ TxController.prototype.list = function(req, res) {
|
|||||||
|
|
||||||
var blockHash = req.query.block;
|
var blockHash = req.query.block;
|
||||||
var address = req.query.address;
|
var address = req.query.address;
|
||||||
var page = req.query.pageNum;
|
var page = parseInt(req.query.pageNum) || 0;
|
||||||
var pageLength = 10;
|
var pageLength = 10;
|
||||||
var pagesTotal = 1;
|
var pagesTotal = 1;
|
||||||
|
|
||||||
@ -235,28 +235,27 @@ TxController.prototype.list = function(req, res) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else if(address) {
|
} else if(address) {
|
||||||
self.node.getAddressHistory(address, true, function(err, txinfos) {
|
var options = {
|
||||||
|
from: page * pageLength,
|
||||||
|
to: (page + 1) * pageLength
|
||||||
|
};
|
||||||
|
|
||||||
|
self.node.getAddressHistory(address, options, function(err, result) {
|
||||||
if(err) {
|
if(err) {
|
||||||
return common.handleErrors(err, res);
|
return common.handleErrors(err, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
var txs = txinfos.map(function(info) {
|
var txs = result.items.map(function(info) {
|
||||||
return info.tx;
|
return info.tx;
|
||||||
}).filter(function(value, index, self) {
|
}).filter(function(value, index, self) {
|
||||||
return self.indexOf(value) === index;
|
return self.indexOf(value) === index;
|
||||||
});
|
});
|
||||||
|
|
||||||
var totalTxs = txs.length;
|
|
||||||
|
|
||||||
if(page) {
|
|
||||||
txs = txs.splice(page * pageLength, pageLength);
|
|
||||||
pagesTotal = Math.ceil(totalTxs / pageLength);
|
|
||||||
}
|
|
||||||
|
|
||||||
var transformed = txs.map(self.transformTransaction.bind(self));
|
var transformed = txs.map(self.transformTransaction.bind(self));
|
||||||
|
|
||||||
res.jsonp({
|
res.jsonp({
|
||||||
pagesTotal: pagesTotal,
|
pagesTotal: Math.ceil(result.totalCount / pageLength),
|
||||||
txs: transformed
|
txs: transformed
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -5,88 +5,91 @@ var AddressController = require('../lib/addresses');
|
|||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var bitcore = require('bitcore');
|
var bitcore = require('bitcore');
|
||||||
|
|
||||||
var txinfos = [
|
var txinfos = {
|
||||||
{
|
totalCount: 2,
|
||||||
"address": "mkPvAKZ2rar6qeG3KjBtJHHMSP1wFZH7Er",
|
items: [
|
||||||
"satoshis": 2782729129,
|
{
|
||||||
"height": 534105,
|
"address": "mkPvAKZ2rar6qeG3KjBtJHHMSP1wFZH7Er",
|
||||||
"confirmations": 123,
|
"satoshis": 2782729129,
|
||||||
"timestamp": 1441068774,
|
"height": 534105,
|
||||||
"fees": 35436,
|
"confirmations": 123,
|
||||||
"outputIndexes": [
|
"timestamp": 1441068774,
|
||||||
0
|
"fees": 35436,
|
||||||
],
|
"outputIndexes": [
|
||||||
"inputIndexes": [],
|
0
|
||||||
"tx": {
|
],
|
||||||
"hash": "bb0ec3b96209fac9529570ea6f83a86af2cceedde4aaf2bfcc4796680d23f1c7",
|
"inputIndexes": [],
|
||||||
"version": 1,
|
"tx": {
|
||||||
"inputs": [
|
"hash": "bb0ec3b96209fac9529570ea6f83a86af2cceedde4aaf2bfcc4796680d23f1c7",
|
||||||
{
|
"version": 1,
|
||||||
"prevTxId": "ea5e5bafbf29cdf6f6097ab344128477e67889d4d6203cb43594836daa6cc425",
|
"inputs": [
|
||||||
"outputIndex": 1,
|
{
|
||||||
"sequenceNumber": 4294967294,
|
"prevTxId": "ea5e5bafbf29cdf6f6097ab344128477e67889d4d6203cb43594836daa6cc425",
|
||||||
"script": "483045022100f4d169783bef70e3943d2a617cce55d9fe4e33fc6f9880b8277265e2f619a97002201238648abcdf52960500664e969046d41755f7fc371971ebc78002fc418465a6012103acdcd31d51272403ce0829447e59e2ac9e08ed0bf92011cbf7420addf24534e6",
|
"outputIndex": 1,
|
||||||
"scriptString": "72 0x3045022100f4d169783bef70e3943d2a617cce55d9fe4e33fc6f9880b8277265e2f619a97002201238648abcdf52960500664e969046d41755f7fc371971ebc78002fc418465a601 33 0x03acdcd31d51272403ce0829447e59e2ac9e08ed0bf92011cbf7420addf24534e6",
|
"sequenceNumber": 4294967294,
|
||||||
"output": {
|
"script": "483045022100f4d169783bef70e3943d2a617cce55d9fe4e33fc6f9880b8277265e2f619a97002201238648abcdf52960500664e969046d41755f7fc371971ebc78002fc418465a6012103acdcd31d51272403ce0829447e59e2ac9e08ed0bf92011cbf7420addf24534e6",
|
||||||
"satoshis": 2796764565,
|
"scriptString": "72 0x3045022100f4d169783bef70e3943d2a617cce55d9fe4e33fc6f9880b8277265e2f619a97002201238648abcdf52960500664e969046d41755f7fc371971ebc78002fc418465a601 33 0x03acdcd31d51272403ce0829447e59e2ac9e08ed0bf92011cbf7420addf24534e6",
|
||||||
"script": "76a91488b1fe8aec5ae4358a11447a2f22b2781faedb9b88ac"
|
"output": {
|
||||||
|
"satoshis": 2796764565,
|
||||||
|
"script": "76a91488b1fe8aec5ae4358a11447a2f22b2781faedb9b88ac"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
],
|
||||||
],
|
"outputs": [
|
||||||
"outputs": [
|
{
|
||||||
{
|
|
||||||
"satoshis": 2782729129,
|
|
||||||
"script": "76a9143583efb5e64a4668c6c54bb5fcc30af4417b4f2d88ac"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"satoshis": 14000000,
|
|
||||||
"script": "76a9149713201957f42379e574d7c70d506ee49c2c8ad688ac"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"nLockTime": 534089
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"address": "mkPvAKZ2rar6qeG3KjBtJHHMSP1wFZH7Er",
|
|
||||||
"satoshis": -2782729129,
|
|
||||||
"height": 534110,
|
|
||||||
"confirmations": 118,
|
|
||||||
"timestamp": 1441072817,
|
|
||||||
"fees": 35437,
|
|
||||||
"outputIndexes": [],
|
|
||||||
"inputIndexes": [
|
|
||||||
"0"
|
|
||||||
],
|
|
||||||
"tx": {
|
|
||||||
"hash": "01f700df84c466f2a389440e5eeacdc47d04f380c39e5d19dce2ce91a11ecba3",
|
|
||||||
"version": 1,
|
|
||||||
"inputs": [
|
|
||||||
{
|
|
||||||
"prevTxId": "bb0ec3b96209fac9529570ea6f83a86af2cceedde4aaf2bfcc4796680d23f1c7",
|
|
||||||
"outputIndex": 0,
|
|
||||||
"sequenceNumber": 4294967294,
|
|
||||||
"script": "47304402201ee69281db6b95bb1aa3074059b67581635b719e8f64e4c2694db6ec56ad9447022011e91528996ea459b1fb2c0b59363fecbefe4bc2ca90f7b2382bdaa358f2d5640121034cc057b12a68ee79df998004b9a1341bbb18b17ea4939bebaa3bac001e940f24",
|
|
||||||
"scriptString": "71 0x304402201ee69281db6b95bb1aa3074059b67581635b719e8f64e4c2694db6ec56ad9447022011e91528996ea459b1fb2c0b59363fecbefe4bc2ca90f7b2382bdaa358f2d56401 33 0x034cc057b12a68ee79df998004b9a1341bbb18b17ea4939bebaa3bac001e940f24",
|
|
||||||
"output": {
|
|
||||||
"satoshis": 2782729129,
|
"satoshis": 2782729129,
|
||||||
"script": "76a9143583efb5e64a4668c6c54bb5fcc30af4417b4f2d88ac"
|
"script": "76a9143583efb5e64a4668c6c54bb5fcc30af4417b4f2d88ac"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"satoshis": 14000000,
|
||||||
|
"script": "76a9149713201957f42379e574d7c70d506ee49c2c8ad688ac"
|
||||||
}
|
}
|
||||||
}
|
],
|
||||||
|
"nLockTime": 534089
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"address": "mkPvAKZ2rar6qeG3KjBtJHHMSP1wFZH7Er",
|
||||||
|
"satoshis": -2782729129,
|
||||||
|
"height": 534110,
|
||||||
|
"confirmations": 118,
|
||||||
|
"timestamp": 1441072817,
|
||||||
|
"fees": 35437,
|
||||||
|
"outputIndexes": [],
|
||||||
|
"inputIndexes": [
|
||||||
|
"0"
|
||||||
],
|
],
|
||||||
"outputs": [
|
"tx": {
|
||||||
{
|
"hash": "01f700df84c466f2a389440e5eeacdc47d04f380c39e5d19dce2ce91a11ecba3",
|
||||||
"satoshis": 2764693692,
|
"version": 1,
|
||||||
"script": "76a91456e446bc3489543d8324c6d0271524c0bd0506dd88ac"
|
"inputs": [
|
||||||
},
|
{
|
||||||
{
|
"prevTxId": "bb0ec3b96209fac9529570ea6f83a86af2cceedde4aaf2bfcc4796680d23f1c7",
|
||||||
"satoshis": 18000000,
|
"outputIndex": 0,
|
||||||
"script": "76a914011d2963b619186a318f768dddfd98cd553912a088ac"
|
"sequenceNumber": 4294967294,
|
||||||
}
|
"script": "47304402201ee69281db6b95bb1aa3074059b67581635b719e8f64e4c2694db6ec56ad9447022011e91528996ea459b1fb2c0b59363fecbefe4bc2ca90f7b2382bdaa358f2d5640121034cc057b12a68ee79df998004b9a1341bbb18b17ea4939bebaa3bac001e940f24",
|
||||||
],
|
"scriptString": "71 0x304402201ee69281db6b95bb1aa3074059b67581635b719e8f64e4c2694db6ec56ad9447022011e91528996ea459b1fb2c0b59363fecbefe4bc2ca90f7b2382bdaa358f2d56401 33 0x034cc057b12a68ee79df998004b9a1341bbb18b17ea4939bebaa3bac001e940f24",
|
||||||
"nLockTime": 534099
|
"output": {
|
||||||
|
"satoshis": 2782729129,
|
||||||
|
"script": "76a9143583efb5e64a4668c6c54bb5fcc30af4417b4f2d88ac"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"satoshis": 2764693692,
|
||||||
|
"script": "76a91456e446bc3489543d8324c6d0271524c0bd0506dd88ac"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"satoshis": 18000000,
|
||||||
|
"script": "76a914011d2963b619186a318f768dddfd98cd553912a088ac"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"nLockTime": 534099
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
]
|
||||||
];
|
};
|
||||||
|
|
||||||
var tx = bitcore.Transaction().fromObject({
|
var tx = bitcore.Transaction().fromObject({
|
||||||
"hash": "63b68becb0e514b32317f4b29a5cf0627d4087e54ac17f686fcb1d9a27680f73",
|
"hash": "63b68becb0e514b32317f4b29a5cf0627d4087e54ac17f686fcb1d9a27680f73",
|
||||||
@ -135,14 +138,14 @@ var tx = bitcore.Transaction().fromObject({
|
|||||||
tx.__height = 534181;
|
tx.__height = 534181;
|
||||||
tx.__timestamp = 1441116143;
|
tx.__timestamp = 1441116143;
|
||||||
tx.__blockHash = '0000000000000041ddc94ecf4f86a456a83b2e320c36c6f0c13ff92c7e75f013';
|
tx.__blockHash = '0000000000000041ddc94ecf4f86a456a83b2e320c36c6f0c13ff92c7e75f013';
|
||||||
var txinfos2 = [
|
var txinfos2 = {
|
||||||
{
|
totalCount: 1,
|
||||||
tx: tx
|
items: [
|
||||||
},
|
{
|
||||||
{
|
tx: tx
|
||||||
tx: tx
|
}
|
||||||
}
|
]
|
||||||
];
|
};
|
||||||
|
|
||||||
var utxos = [
|
var utxos = [
|
||||||
{
|
{
|
||||||
@ -512,7 +515,9 @@ describe('Addresses', function() {
|
|||||||
var addresses = new AddressController(node);
|
var addresses = new AddressController(node);
|
||||||
|
|
||||||
var req = {
|
var req = {
|
||||||
addrs: 'mzkD4nmQ8ixqxySdBgsXTpgvAMK5iRZpNK,moZY18rGNmh4YCPeugtGW46AkkWMQttBUD'
|
addrs: 'mzkD4nmQ8ixqxySdBgsXTpgvAMK5iRZpNK,moZY18rGNmh4YCPeugtGW46AkkWMQttBUD',
|
||||||
|
query: {},
|
||||||
|
body: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
var res = {
|
var res = {
|
||||||
|
|||||||
@ -613,6 +613,11 @@ describe('Transactions', function() {
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var historyResult = {
|
||||||
|
totalCount: txinfos.length,
|
||||||
|
items: txinfos
|
||||||
|
};
|
||||||
|
|
||||||
txinfos[0].tx.__blockHash = '00000000000001001aba15de213648f370607fb048288dd27b96f7e833a73520';
|
txinfos[0].tx.__blockHash = '00000000000001001aba15de213648f370607fb048288dd27b96f7e833a73520';
|
||||||
txinfos[0].tx.__timestamp = 1441068774;
|
txinfos[0].tx.__timestamp = 1441068774;
|
||||||
txinfos[0].tx.__height = 534105;
|
txinfos[0].tx.__height = 534105;
|
||||||
@ -622,7 +627,7 @@ describe('Transactions', function() {
|
|||||||
txinfos[1].tx.__height = 534110;
|
txinfos[1].tx.__height = 534110;
|
||||||
|
|
||||||
var node = {
|
var node = {
|
||||||
getAddressHistory: sinon.stub().callsArgWith(2, null, txinfos),
|
getAddressHistory: sinon.stub().callsArgWith(2, null, historyResult),
|
||||||
services: {
|
services: {
|
||||||
db: {
|
db: {
|
||||||
tip: {
|
tip: {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user