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.
|
||||
|
||||
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
|
||||
```
|
||||
@ -53,6 +53,8 @@ https://docs.google.com/a/bit-pay.com/spreadsheets/d/1hDlf16F6zAxBrOC3ZdnvfRrSB9
|
||||
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
|
||||
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
|
||||
* Reorg testing - Bcoin will handle this but we need to account for this in our mongo indexes.
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
const config = {
|
||||
start_node: true,
|
||||
start_node: false,
|
||||
logging: 'debug',
|
||||
bcoin: {
|
||||
network: 'main',
|
||||
@ -17,7 +17,7 @@ const config = {
|
||||
},
|
||||
},
|
||||
api: {
|
||||
port: 80,
|
||||
port: 3000,
|
||||
json_spaces: 2,
|
||||
currency_refresh: 60,
|
||||
ticker_url: 'https://www.bitstamp.net/api/ticker/',
|
||||
|
||||
@ -3,9 +3,13 @@ const logger = require('../logger');
|
||||
|
||||
const MAX_BLOCKS = 200;
|
||||
|
||||
function getBlock(params, options, cb) {
|
||||
function getBlock(params, options, limit, cb) {
|
||||
const defaultOptions = { _id: 0 };
|
||||
|
||||
if (!Number.isInteger(limit)) {
|
||||
limit = MAX_BLOCKS;
|
||||
}
|
||||
|
||||
Object.assign(defaultOptions, options);
|
||||
|
||||
Block.find(
|
||||
@ -13,7 +17,7 @@ function getBlock(params, options, cb) {
|
||||
defaultOptions,
|
||||
cb)
|
||||
.sort({ height: -1 })
|
||||
.limit(MAX_BLOCKS);
|
||||
.limit(limit);
|
||||
}
|
||||
|
||||
module.exports = function BlockAPI(router) {
|
||||
@ -21,6 +25,7 @@ module.exports = function BlockAPI(router) {
|
||||
getBlock(
|
||||
{ hash: req.params.blockHash },
|
||||
{ rawBlock: 0 },
|
||||
MAX_BLOCKS,
|
||||
(err, block) => {
|
||||
if (err) {
|
||||
res.status(501).send();
|
||||
@ -54,6 +59,8 @@ module.exports = function BlockAPI(router) {
|
||||
});
|
||||
|
||||
router.get('/blocks', (req, res) => {
|
||||
const limit = parseInt(req.query.limit) || MAX_BLOCKS;
|
||||
|
||||
getBlock(
|
||||
{},
|
||||
{ height: 1,
|
||||
@ -61,23 +68,23 @@ module.exports = function BlockAPI(router) {
|
||||
hash: 1,
|
||||
ts: 1,
|
||||
txs: 1,
|
||||
poolInfo: 1 },
|
||||
poolInfo: 1,
|
||||
},
|
||||
limit,
|
||||
(err, blocks) => {
|
||||
if (err) {
|
||||
res.status(501).send();
|
||||
logger.log('err', err);
|
||||
}
|
||||
res.json({
|
||||
blocks: blocks.map((block) => {
|
||||
return {
|
||||
hash: block.hash,
|
||||
height: block.height,
|
||||
size: block.size,
|
||||
time: block.ts,
|
||||
txlength: block.txs.length,
|
||||
poolInfo: {},
|
||||
};
|
||||
}),
|
||||
blocks: blocks.map(block => ({
|
||||
hash: block.hash,
|
||||
height: block.height,
|
||||
size: block.size,
|
||||
time: block.ts,
|
||||
txlength: block.txs.length,
|
||||
poolInfo: {},
|
||||
})),
|
||||
length: blocks.length,
|
||||
pagination: {},
|
||||
});
|
||||
@ -88,6 +95,7 @@ module.exports = function BlockAPI(router) {
|
||||
getBlock(
|
||||
{ hash: req.params.blockHash },
|
||||
{ rawBlock: 1 },
|
||||
MAX_BLOCKS,
|
||||
(err, block) => {
|
||||
if (err) {
|
||||
res.status(501).send();
|
||||
@ -101,6 +109,7 @@ module.exports = function BlockAPI(router) {
|
||||
getBlock(
|
||||
{ height: req.params.height },
|
||||
{ hash: 1 },
|
||||
MAX_BLOCKS,
|
||||
(err, block) => {
|
||||
if (err) {
|
||||
res.status(501).send();
|
||||
|
||||
@ -34,7 +34,9 @@ function getRate() {
|
||||
module.exports = function currencyAPI(app) {
|
||||
app.get('/currency', (req, res) => {
|
||||
res.json({
|
||||
bitstamp: lastRate,
|
||||
data: {
|
||||
bitstamp: lastRate,
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@ -1,18 +1,22 @@
|
||||
const express = require('express');
|
||||
const config = require('../../config');
|
||||
|
||||
|
||||
const app = express();
|
||||
const api = express.Router();
|
||||
|
||||
// Serve insight ui front end from root dir public folder
|
||||
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);
|
||||
|
||||
// Pass express to register the routes
|
||||
// Pass router to register the routes
|
||||
const AddressAPI = require('./address')(api);
|
||||
const BlockAPI = require('./block') (api);
|
||||
const BlockAPI = require('./block')(api);
|
||||
const CurrencyAPI = require('./currency')(api);
|
||||
const StatusAPI = require('./status')(api);
|
||||
const TransactionAPI = require('./transaction')(api);
|
||||
|
||||
@ -1,10 +1,9 @@
|
||||
const io = require('socket.io')
|
||||
|
||||
module.exports = function addressrouter(server) {
|
||||
io.(server);
|
||||
const io = require('socket.io')(server);
|
||||
|
||||
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 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) {
|
||||
router.get('/status', (req, res) => {
|
||||
res.json({
|
||||
@ -21,12 +44,12 @@ module.exports = function statusAPI(router) {
|
||||
|
||||
router.get('/sync', (req, res) => {
|
||||
res.json({
|
||||
status: '',
|
||||
status: '',
|
||||
blockChainHeight: 0,
|
||||
syncPercentage: 0,
|
||||
height: 0,
|
||||
error: null,
|
||||
type: 'bitcore node',
|
||||
syncPercentage: 0,
|
||||
height: 0,
|
||||
error: null,
|
||||
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"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^4.4.1",
|
||||
"eslint-config-airbnb-base": "^11.3.1",
|
||||
"eslint-plugin-import": "^2.7.0"
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ ScopedSocket.prototype.emit = function(event, data, callback) {
|
||||
|
||||
angular.module('insight.socket').factory('getSocket',
|
||||
function($rootScope) {
|
||||
var socket = io.connect(null, {
|
||||
var socket = io.connect('/', {
|
||||
'reconnect': true,
|
||||
'reconnection delay': 500,
|
||||
});
|
||||
|
||||
Loading…
Reference in New Issue
Block a user