Remove index from txs. Explicit return and fix spent and received in addr.
This commit is contained in:
parent
a3e4e19a9d
commit
bf26304746
@ -47,14 +47,14 @@ module.exports = function AddressAPI(router) {
|
|||||||
logger.log('error',
|
logger.log('error',
|
||||||
`${err}`);
|
`${err}`);
|
||||||
}
|
}
|
||||||
const totalSpent = body.reduce((sum, tx) => sum + tx.outputs.reduce((sum, output) => {
|
const totalReceived = body.reduce((sum, tx) => sum + tx.outputs.reduce((sum, output) => {
|
||||||
if (output.address === req.params.addr) {
|
if (output.address === req.params.addr) {
|
||||||
return sum + output.value;
|
return sum + output.value;
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
}, 0), 0);
|
}, 0), 0);
|
||||||
|
|
||||||
const totalReceived = body.reduce((sum, tx) => sum + tx.inputs.reduce((sum, input) => {
|
const totalSpent = body.reduce((sum, tx) => sum + tx.inputs.reduce((sum, input) => {
|
||||||
if (input.coin && input.coin.address === req.params.addr) {
|
if (input.coin && input.coin.address === req.params.addr) {
|
||||||
return sum + input.coin.value;
|
return sum + input.coin.value;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,7 +60,6 @@ module.exports = function BlockAPI(router) {
|
|||||||
|
|
||||||
router.get('/blocks', (req, res) => {
|
router.get('/blocks', (req, res) => {
|
||||||
const limit = parseInt(req.query.limit) || MAX_BLOCKS;
|
const limit = parseInt(req.query.limit) || MAX_BLOCKS;
|
||||||
|
|
||||||
getBlock(
|
getBlock(
|
||||||
{},
|
{},
|
||||||
{ height: 1,
|
{ height: 1,
|
||||||
@ -75,6 +74,7 @@ module.exports = function BlockAPI(router) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
res.status(501).send();
|
res.status(501).send();
|
||||||
logger.log('err', err);
|
logger.log('err', err);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
|
|||||||
@ -22,8 +22,6 @@ const TransactionSchema = new Schema({
|
|||||||
network: String,
|
network: String,
|
||||||
});
|
});
|
||||||
|
|
||||||
TransactionSchema.index({ hash: 1 });
|
|
||||||
|
|
||||||
const Transaction = mongoose.model('Transaction', TransactionSchema);
|
const Transaction = mongoose.model('Transaction', TransactionSchema);
|
||||||
|
|
||||||
module.exports = Transaction;
|
module.exports = Transaction;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user