Merge pull request #2403 from mempool/simon/da-api-handle-error
Fix for difficulty adjustment throwing error before in sync
This commit is contained in:
commit
b36a7a2bcf
@ -510,7 +510,12 @@ class BitcoinRoutes {
|
||||
|
||||
private getDifficultyChange(req: Request, res: Response) {
|
||||
try {
|
||||
res.json(difficultyAdjustment.getDifficultyAdjustment());
|
||||
const da = difficultyAdjustment.getDifficultyAdjustment();
|
||||
if (da) {
|
||||
res.json(da);
|
||||
} else {
|
||||
res.status(503).send(`Service Temporarily Unavailable`);
|
||||
}
|
||||
} catch (e) {
|
||||
res.status(500).send(e instanceof Error ? e.message : e);
|
||||
}
|
||||
|
@ -81,14 +81,15 @@ export function calcDifficultyAdjustment(
|
||||
}
|
||||
|
||||
class DifficultyAdjustmentApi {
|
||||
constructor() { }
|
||||
|
||||
public getDifficultyAdjustment(): IDifficultyAdjustment {
|
||||
public getDifficultyAdjustment(): IDifficultyAdjustment | null {
|
||||
const DATime = blocks.getLastDifficultyAdjustmentTime();
|
||||
const previousRetarget = blocks.getPreviousDifficultyRetarget();
|
||||
const blockHeight = blocks.getCurrentBlockHeight();
|
||||
const blocksCache = blocks.getBlocks();
|
||||
const latestBlock = blocksCache[blocksCache.length - 1];
|
||||
if (!latestBlock) {
|
||||
return null;
|
||||
}
|
||||
const nowSeconds = Math.floor(new Date().getTime() / 1000);
|
||||
|
||||
return calcDifficultyAdjustment(
|
||||
|
Loading…
x
Reference in New Issue
Block a user