Merge branch 'next-merge' of https://github.com/tenthirtyone/insight into next

This commit is contained in:
Darren Nelsen 2017-08-22 14:11:10 -04:00
commit b9de71862d
3 changed files with 29 additions and 26 deletions

View File

@ -1,7 +1,7 @@
const Bcoin = require('./lib/node');
const config = require('./config');
const logger = require('./lib/logger');
const Api = require('./lib/api');
const Api = require('./lib/api').server;
const db = require('./lib/db');
logger.log('debug',

View File

@ -14,6 +14,8 @@ app.use(bodyParser.json());
// Serve insight ui front end from root dir public folder
app.use(express.static('../app/www', { maxage: '1w' }));
// Legacy UI - useful for 1:1 compares
// app.use(express.static('./public', { maxage: '1w' }));
app.set('json spaces', config.api.json_spaces);
@ -37,4 +39,7 @@ app.use((req, res) => res.status(404).send({
// Socket server
const server = require('http').Server(app);
module.exports = server;
module.exports = {
server,
api,
};

View File

@ -59,7 +59,6 @@ module.exports = function transactionAPI(router) {
// /txs is overloaded. Next ver separate concerns
// query by block
// query by address
// last n txs - haha jk YOU 404
router.get('/txs', (req, res) => {
const pageNum = parseInt(req.query.pageNum, 10) || 0;
const rangeStart = pageNum * MAX_TXS;
@ -174,30 +173,29 @@ module.exports = function transactionAPI(router) {
`/txs getTopTransactions ${err}`);
return res.status(404).send(err);
}
return res.json({
txs: txs.map(tx => ({
txid: tx.hash,
fees: tx.fee / 1e8,
size: tx.size,
confirmations: (height - tx.height) + 1,
valueOut: tx.outputs.reduce((sum, output) => sum + output.value, 0) / 1e8,
vin: tx.inputs.map(input => ({
scriptSig: {
asm: input.script,
},
addr: input.address,
value: input.value / 1e8,
})),
vout: tx.outputs.map(output => ({
scriptPubKey: {
asm: output.script,
addresses: [output.address],
},
value: output.value / 1e8,
})),
isCoinBase: tx.inputs[0].prevout.hash === '0000000000000000000000000000000000000000000000000000000000000000',
return res.send(txs.map(tx => ({
txid: tx.hash,
fees: tx.fee / 1e8,
size: tx.size,
confirmations: (height - tx.height) + 1,
valueOut: tx.outputs.reduce((sum, output) => sum + output.value, 0) / 1e8,
vin: tx.inputs.map(input => ({
scriptSig: {
asm: input.script,
},
addr: input.address,
value: input.value / 1e8,
})),
});
vout: tx.outputs.map(output => ({
scriptPubKey: {
asm: output.script,
addresses: [output.address],
},
value: output.value / 1e8,
})),
isCoinBase: tx.inputs[0].prevout.hash === '0000000000000000000000000000000000000000000000000000000000000000',
})),
);
});
}
});