* Added difficulty adjustment information API * Added Difficulty API in API docs frontend * Added link to API * Updated the API implementation of difficulty-adjustment * Updated API End Point in frontend * Updated sample API response in frontend
This commit is contained in:
parent
ad08c3a907
commit
9e0a5300b0
3
backend/package-lock.json
generated
3
backend/package-lock.json
generated
@ -2820,8 +2820,7 @@
|
|||||||
"ws": {
|
"ws": {
|
||||||
"version": "7.4.6",
|
"version": "7.4.6",
|
||||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz",
|
"resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz",
|
||||||
"integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==",
|
"integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A=="
|
||||||
"requires": {}
|
|
||||||
},
|
},
|
||||||
"yallist": {
|
"yallist": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
|
@ -248,6 +248,7 @@ class Server {
|
|||||||
.get(config.MEMPOOL.API_URL_PREFIX + 'address/:address/txs', routes.getAddressTransactions)
|
.get(config.MEMPOOL.API_URL_PREFIX + 'address/:address/txs', routes.getAddressTransactions)
|
||||||
.get(config.MEMPOOL.API_URL_PREFIX + 'address/:address/txs/chain/:txId', routes.getAddressTransactions)
|
.get(config.MEMPOOL.API_URL_PREFIX + 'address/:address/txs/chain/:txId', routes.getAddressTransactions)
|
||||||
.get(config.MEMPOOL.API_URL_PREFIX + 'address-prefix/:prefix', routes.getAddressPrefix)
|
.get(config.MEMPOOL.API_URL_PREFIX + 'address-prefix/:prefix', routes.getAddressPrefix)
|
||||||
|
.get(config.MEMPOOL.API_URL_PREFIX + 'difficulty-adjustment', routes.getDifficultyChange)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -666,6 +666,46 @@ class Routes {
|
|||||||
public getTransactionOutspends(req: Request, res: Response) {
|
public getTransactionOutspends(req: Request, res: Response) {
|
||||||
res.status(501).send('Not implemented');
|
res.status(501).send('Not implemented');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getDifficultyChange(req: Request, res: Response) {
|
||||||
|
try {
|
||||||
|
const now = new Date().getTime() / 1000;
|
||||||
|
const DATime=blocks.getLastDifficultyAdjustmentTime();
|
||||||
|
const diff = now - DATime;
|
||||||
|
const blockHeight=blocks.getCurrentBlockHeight();
|
||||||
|
const blocksInEpoch = blockHeight % 2016;
|
||||||
|
const estimatedBlocks = Math.round(diff / 60 / 10);
|
||||||
|
const difficultyChange = (600 / (diff / blocksInEpoch ) - 1) * 100;
|
||||||
|
|
||||||
|
const timeAvgDiff = difficultyChange * 0.1;
|
||||||
|
|
||||||
|
let timeAvgMins = 10;
|
||||||
|
if (timeAvgDiff > 0 ){
|
||||||
|
timeAvgMins -= Math.abs(timeAvgDiff);
|
||||||
|
} else {
|
||||||
|
timeAvgMins += Math.abs(timeAvgDiff);
|
||||||
|
}
|
||||||
|
|
||||||
|
const remainingBlocks = 2016 - blocksInEpoch;
|
||||||
|
const timeAvgSeconds = timeAvgMins * 60;
|
||||||
|
const remainingTime = remainingBlocks * timeAvgSeconds;
|
||||||
|
const estimatedRetargetDate=(remainingTime + now);
|
||||||
|
const totalTime=estimatedRetargetDate-DATime;
|
||||||
|
const progressPercent=100-((remainingTime*100)/totalTime);
|
||||||
|
|
||||||
|
const result={
|
||||||
|
progressPercent,
|
||||||
|
difficultyChange,
|
||||||
|
estimatedRetargetDate,
|
||||||
|
remainingBlocks,
|
||||||
|
remainingTime,
|
||||||
|
}
|
||||||
|
res.json(result);
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
res.status(500).send(e.message || e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new Routes();
|
export default new Routes();
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
{
|
{
|
||||||
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
||||||
|
"cli": {
|
||||||
|
"analytics": "ed0ff723-05da-4a22-b43d-692b797b5243"
|
||||||
|
},
|
||||||
"version": 1,
|
"version": 1,
|
||||||
"newProjectRoot": "projects",
|
"newProjectRoot": "projects",
|
||||||
"projects": {
|
"projects": {
|
||||||
|
@ -823,6 +823,23 @@
|
|||||||
</ng-template>
|
</ng-template>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li *ngIf="network.val !== 'bisq'" [ngbNavItem]="8">
|
||||||
|
<a ngbNavLink i18n="api-docs.tab.difficulty|API Docs tab for Difficulty">Difficulty</a>
|
||||||
|
<ng-template ngbNavContent >
|
||||||
|
<div class="difficulty">
|
||||||
|
<div class="endpoint">
|
||||||
|
<div class="subtitle" i18n="Api docs endpoint">Endpoint</div>
|
||||||
|
<a href="{{ network.val === '' ? '' : '/' + network.val }}/api/difficulty-adjustment" target="_blank">GET {{ network.val === '' ? '' : '/' + network.val }}/api/difficulty-adjustment</a>
|
||||||
|
</div>
|
||||||
|
<div class="description">
|
||||||
|
<div class="subtitle" i18n>Description</div>
|
||||||
|
<div i18n>Returns details about difficulty adjustment.</div>
|
||||||
|
</div>
|
||||||
|
<app-code-template [code]="code.difficulty" [network]="network.val" ></app-code-template>
|
||||||
|
</div>
|
||||||
|
</ng-template>
|
||||||
|
</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<div [ngbNavOutlet]="nav" class="mt-2"></div>
|
<div [ngbNavOutlet]="nav" class="mt-2"></div>
|
||||||
|
@ -69,4 +69,8 @@ li.nav-item {
|
|||||||
}
|
}
|
||||||
.websocket {
|
.websocket {
|
||||||
padding: 15px;
|
padding: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.difficulty {
|
||||||
|
padding: 15px;
|
||||||
}
|
}
|
@ -1125,7 +1125,24 @@ responseSample: `{
|
|||||||
curl: ``,
|
curl: ``,
|
||||||
},
|
},
|
||||||
responseSample: ``,
|
responseSample: ``,
|
||||||
}
|
},
|
||||||
|
|
||||||
|
difficulty: {
|
||||||
|
codeSample: {
|
||||||
|
esModule:``,
|
||||||
|
commonJS:``,
|
||||||
|
curl: `curl -X GET "https://mempool.space/api/difficulty-adjustment"`,
|
||||||
|
},
|
||||||
|
responseSample: `{
|
||||||
|
progressPercent: 18.55392610846515,
|
||||||
|
difficultyChange: -1.2440503501069622,
|
||||||
|
estimatedRetargetDate: 1627400849.2000492,
|
||||||
|
remainingBlocks: 1642,
|
||||||
|
remainingTime: 997456.3840492539
|
||||||
|
|
||||||
|
}`,
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -71,6 +71,10 @@ li.nav-item {
|
|||||||
padding: 15px;
|
padding: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.difficulty {
|
||||||
|
padding: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
.links {
|
.links {
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
a {
|
a {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user