getBestHeight added to db api
This commit is contained in:
parent
3b8b900405
commit
2f4533e057
@ -8,7 +8,7 @@ module.exports = function AddressAPI(router) {
|
||||
router.get('/addr/:addr', (req, res) => {
|
||||
const addr = req.params.addr || '';
|
||||
// Get Bcoin data
|
||||
request(`${API_URL}/tx/address/${addr}`,
|
||||
return request(`${API_URL}/tx/address/${addr}`,
|
||||
(error, bcoinRes, txs) => {
|
||||
if (error) {
|
||||
logger.log('error',
|
||||
@ -41,17 +41,17 @@ module.exports = function AddressAPI(router) {
|
||||
|
||||
// Match Insight API
|
||||
return res.json({
|
||||
addrStr: req.params.addr,
|
||||
balance: (totalReceived - totalSpent) / 1e8,
|
||||
balanceSat: totalReceived - totalSpent,
|
||||
totalReceived: totalReceived / 1e8,
|
||||
totalReceivedSat: totalReceived,
|
||||
totalSent: totalSpent / 1e8,
|
||||
totalSentSat: totalSpent,
|
||||
unconfirmedBalance: 0,
|
||||
unconfirmedBalanceSat: 0,
|
||||
addrStr: req.params.addr,
|
||||
balance: (totalReceived - totalSpent) / 1e8,
|
||||
balanceSat: totalReceived - totalSpent,
|
||||
totalReceived: totalReceived / 1e8,
|
||||
totalReceivedSat: totalReceived,
|
||||
totalSent: totalSpent / 1e8,
|
||||
totalSentSat: totalSpent,
|
||||
unconfirmedBalance: 0,
|
||||
unconfirmedBalanceSat: 0,
|
||||
unconfirmedTxApperances: 0,
|
||||
txApperances: txs.length,
|
||||
txApperances: txs.length,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -16,6 +16,7 @@ setInterval(() => {
|
||||
getRate();
|
||||
}, refreshInterval);
|
||||
|
||||
// Make the request to the remote API
|
||||
function getRate() {
|
||||
request(config.api.ticker_url, (err, res, body) => {
|
||||
if (err) {
|
||||
|
||||
@ -7,9 +7,7 @@ const api = express.Router();
|
||||
const cors = require('./cors');
|
||||
|
||||
app.use(cors);
|
||||
|
||||
app.use(bodyParser.urlencoded({ extended: false }))
|
||||
|
||||
app.use(bodyParser.urlencoded({ extended: false }));
|
||||
app.use(bodyParser.json());
|
||||
|
||||
// Serve insight ui front end from root dir public folder
|
||||
@ -47,6 +45,7 @@ app.use((req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
// Socket server
|
||||
const server = require('http').Server(app);
|
||||
const io = require('socket.io')(server);
|
||||
|
||||
|
||||
@ -10,10 +10,7 @@ module.exports = function transactionAPI(router) {
|
||||
// Txs by txid
|
||||
router.get('/tx/:txid', (req, res) => {
|
||||
// Get max block height for calculating confirmations
|
||||
db.blocks.getBlock(
|
||||
{},
|
||||
{ height: 1 },
|
||||
1,
|
||||
db.blocks.getBestHeight(
|
||||
(err, block) => {
|
||||
if (err) {
|
||||
logger.log('err', err);
|
||||
@ -22,7 +19,7 @@ module.exports = function transactionAPI(router) {
|
||||
|
||||
const height = block.height;
|
||||
// Bcoin transaction data
|
||||
request(`${API_URL}/tx/${req.params.txid}`, (error, localRes, tx) => {
|
||||
return request(`${API_URL}/tx/${req.params.txid}`, (error, localRes, tx) => {
|
||||
if (error) {
|
||||
logger.log('error',
|
||||
`${error}`);
|
||||
@ -73,10 +70,7 @@ module.exports = function transactionAPI(router) {
|
||||
const rangeEnd = rangeStart + MAX_TXS;
|
||||
// get txs for blockhash
|
||||
if (req.query.block) {
|
||||
db.blocks.getBlock(
|
||||
{},
|
||||
{ height: 1 },
|
||||
1,
|
||||
db.blocks.getBestHeight(
|
||||
(err, block) => {
|
||||
if (err) {
|
||||
logger.log('err', err);
|
||||
@ -84,7 +78,7 @@ module.exports = function transactionAPI(router) {
|
||||
}
|
||||
const height = block.height;
|
||||
// Get Bcoin data
|
||||
request(`${API_URL}/block/${req.query.block}`, (error, localRes, block) => {
|
||||
return request(`${API_URL}/block/${req.query.block}`, (error, localRes, block) => {
|
||||
if (error) {
|
||||
logger.log('error',
|
||||
`${error}`);
|
||||
@ -129,9 +123,6 @@ module.exports = function transactionAPI(router) {
|
||||
} else if (req.query.address) {
|
||||
// Get txs by address
|
||||
db.blocks.getBestHeight(
|
||||
{},
|
||||
{ height: 1 },
|
||||
1,
|
||||
(err, block) => {
|
||||
if (err) {
|
||||
logger.log('err', err);
|
||||
@ -141,7 +132,7 @@ module.exports = function transactionAPI(router) {
|
||||
const height = block.height;
|
||||
const addr = req.query.address || '';
|
||||
|
||||
request(`${API_URL}/tx/address/${req.query.address}`, (error, localRes, txs) => {
|
||||
return request(`${API_URL}/tx/address/${req.query.address}`, (error, localRes, txs) => {
|
||||
if (error) {
|
||||
logger.log('error',
|
||||
`${error}`);
|
||||
|
||||
@ -53,7 +53,7 @@ function getBlock(params, options, limit, cb) {
|
||||
return cb(null, blocks[0]);
|
||||
});
|
||||
}
|
||||
|
||||
// Highest known height
|
||||
function getBestHeight(cb) {
|
||||
getBlock({}, {}, 1, (err, block) => {
|
||||
if (err) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user