Skip to content

Commit f61f520

Browse files
authored
Merge pull request mempool#3687 from mempool/simon/backend-block-tip-height-endpoint
Backend block tip height endpoint
2 parents 5628da2 + 864225a commit f61f520

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

backend/src/api/bitcoin/bitcoin.routes.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class BitcoinRoutes {
9494
.get(config.MEMPOOL.API_URL_PREFIX + 'block/:hash', this.getBlock)
9595
.get(config.MEMPOOL.API_URL_PREFIX + 'block/:hash/summary', this.getStrippedBlockTransactions)
9696
.get(config.MEMPOOL.API_URL_PREFIX + 'block/:hash/audit-summary', this.getBlockAuditSummary)
97+
.get(config.MEMPOOL.API_URL_PREFIX + 'blocks/tip/height', this.getBlockTipHeight)
9798
.post(config.MEMPOOL.API_URL_PREFIX + 'psbt/addparents', this.postPsbtCompletion)
9899
.get(config.MEMPOOL.API_URL_PREFIX + 'blocks-bulk/:from', this.getBlocksByBulk.bind(this))
99100
.get(config.MEMPOOL.API_URL_PREFIX + 'blocks-bulk/:from/:to', this.getBlocksByBulk.bind(this))
@@ -110,7 +111,6 @@ class BitcoinRoutes {
110111
.get(config.MEMPOOL.API_URL_PREFIX + 'tx/:txId/status', this.getTransactionStatus)
111112
.get(config.MEMPOOL.API_URL_PREFIX + 'tx/:txId/outspends', this.getTransactionOutspends)
112113
.get(config.MEMPOOL.API_URL_PREFIX + 'block/:hash/header', this.getBlockHeader)
113-
.get(config.MEMPOOL.API_URL_PREFIX + 'blocks/tip/height', this.getBlockTipHeight)
114114
.get(config.MEMPOOL.API_URL_PREFIX + 'blocks/tip/hash', this.getBlockTipHash)
115115
.get(config.MEMPOOL.API_URL_PREFIX + 'block/:hash/raw', this.getRawBlock)
116116
.get(config.MEMPOOL.API_URL_PREFIX + 'block/:hash/txids', this.getTxIdsForBlock)
@@ -589,10 +589,14 @@ class BitcoinRoutes {
589589
}
590590
}
591591

592-
private async getBlockTipHeight(req: Request, res: Response) {
592+
private getBlockTipHeight(req: Request, res: Response) {
593593
try {
594-
const result = await bitcoinApi.$getBlockHeightTip();
595-
res.json(result);
594+
const result = blocks.getCurrentBlockHeight();
595+
if (!result) {
596+
return res.status(503).send(`Service Temporarily Unavailable`);
597+
}
598+
res.setHeader('content-type', 'text/plain');
599+
res.send(result.toString());
596600
} catch (e) {
597601
res.status(500).send(e instanceof Error ? e.message : e);
598602
}

0 commit comments

Comments
 (0)