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