block limits added, currency fixed, FE routes added
This commit is contained in:
parent
0174fd5226
commit
7beb1867d7
@ -24,9 +24,9 @@ Mongo will create the bitcore db and a blocks/transactions collection automatica
|
|||||||
|
|
||||||
Bcoin offers a few database types. The most ideal for our purpose is the in memory database. Unfortunately, Bcoin will not record blockchain sync checkpoints in this mode. Every restart of the client would result in Bcoin sync'ing from the Genesis block. Long term, we should consider sending them a friendly PR.
|
Bcoin offers a few database types. The most ideal for our purpose is the in memory database. Unfortunately, Bcoin will not record blockchain sync checkpoints in this mode. Every restart of the client would result in Bcoin sync'ing from the Genesis block. Long term, we should consider sending them a friendly PR.
|
||||||
|
|
||||||
Alternatively, I've explored putting mongo into Bcoin. The db interface seems simple enough. Bcoin mostly get/puts but it is surprisingly complicated under the hood. So Bcoin creates its own leveldb.
|
Alternatively, I've explored putting mongo into Bcoin. The db interface seems simple enough. Bcoin mostly get/puts but it is surprisingly complicated under the hood. So Bcoin creates its own leveldb for now.
|
||||||
|
|
||||||
Refresh does not work unless you setup to run as root on port 80 and set an /etc/hosts override.
|
Refresh does not work unless you setup to run as root on port 80 and set an /etc/hosts override. Web server is absolutely minimal right now
|
||||||
|
|
||||||
### Resetting Application State
|
### Resetting Application State
|
||||||
```
|
```
|
||||||
@ -53,6 +53,8 @@ https://docs.google.com/a/bit-pay.com/spreadsheets/d/1hDlf16F6zAxBrOC3ZdnvfRrSB9
|
|||||||
1. scriptpubkey asm
|
1. scriptpubkey asm
|
||||||
2. peer's best block height is learned on peer connect but not retained by the app. Block height is the current sync height
|
2. peer's best block height is learned on peer connect but not retained by the app. Block height is the current sync height
|
||||||
3. Multiple Outputs were overlooked in the mongo model
|
3. Multiple Outputs were overlooked in the mongo model
|
||||||
|
* Post-sync listeners are not wired up yet (sockets).
|
||||||
|
* Parameters for some routes are missing. Spreadsheet is not 100% complete. Need a test run / qa round.
|
||||||
|
|
||||||
# ToDo but not Required for a release
|
# ToDo but not Required for a release
|
||||||
* Reorg testing - Bcoin will handle this but we need to account for this in our mongo indexes.
|
* Reorg testing - Bcoin will handle this but we need to account for this in our mongo indexes.
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
const config = {
|
const config = {
|
||||||
start_node: true,
|
start_node: false,
|
||||||
logging: 'debug',
|
logging: 'debug',
|
||||||
bcoin: {
|
bcoin: {
|
||||||
network: 'main',
|
network: 'main',
|
||||||
@ -17,7 +17,7 @@ const config = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
api: {
|
api: {
|
||||||
port: 80,
|
port: 3000,
|
||||||
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/',
|
||||||
|
|||||||
@ -3,9 +3,13 @@ const logger = require('../logger');
|
|||||||
|
|
||||||
const MAX_BLOCKS = 200;
|
const MAX_BLOCKS = 200;
|
||||||
|
|
||||||
function getBlock(params, options, cb) {
|
function getBlock(params, options, limit, cb) {
|
||||||
const defaultOptions = { _id: 0 };
|
const defaultOptions = { _id: 0 };
|
||||||
|
|
||||||
|
if (!Number.isInteger(limit)) {
|
||||||
|
limit = MAX_BLOCKS;
|
||||||
|
}
|
||||||
|
|
||||||
Object.assign(defaultOptions, options);
|
Object.assign(defaultOptions, options);
|
||||||
|
|
||||||
Block.find(
|
Block.find(
|
||||||
@ -13,7 +17,7 @@ function getBlock(params, options, cb) {
|
|||||||
defaultOptions,
|
defaultOptions,
|
||||||
cb)
|
cb)
|
||||||
.sort({ height: -1 })
|
.sort({ height: -1 })
|
||||||
.limit(MAX_BLOCKS);
|
.limit(limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function BlockAPI(router) {
|
module.exports = function BlockAPI(router) {
|
||||||
@ -21,6 +25,7 @@ module.exports = function BlockAPI(router) {
|
|||||||
getBlock(
|
getBlock(
|
||||||
{ hash: req.params.blockHash },
|
{ hash: req.params.blockHash },
|
||||||
{ rawBlock: 0 },
|
{ rawBlock: 0 },
|
||||||
|
MAX_BLOCKS,
|
||||||
(err, block) => {
|
(err, block) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.status(501).send();
|
res.status(501).send();
|
||||||
@ -54,6 +59,8 @@ module.exports = function BlockAPI(router) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
router.get('/blocks', (req, res) => {
|
router.get('/blocks', (req, res) => {
|
||||||
|
const limit = parseInt(req.query.limit) || MAX_BLOCKS;
|
||||||
|
|
||||||
getBlock(
|
getBlock(
|
||||||
{},
|
{},
|
||||||
{ height: 1,
|
{ height: 1,
|
||||||
@ -61,23 +68,23 @@ module.exports = function BlockAPI(router) {
|
|||||||
hash: 1,
|
hash: 1,
|
||||||
ts: 1,
|
ts: 1,
|
||||||
txs: 1,
|
txs: 1,
|
||||||
poolInfo: 1 },
|
poolInfo: 1,
|
||||||
|
},
|
||||||
|
limit,
|
||||||
(err, blocks) => {
|
(err, blocks) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.status(501).send();
|
res.status(501).send();
|
||||||
logger.log('err', err);
|
logger.log('err', err);
|
||||||
}
|
}
|
||||||
res.json({
|
res.json({
|
||||||
blocks: blocks.map((block) => {
|
blocks: blocks.map(block => ({
|
||||||
return {
|
hash: block.hash,
|
||||||
hash: block.hash,
|
height: block.height,
|
||||||
height: block.height,
|
size: block.size,
|
||||||
size: block.size,
|
time: block.ts,
|
||||||
time: block.ts,
|
txlength: block.txs.length,
|
||||||
txlength: block.txs.length,
|
poolInfo: {},
|
||||||
poolInfo: {},
|
})),
|
||||||
};
|
|
||||||
}),
|
|
||||||
length: blocks.length,
|
length: blocks.length,
|
||||||
pagination: {},
|
pagination: {},
|
||||||
});
|
});
|
||||||
@ -88,6 +95,7 @@ module.exports = function BlockAPI(router) {
|
|||||||
getBlock(
|
getBlock(
|
||||||
{ hash: req.params.blockHash },
|
{ hash: req.params.blockHash },
|
||||||
{ rawBlock: 1 },
|
{ rawBlock: 1 },
|
||||||
|
MAX_BLOCKS,
|
||||||
(err, block) => {
|
(err, block) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.status(501).send();
|
res.status(501).send();
|
||||||
@ -101,6 +109,7 @@ module.exports = function BlockAPI(router) {
|
|||||||
getBlock(
|
getBlock(
|
||||||
{ height: req.params.height },
|
{ height: req.params.height },
|
||||||
{ hash: 1 },
|
{ hash: 1 },
|
||||||
|
MAX_BLOCKS,
|
||||||
(err, block) => {
|
(err, block) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
res.status(501).send();
|
res.status(501).send();
|
||||||
|
|||||||
@ -34,7 +34,9 @@ function getRate() {
|
|||||||
module.exports = function currencyAPI(app) {
|
module.exports = function currencyAPI(app) {
|
||||||
app.get('/currency', (req, res) => {
|
app.get('/currency', (req, res) => {
|
||||||
res.json({
|
res.json({
|
||||||
bitstamp: lastRate,
|
data: {
|
||||||
|
bitstamp: lastRate,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,18 +1,22 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const config = require('../../config');
|
const config = require('../../config');
|
||||||
|
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const api = express.Router();
|
const api = express.Router();
|
||||||
|
|
||||||
// Serve insight ui front end from root dir public folder
|
// Serve insight ui front end from root dir public folder
|
||||||
app.use('/', express.static('./public'));
|
app.use('/', express.static('./public'));
|
||||||
|
app.use('/blocks', express.static('./public'));
|
||||||
|
app.use('/blocks-date/:date', express.static('./public'));
|
||||||
|
app.use('/block/:blockhash', express.static('./public'));
|
||||||
|
app.use('/tx/:txid', express.static('./public'));
|
||||||
|
app.use('/address/:addr', express.static('./public'));
|
||||||
|
|
||||||
app.set('json spaces', config.api.json_spaces);
|
app.set('json spaces', config.api.json_spaces);
|
||||||
|
|
||||||
// Pass express to register the routes
|
// Pass router to register the routes
|
||||||
const AddressAPI = require('./address')(api);
|
const AddressAPI = require('./address')(api);
|
||||||
const BlockAPI = require('./block') (api);
|
const BlockAPI = require('./block')(api);
|
||||||
const CurrencyAPI = require('./currency')(api);
|
const CurrencyAPI = require('./currency')(api);
|
||||||
const StatusAPI = require('./status')(api);
|
const StatusAPI = require('./status')(api);
|
||||||
const TransactionAPI = require('./transaction')(api);
|
const TransactionAPI = require('./transaction')(api);
|
||||||
|
|||||||
@ -1,10 +1,9 @@
|
|||||||
const io = require('socket.io')
|
|
||||||
|
|
||||||
module.exports = function addressrouter(server) {
|
module.exports = function addressrouter(server) {
|
||||||
io.(server);
|
const io = require('socket.io')(server);
|
||||||
|
|
||||||
io.on('connection', (socket) => {
|
io.on('connection', (socket) => {
|
||||||
console.log(socket);
|
//console.log(socket);
|
||||||
})
|
})
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,5 +1,28 @@
|
|||||||
|
const Block = require('../../models/block.js');
|
||||||
const pkg = require('../../package.json');
|
const pkg = require('../../package.json');
|
||||||
|
|
||||||
|
const logger = require('../logger');
|
||||||
|
|
||||||
|
const MAX_BLOCKS = 200;
|
||||||
|
|
||||||
|
// Not dry, in multiple APIs. Refactor to db api
|
||||||
|
function getBlock(params, options, limit, cb) {
|
||||||
|
const defaultOptions = { _id: 0 };
|
||||||
|
|
||||||
|
if (!Number.isInteger(limit)) {
|
||||||
|
limit = MAX_BLOCKS;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.assign(defaultOptions, options);
|
||||||
|
|
||||||
|
Block.find(
|
||||||
|
params,
|
||||||
|
defaultOptions,
|
||||||
|
cb)
|
||||||
|
.sort({ height: -1 })
|
||||||
|
.limit(limit);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = function statusAPI(router) {
|
module.exports = function statusAPI(router) {
|
||||||
router.get('/status', (req, res) => {
|
router.get('/status', (req, res) => {
|
||||||
res.json({
|
res.json({
|
||||||
@ -21,12 +44,12 @@ module.exports = function statusAPI(router) {
|
|||||||
|
|
||||||
router.get('/sync', (req, res) => {
|
router.get('/sync', (req, res) => {
|
||||||
res.json({
|
res.json({
|
||||||
status: '',
|
status: '',
|
||||||
blockChainHeight: 0,
|
blockChainHeight: 0,
|
||||||
syncPercentage: 0,
|
syncPercentage: 0,
|
||||||
height: 0,
|
height: 0,
|
||||||
error: null,
|
error: null,
|
||||||
type: 'bitcore node',
|
type: 'bitcore node',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
936
package-lock.json
generated
936
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -21,6 +21,7 @@
|
|||||||
"winston": "^2.3.1"
|
"winston": "^2.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"eslint": "^4.4.1",
|
||||||
"eslint-config-airbnb-base": "^11.3.1",
|
"eslint-config-airbnb-base": "^11.3.1",
|
||||||
"eslint-plugin-import": "^2.7.0"
|
"eslint-plugin-import": "^2.7.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,7 +55,7 @@ ScopedSocket.prototype.emit = function(event, data, callback) {
|
|||||||
|
|
||||||
angular.module('insight.socket').factory('getSocket',
|
angular.module('insight.socket').factory('getSocket',
|
||||||
function($rootScope) {
|
function($rootScope) {
|
||||||
var socket = io.connect(null, {
|
var socket = io.connect('/', {
|
||||||
'reconnect': true,
|
'reconnect': true,
|
||||||
'reconnection delay': 500,
|
'reconnection delay': 500,
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user