sync, status and last block hash finished
This commit is contained in:
parent
4b71ae91ae
commit
69538704f6
@ -116,7 +116,6 @@ module.exports = function BlockAPI(router) {
|
|||||||
res.status(501).send();
|
res.status(501).send();
|
||||||
logger.log('err', err);
|
logger.log('err', err);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block[0]) {
|
if (block[0]) {
|
||||||
res.json({
|
res.json({
|
||||||
blockHash: block[0].hash,
|
blockHash: block[0].hash,
|
||||||
|
|||||||
@ -10,10 +10,12 @@ app.use(cors);
|
|||||||
// 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', express.static('./public'));
|
||||||
|
app.use('/block-index', express.static('./public'));
|
||||||
app.use('/blocks-date/:date', express.static('./public'));
|
app.use('/blocks-date/:date', express.static('./public'));
|
||||||
app.use('/block/:blockhash', express.static('./public'));
|
app.use('/block/:blockhash', express.static('./public'));
|
||||||
app.use('/tx/:txid', express.static('./public'));
|
app.use('/tx/:txid', express.static('./public'));
|
||||||
app.use('/address/:addr', express.static('./public'));
|
app.use('/address/:addr', express.static('./public'));
|
||||||
|
app.use('/status', express.static('./public'));
|
||||||
|
|
||||||
app.set('json spaces', config.api.json_spaces);
|
app.set('json spaces', config.api.json_spaces);
|
||||||
|
|
||||||
|
|||||||
@ -1,34 +1,87 @@
|
|||||||
|
const request = require('request');
|
||||||
|
const Block = require('../../models/block');
|
||||||
const pkg = require('../../package.json');
|
const pkg = require('../../package.json');
|
||||||
|
const config = require('../../config');
|
||||||
|
const netCfg = require('bcoin/lib/net/common');
|
||||||
const logger = require('../logger');
|
const logger = require('../logger');
|
||||||
|
|
||||||
|
// Here comes the ugly. Moo who haha
|
||||||
|
function getStatus(cb) {
|
||||||
|
request(`http://${config.bcoin_http}:${config.bcoin['http-port']}/`, (err, localRes, body) => {
|
||||||
|
if (err) {
|
||||||
|
logger.log('error',
|
||||||
|
`${err}`);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
body = JSON.parse(body);
|
||||||
|
} catch (e) {
|
||||||
|
logger.log('error',
|
||||||
|
`${err}`);
|
||||||
|
cb(e);
|
||||||
|
}
|
||||||
|
cb(null, body);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = function statusAPI(router) {
|
module.exports = function statusAPI(router) {
|
||||||
router.get('/status', (req, res) => {
|
router.get('/status', (req, res) => {
|
||||||
res.json({
|
if (req.query.q === 'getLastBlockHash') {
|
||||||
info: {
|
Block.findOne({}, { 'hash': 1 }, { sort: { 'height': -1 } }, (err, block) => {
|
||||||
version: 0,
|
if (err) {
|
||||||
protocolversion: 0,
|
logger.log('error',
|
||||||
blocks: 0,
|
`${err}`);
|
||||||
timeoffset: 0,
|
res.status(501).send(err);
|
||||||
connections: 0,
|
} else {
|
||||||
proxy: '',
|
res.send({
|
||||||
difficulty: 0,
|
syncTipHash: block.hash,
|
||||||
testnet: false,
|
lastblockhash: block.hash,
|
||||||
relayfee: 0,
|
});
|
||||||
errors: '',
|
}
|
||||||
network: 'main',
|
});
|
||||||
},
|
} else {
|
||||||
});
|
getStatus((err, status) => {
|
||||||
|
if (err) {
|
||||||
|
res.status(501).send(err);
|
||||||
|
} else if (status) {
|
||||||
|
res.json({
|
||||||
|
info: {
|
||||||
|
version: status.version,
|
||||||
|
protocolversion: netCfg.PROTOCOL_VERSION,
|
||||||
|
blocks: status.chain.height,
|
||||||
|
timeoffset: status.time.offset,
|
||||||
|
connections: status.pool.outbound,
|
||||||
|
proxy: '',
|
||||||
|
difficulty: 0,
|
||||||
|
testnet: status.network !== 'main',
|
||||||
|
relayfee: 0,
|
||||||
|
errors: '',
|
||||||
|
network: status.network,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.send();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/sync', (req, res) => {
|
router.get('/sync', (req, res) => {
|
||||||
res.json({
|
getStatus((err, status) => {
|
||||||
status: '',
|
if (err) {
|
||||||
blockChainHeight: 0,
|
res.status(501).send(err);
|
||||||
syncPercentage: 0,
|
} else if (status) {
|
||||||
height: 0,
|
res.json({
|
||||||
error: null,
|
status: 'syncing',
|
||||||
type: 'bitcore node',
|
blockChainHeight: status.chain.height,
|
||||||
|
syncPercentage: Math.round(status.chain.progress * 100),
|
||||||
|
height: status.chain.height,
|
||||||
|
error: null,
|
||||||
|
type: 'bcoin node',
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
res.send();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user