Clean up eslint complaints
This commit is contained in:
parent
e5b608809b
commit
c47f58f8e8
@ -9,6 +9,8 @@
|
||||
"no-use-before-define": 1,
|
||||
"object-shorthand": 1,
|
||||
"key-spacing": 0,
|
||||
"no-plusplus": 0
|
||||
"no-plusplus": 0,
|
||||
"no-unused-vars": 1,
|
||||
"no-param-reassign": 1
|
||||
}
|
||||
}
|
||||
@ -10,7 +10,6 @@ logger.log('debug',
|
||||
db.connect(config.mongodb.uri, config.mongodb.options);
|
||||
|
||||
db.connection.once('open', () => {
|
||||
|
||||
if (config.start_node) Bcoin.start();
|
||||
|
||||
Api.listen(config.api.port, () => {
|
||||
|
||||
@ -9,14 +9,15 @@ module.exports = function AddressAPI(router) {
|
||||
const addr = req.params.addr || '';
|
||||
// Get Bcoin data
|
||||
return request(`${API_URL}/tx/address/${addr}`,
|
||||
(error, bcoinRes, txs) => {
|
||||
(error, bcoinRes, bcoinTxs) => {
|
||||
if (error) {
|
||||
logger.log('error',
|
||||
`${error}`);
|
||||
return res.status(404).send({});
|
||||
}
|
||||
let txs = {};
|
||||
try {
|
||||
txs = JSON.parse(txs);
|
||||
txs = JSON.parse(bcoinTxs);
|
||||
} catch (e) {
|
||||
logger.log('error',
|
||||
`${e}`);
|
||||
@ -24,7 +25,7 @@ module.exports = function AddressAPI(router) {
|
||||
}
|
||||
|
||||
// Sum the matching outputs for every tx
|
||||
const totalReceived = txs.reduce((sum, tx) => sum + tx.outputs.reduce((sum, output) => {
|
||||
const totalReceived = txs.reduce((total, tx) => total + tx.outputs.reduce((sum, output) => {
|
||||
if (output.address === req.params.addr) {
|
||||
return sum + output.value;
|
||||
}
|
||||
@ -32,7 +33,7 @@ module.exports = function AddressAPI(router) {
|
||||
}, 0), 0) || 0;
|
||||
|
||||
// Sum the matching inputs for every tx
|
||||
const totalSpent = txs.reduce((sum, tx) => sum + tx.inputs.reduce((sum, input) => {
|
||||
const totalSpent = txs.reduce((total, tx) => total + tx.inputs.reduce((sum, input) => {
|
||||
if (input.coin && input.coin.address === req.params.addr) {
|
||||
return sum + input.coin.value;
|
||||
}
|
||||
|
||||
@ -37,7 +37,7 @@ module.exports = function BlockAPI(router) {
|
||||
});
|
||||
|
||||
router.get('/blocks', (req, res) => {
|
||||
const limit = parseInt(req.query.limit) || 100;
|
||||
const limit = parseInt(req.query.limit, 10) || 100;
|
||||
// Pass Mongo params, fields and limit to db api.
|
||||
db.blocks.getBlocks(
|
||||
{},
|
||||
@ -89,7 +89,7 @@ module.exports = function BlockAPI(router) {
|
||||
});
|
||||
|
||||
router.get('/block-index/:height', (req, res) => {
|
||||
const blockHeight = parseInt(req.params.height) || 1;
|
||||
const blockHeight = parseInt(req.params.height, 10) || 1;
|
||||
// Pass Mongo params, fields and limit to db api.
|
||||
db.blocks.getBlock(
|
||||
{ height: blockHeight },
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
module.exports = function (req, res, next) {
|
||||
let allowed = {
|
||||
const allowed = {
|
||||
|
||||
origins: [
|
||||
'*',
|
||||
|
||||
@ -10,11 +10,15 @@ const refreshInterval = config.api.currency_refresh >= 1 ?
|
||||
60 * 1000;
|
||||
let lastRate = 0;
|
||||
|
||||
getRate();
|
||||
init();
|
||||
|
||||
setInterval(() => {
|
||||
function init() {
|
||||
getRate();
|
||||
}, refreshInterval);
|
||||
|
||||
setInterval(() => {
|
||||
getRate();
|
||||
}, refreshInterval);
|
||||
}
|
||||
|
||||
// Make the request to the remote API
|
||||
function getRate() {
|
||||
@ -38,7 +42,7 @@ function getRate() {
|
||||
module.exports = function currencyAPI(app) {
|
||||
// Return the ticker price
|
||||
app.get('/currency', (req, res) => {
|
||||
const data = {}
|
||||
const data = {};
|
||||
data[config.api.ticker_prop] = lastRate;
|
||||
|
||||
res.json({
|
||||
|
||||
@ -50,10 +50,10 @@ function emitTx(transaction) {
|
||||
const txJSON = transaction.toJSON();
|
||||
io.sockets.emit('tx', {
|
||||
txid: txJSON.hash,
|
||||
valueOut: transaction.outputs.reduce((sum, tx) => {
|
||||
tx = tx.toJSON();
|
||||
valueOut: transaction.outputs.reduce((sum, output) => {
|
||||
output = output.toJSON();
|
||||
|
||||
const valB = (tx.value || tx.valueOut.value || 0) / 1e8;
|
||||
const valB = (output.value || output.valueOut.value || 0) / 1e8;
|
||||
|
||||
return sum + valB;
|
||||
}, 0),
|
||||
|
||||
@ -53,11 +53,11 @@ module.exports = function statusAPI(router) {
|
||||
return res.status(404).send(err);
|
||||
}
|
||||
if (!status) {
|
||||
logger.log('err'
|
||||
`/status getStatus: no Status`);
|
||||
logger.log('err',
|
||||
'/status getStatus: no Status');
|
||||
return res.status(404).send();
|
||||
}
|
||||
res.json({
|
||||
return res.json({
|
||||
info: {
|
||||
version: status.version,
|
||||
protocolversion: netCfg.PROTOCOL_VERSION,
|
||||
@ -88,8 +88,8 @@ module.exports = function statusAPI(router) {
|
||||
'/sync: no status');
|
||||
return res.status(404).send();
|
||||
}
|
||||
res.json({
|
||||
status: status.chain.progress === 100 ? 'synced': 'syncing',
|
||||
return res.json({
|
||||
status: status.chain.progress === 100 ? 'synced' : 'syncing',
|
||||
blockChainHeight: status.chain.height,
|
||||
syncPercentage: Math.round(status.chain.progress * 100),
|
||||
height: status.chain.height,
|
||||
|
||||
@ -47,7 +47,7 @@ module.exports = function transactionAPI(router) {
|
||||
locktime: tx.locktime,
|
||||
blockhash: tx.block,
|
||||
fees: tx.fee / 1e8,
|
||||
confirmations: height - tx.height + 1,
|
||||
confirmations: (height - tx.height) + 1,
|
||||
valueOut: tx.outputs.reduce((sum, output) => sum + output.value, 0) / 1e8,
|
||||
vin: tx.inputs.map(input => ({
|
||||
addr: input.coin ? input.coin.address : '',
|
||||
@ -70,12 +70,11 @@ module.exports = function transactionAPI(router) {
|
||||
// query by address
|
||||
// last n txs
|
||||
router.get('/txs', (req, res) => {
|
||||
const pageNum = parseInt(req.query.pageNum) || 0;
|
||||
const pageNum = parseInt(req.query.pageNum, 10) || 0;
|
||||
const rangeStart = pageNum * MAX_TXS;
|
||||
const rangeEnd = rangeStart + MAX_TXS;
|
||||
// get txs for blockhash, start with best height to calc confirmations
|
||||
if (req.query.block) {
|
||||
|
||||
db.blocks.getBestHeight(
|
||||
(err, blockHeight) => {
|
||||
if (err) {
|
||||
@ -111,7 +110,7 @@ module.exports = function transactionAPI(router) {
|
||||
txs: block.txs.map(tx => ({
|
||||
txid: tx.hash,
|
||||
fees: tx.fee / 1e8,
|
||||
confirmations: height - block.height + 1,
|
||||
confirmations: (height - block.height) + 1,
|
||||
valueOut: tx.outputs.reduce((sum, output) => sum + output.value, 0) / 1e8,
|
||||
vin: tx.inputs.map(input => ({
|
||||
addr: input.coin ? input.coin.address : '',
|
||||
@ -160,7 +159,7 @@ module.exports = function transactionAPI(router) {
|
||||
txs: txs.map(tx => ({
|
||||
txid: tx.hash,
|
||||
fees: tx.fee / 1e8,
|
||||
confirmations: height - tx.height + 1,
|
||||
confirmations: (height - tx.height) + 1,
|
||||
valueOut: tx.outputs.reduce((sum, output) => sum + output.value, 0) / 1e8,
|
||||
vin: tx.inputs.map(input => ({
|
||||
addr: input.coin ? input.coin.address : '',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user