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