Add last_txs to getaddress API
This commit is contained in:
@@ -71,17 +71,45 @@ app.use('/ext/getmoneysupply', function(req,res){
|
||||
|
||||
app.use('/ext/getaddress/:hash', function(req,res){
|
||||
db.get_address(req.params.hash, false, function(address){
|
||||
if (address) {
|
||||
var a_ext = {
|
||||
address: address.a_id,
|
||||
sent: (address.sent / 100000000),
|
||||
received: (address.received / 100000000),
|
||||
balance: (address.balance / 100000000).toString().replace(/(^-+)/mg, ''),
|
||||
};
|
||||
res.send(a_ext);
|
||||
} else {
|
||||
res.send({ error: 'address not found.', hash: req.params.hash})
|
||||
}
|
||||
db.get_address_txs_ajax(req.params.hash, 0, settings.txcount, function(txs, count){
|
||||
if (address) {
|
||||
var last_txs = [];
|
||||
for(i=0; i<txs.length; i++){
|
||||
if(typeof txs[i].txid !== "undefined") {
|
||||
var out = 0,
|
||||
vin = 0,
|
||||
tx_type = 'vout',
|
||||
row = {};
|
||||
txs[i].vout.forEach(function (r) {
|
||||
if (r.addresses == req.params.hash) {
|
||||
out += r.amount;
|
||||
}
|
||||
});
|
||||
txs[i].vin.forEach(function (s) {
|
||||
if (s.addresses == req.params.hash) {
|
||||
vin += s.amount;
|
||||
}
|
||||
});
|
||||
if (vin > out) {
|
||||
tx_type = 'vin';
|
||||
}
|
||||
row['addresses'] = txs[i].txid;
|
||||
row['type'] = tx_type;
|
||||
last_txs.push(row);
|
||||
}
|
||||
}
|
||||
var a_ext = {
|
||||
address: address.a_id,
|
||||
sent: (address.sent / 100000000),
|
||||
received: (address.received / 100000000),
|
||||
balance: (address.balance / 100000000).toString().replace(/(^-+)/mg, ''),
|
||||
last_txs: last_txs
|
||||
};
|
||||
res.send(a_ext);
|
||||
} else {
|
||||
res.send({ error: 'address not found.', hash: req.params.hash});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+5
-4
@@ -413,9 +413,9 @@ module.exports = {
|
||||
} else {
|
||||
totalCount = count;
|
||||
AddressTx.aggregate([
|
||||
{ $match: { a_id: hash } },
|
||||
{ $match: { a_id: hash } },
|
||||
{ $sort: {blockindex: -1} },
|
||||
{ $skip: Number(start) },
|
||||
{ $skip: Number(start) },
|
||||
{
|
||||
$group: {
|
||||
_id: '',
|
||||
@@ -439,12 +439,13 @@ module.exports = {
|
||||
} else {
|
||||
var txs = [];
|
||||
var count = address_tx.length;
|
||||
var running_balance = balance_sum[0].balance;
|
||||
var running_balance = balance_sum.length > 0 ? balance_sum[0].balance : 0;
|
||||
|
||||
var txs = [];
|
||||
|
||||
lib.syncLoop(count, function (loop) {
|
||||
var i = loop.iteration();
|
||||
find_tx(hashes[i].txid, function (tx) {
|
||||
find_tx(address_tx[i].txid, function (tx) {
|
||||
if (tx && !txs.includes(tx)) {
|
||||
tx.balance = running_balance;
|
||||
txs.push(tx);
|
||||
|
||||
Reference in New Issue
Block a user