Moved db configs to config file. Dropped time from log files. Simple commenting
This commit is contained in:
parent
2eac46fdb5
commit
e3b8413eee
@ -26,6 +26,9 @@ const config = {
|
|||||||
json_spaces: 2,
|
json_spaces: 2,
|
||||||
currency_refresh: 60,
|
currency_refresh: 60,
|
||||||
ticker_url: 'https://www.bitstamp.net/api/ticker/',
|
ticker_url: 'https://www.bitstamp.net/api/ticker/',
|
||||||
|
ticker_prop: 'bitstamp',
|
||||||
|
max_blocks: 72,
|
||||||
|
max_txs: 10,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ const db = require('../db');
|
|||||||
|
|
||||||
module.exports = function BlockAPI(router) {
|
module.exports = function BlockAPI(router) {
|
||||||
router.get('/block/:blockHash', (req, res) => {
|
router.get('/block/:blockHash', (req, res) => {
|
||||||
|
// Pass Mongo params, fields and limit to db api.
|
||||||
db.blocks.getBlock(
|
db.blocks.getBlock(
|
||||||
{ hash: req.params.blockHash },
|
{ hash: req.params.blockHash },
|
||||||
{ rawBlock: 0 },
|
{ rawBlock: 0 },
|
||||||
@ -12,7 +13,7 @@ module.exports = function BlockAPI(router) {
|
|||||||
logger.log('err', err);
|
logger.log('err', err);
|
||||||
return res.status(404).send();
|
return res.status(404).send();
|
||||||
}
|
}
|
||||||
|
// Format the request for insight ui
|
||||||
return res.json({
|
return res.json({
|
||||||
hash: block.hash,
|
hash: block.hash,
|
||||||
size: block.size,
|
size: block.size,
|
||||||
@ -37,7 +38,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) || 100;
|
||||||
|
// Pass Mongo params, fields and limit to db api.
|
||||||
db.blocks.getBlocks(
|
db.blocks.getBlocks(
|
||||||
{},
|
{},
|
||||||
{ height: 1,
|
{ height: 1,
|
||||||
@ -54,7 +55,7 @@ module.exports = function BlockAPI(router) {
|
|||||||
`/blocks: ${err}`);
|
`/blocks: ${err}`);
|
||||||
return res.status(404).send();
|
return res.status(404).send();
|
||||||
}
|
}
|
||||||
|
// Format the request for insight ui
|
||||||
return res.json({
|
return res.json({
|
||||||
blocks: blocks.map(block => ({
|
blocks: blocks.map(block => ({
|
||||||
hash: block.hash,
|
hash: block.hash,
|
||||||
@ -72,7 +73,7 @@ module.exports = function BlockAPI(router) {
|
|||||||
|
|
||||||
router.get('/rawblock/:blockHash', (req, res) => {
|
router.get('/rawblock/:blockHash', (req, res) => {
|
||||||
const blockHash = req.params.blockHash || '';
|
const blockHash = req.params.blockHash || '';
|
||||||
|
// Pass Mongo params, fields and limit to db api.
|
||||||
db.blocks.getBlock(
|
db.blocks.getBlock(
|
||||||
{ hash: blockHash },
|
{ hash: blockHash },
|
||||||
{ rawBlock: 1 },
|
{ rawBlock: 1 },
|
||||||
@ -89,7 +90,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) || 1;
|
||||||
|
// Pass Mongo params, fields and limit to db api.
|
||||||
db.blocks.getBlock(
|
db.blocks.getBlock(
|
||||||
{ height: blockHeight },
|
{ height: blockHeight },
|
||||||
{ hash: 1 },
|
{ hash: 1 },
|
||||||
|
|||||||
@ -2,6 +2,9 @@ const config = require('../../config');
|
|||||||
const logger = require('../logger');
|
const logger = require('../logger');
|
||||||
const request = require('request');
|
const request = require('request');
|
||||||
|
|
||||||
|
// Retrieve the configured endpoint's ticker rate at a
|
||||||
|
// set interval
|
||||||
|
|
||||||
const refreshInterval = config.api.currency_refresh >= 1 ?
|
const refreshInterval = config.api.currency_refresh >= 1 ?
|
||||||
config.api.currency_refresh * 1000 :
|
config.api.currency_refresh * 1000 :
|
||||||
60 * 1000;
|
60 * 1000;
|
||||||
@ -32,11 +35,13 @@ function getRate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function currencyAPI(app) {
|
module.exports = function currencyAPI(app) {
|
||||||
|
// Return the ticker price
|
||||||
app.get('/currency', (req, res) => {
|
app.get('/currency', (req, res) => {
|
||||||
|
const data = {}
|
||||||
|
data[config.api.ticker_prop] = lastRate;
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
data: {
|
data,
|
||||||
bitstamp: lastRate,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -4,7 +4,7 @@ const config = require('../../config');
|
|||||||
const db = require('../db');
|
const db = require('../db');
|
||||||
|
|
||||||
const API_URL = `http://${config.bcoin_http}:${config.bcoin['http-port']}`;
|
const API_URL = `http://${config.bcoin_http}:${config.bcoin['http-port']}`;
|
||||||
const MAX_TXS = 50;
|
const MAX_TXS = config.api.max_txs;
|
||||||
|
|
||||||
module.exports = function transactionAPI(router) {
|
module.exports = function transactionAPI(router) {
|
||||||
router.get('/tx/:txid', (req, res) => {
|
router.get('/tx/:txid', (req, res) => {
|
||||||
|
|||||||
@ -2,14 +2,14 @@ const Block = require('../../models/block.js');
|
|||||||
const logger = require('../logger');
|
const logger = require('../logger');
|
||||||
const config = require('../../config');
|
const config = require('../../config');
|
||||||
|
|
||||||
// move to config
|
const MAX_BLOCKS = config.api.max_blocks; // ~ 12 hours
|
||||||
const MAX_BLOCKS = 72; // ~ 12 hours
|
|
||||||
|
|
||||||
function getBlocks(params, options, limit, cb) {
|
function getBlocks(params, options, limit, cb) {
|
||||||
|
// Do not return mongo ids
|
||||||
const defaultOptions = { _id: 0 };
|
const defaultOptions = { _id: 0 };
|
||||||
|
// Copy over mongo options
|
||||||
Object.assign(defaultOptions, options);
|
Object.assign(defaultOptions, options);
|
||||||
|
// Simple sanitizing
|
||||||
if (!Number.isInteger(limit)) {
|
if (!Number.isInteger(limit)) {
|
||||||
limit = 1;
|
limit = 1;
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ function getBlocks(params, options, limit, cb) {
|
|||||||
if (limit < 1) {
|
if (limit < 1) {
|
||||||
limit = 1;
|
limit = 1;
|
||||||
}
|
}
|
||||||
|
// Query mongo
|
||||||
Block.find(
|
Block.find(
|
||||||
params,
|
params,
|
||||||
defaultOptions,
|
defaultOptions,
|
||||||
@ -39,7 +39,7 @@ function getBlocks(params, options, limit, cb) {
|
|||||||
.sort({ height: -1 })
|
.sort({ height: -1 })
|
||||||
.limit(limit);
|
.limit(limit);
|
||||||
}
|
}
|
||||||
|
// Retrieve a single block. For convenience mostly
|
||||||
function getBlock(params, options, limit, cb) {
|
function getBlock(params, options, limit, cb) {
|
||||||
getBlocks(params, options, limit, (err, blocks) => {
|
getBlocks(params, options, limit, (err, blocks) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@ -2,14 +2,14 @@ const Transactions = require('../../models/transaction.js');
|
|||||||
const logger = require('../logger');
|
const logger = require('../logger');
|
||||||
const config = require('../../config');
|
const config = require('../../config');
|
||||||
|
|
||||||
// move to config
|
const MAX_TXS = config.api.max_txs;
|
||||||
const MAX_TXS = 50;
|
|
||||||
|
|
||||||
function getTransactions(params, options, limit, cb) {
|
function getTransactions(params, options, limit, cb) {
|
||||||
|
// Do not return mongo ids
|
||||||
const defaultOptions = { _id: 0 };
|
const defaultOptions = { _id: 0 };
|
||||||
|
// Copy over mongo options
|
||||||
Object.assign(defaultOptions, options);
|
Object.assign(defaultOptions, options);
|
||||||
|
// Simple sanitizing
|
||||||
if (!Number.isInteger(limit)) {
|
if (!Number.isInteger(limit)) {
|
||||||
limit = 1;
|
limit = 1;
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ function getTransactions(params, options, limit, cb) {
|
|||||||
if (limit < 1) {
|
if (limit < 1) {
|
||||||
limit = 1;
|
limit = 1;
|
||||||
}
|
}
|
||||||
|
// Query mongo
|
||||||
Transactions.find(
|
Transactions.find(
|
||||||
params,
|
params,
|
||||||
defaultOptions,
|
defaultOptions,
|
||||||
@ -44,7 +44,7 @@ function getTransaction(params, options, limit, cb) {
|
|||||||
getTransactions(params, options, limit, (err, tx) => {
|
getTransactions(params, options, limit, (err, tx) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.log('error',
|
logger.log('error',
|
||||||
`getBlock: ${err.err}`);
|
`getTransaction: ${err.err}`);
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
if (!tx.length > 0) {
|
if (!tx.length > 0) {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
const winston = require('winston');
|
const winston = require('winston');
|
||||||
const config = require('../../config');
|
const config = require('../../config');
|
||||||
|
|
||||||
const logfile = new Date().toISOString();
|
const logfile = new Date().toISOString().split('T')[0];
|
||||||
|
|
||||||
const logger = new (winston.Logger)({
|
const logger = new (winston.Logger)({
|
||||||
transports: [
|
transports: [
|
||||||
|
|||||||
@ -6,6 +6,8 @@ const addrParser = require('../parser').Address;
|
|||||||
const config = require('../../config');
|
const config = require('../../config');
|
||||||
const io = require('../api').io;
|
const io = require('../api').io;
|
||||||
|
|
||||||
|
// Reverse how sockets are working
|
||||||
|
|
||||||
const node = new FullNode(config.bcoin);
|
const node = new FullNode(config.bcoin);
|
||||||
|
|
||||||
// Hacky move this to config
|
// Hacky move this to config
|
||||||
|
|||||||
@ -55,7 +55,6 @@ ScopedSocket.prototype.emit = function(event, data, callback) {
|
|||||||
|
|
||||||
angular.module('insight.socket').factory('getSocket',
|
angular.module('insight.socket').factory('getSocket',
|
||||||
function($rootScope) {
|
function($rootScope) {
|
||||||
console.log('init my socket');
|
|
||||||
var socket = io.connect('http://localhost', {
|
var socket = io.connect('http://localhost', {
|
||||||
'reconnect': true,
|
'reconnect': true,
|
||||||
'reconnection delay': 500,
|
'reconnection delay': 500,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user