commit-for-socket-changes
This commit is contained in:
parent
ca33a47c0c
commit
cc6ae71814
@ -46,6 +46,7 @@
|
||||
"pg-native": "^3.0.0",
|
||||
"plotly.js": "^1.48.3",
|
||||
"rxjs": "~6.4.0",
|
||||
"socket.io": "^2.2.0",
|
||||
"socket.io-client": "^2.2.0",
|
||||
"swagger-jsdoc": "^3.2.9",
|
||||
"tslib": "^1.9.0",
|
||||
|
@ -45,6 +45,7 @@ import {
|
||||
BlockchainKernelController,
|
||||
BlockchainOutputController
|
||||
} from "./server/controllers";
|
||||
import { universalGetLatestBlockDetails } from "./server/socket";
|
||||
import { dbConfig } from "./server/ormconfig";
|
||||
import { config } from "dotenv";
|
||||
|
||||
@ -128,9 +129,13 @@ app.get("*", (req, res) => {
|
||||
connection
|
||||
.connect()
|
||||
.then(() => {
|
||||
app.listen(PORT, () => {
|
||||
const server = app.listen(PORT, () => {
|
||||
console.log(`Node Express server listening on http://localhost:${PORT}`);
|
||||
});
|
||||
const io = require("socket.io").listen(server);
|
||||
io.sockets.on("connection", socket => {
|
||||
universalGetLatestBlockDetails(socket);
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.log("connection failed..", error);
|
||||
|
160
server/socket/block.ts
Normal file
160
server/socket/block.ts
Normal file
@ -0,0 +1,160 @@
|
||||
import { getConnection } from "typeorm";
|
||||
const moment = require("moment");
|
||||
|
||||
export async function universalGetLatestBlockDetails(socket) {
|
||||
let block_height = "",
|
||||
letest_block = "",
|
||||
letest_block_num = "",
|
||||
letest_block_duration = "";
|
||||
|
||||
const BlockchainLatestBlockQuery = await getConnection().query(
|
||||
"SELECT timestamp,height,edge_bits,hash,secondary_scaling, previous_id, total_difficulty_cuckaroo, total_difficulty_cuckatoo, total_difficulty_progpow, total_difficulty_randomx FROM blockchain_block ORDER BY timestamp DESC LIMIT 1"
|
||||
);
|
||||
const BlockchainPreviousBlockQuery = await getConnection().query(
|
||||
"SELECT total_difficulty_cuckaroo, total_difficulty_cuckatoo, total_difficulty_progpow, total_difficulty_randomx FROM blockchain_block WHERE hash=" +
|
||||
"'" +
|
||||
BlockchainLatestBlockQuery[0].previous_id +
|
||||
"'"
|
||||
);
|
||||
let height = BlockchainLatestBlockQuery[0].height;
|
||||
|
||||
if (height > 12960) {
|
||||
var remain_block = height - 12960;
|
||||
var coin_existence =
|
||||
1440 * 200 +
|
||||
1440 * 180 +
|
||||
1440 * 160 +
|
||||
1440 * 140 +
|
||||
1440 * 120 +
|
||||
1440 * 100 +
|
||||
1440 * 80 +
|
||||
1440 * 60 +
|
||||
1440 * 50 +
|
||||
25 * remain_block;
|
||||
} else if (height > 11520) {
|
||||
var remain_block = height - 11520;
|
||||
var coin_existence =
|
||||
1440 * 200 +
|
||||
1440 * 180 +
|
||||
1440 * 160 +
|
||||
1440 * 140 +
|
||||
1440 * 120 +
|
||||
1440 * 100 +
|
||||
1440 * 80 +
|
||||
1440 * 60 +
|
||||
remain_block * 50;
|
||||
} else if (height > 10080) {
|
||||
var remain_block = height - 10080;
|
||||
var coin_existence =
|
||||
1440 * 200 +
|
||||
1440 * 180 +
|
||||
1440 * 160 +
|
||||
1440 * 140 +
|
||||
1440 * 120 +
|
||||
1440 * 100 +
|
||||
1440 * 80 +
|
||||
remain_block * 60;
|
||||
} else if (height > 8640) {
|
||||
var remain_block = height - 8640;
|
||||
var coin_existence =
|
||||
1440 * 200 +
|
||||
1440 * 180 +
|
||||
1440 * 160 +
|
||||
1440 * 140 +
|
||||
1440 * 120 +
|
||||
1440 * 100 +
|
||||
remain_block * 80;
|
||||
} else if (height > 7200) {
|
||||
var remain_block = height - 7200;
|
||||
var coin_existence =
|
||||
1440 * 200 +
|
||||
1440 * 180 +
|
||||
1440 * 160 +
|
||||
1440 * 140 +
|
||||
1440 * 120 +
|
||||
remain_block * 100;
|
||||
} else if (height > 5760) {
|
||||
var remain_block = height - 5760;
|
||||
var coin_existence =
|
||||
1440 * 200 + 1440 * 180 + 1440 * 160 + 1440 * 140 + remain_block * 120;
|
||||
} else if (height > 4320) {
|
||||
var remain_block = height - 4320;
|
||||
var coin_existence =
|
||||
1440 * 200 + 1440 * 180 + 1440 * 160 + remain_block * 140;
|
||||
} else if (height > 2880) {
|
||||
var remain_block = height - 2880;
|
||||
var coin_existence = 1440 * 200 + 1440 * 180 + remain_block * 160;
|
||||
} else if (height > 1440) {
|
||||
var remain_block = height - 1440;
|
||||
var coin_existence = 1440 * 200 + remain_block * 180;
|
||||
} else {
|
||||
var coin_existence = height * 200;
|
||||
}
|
||||
|
||||
letest_block = moment(BlockchainLatestBlockQuery[0].timestamp).fromNow();
|
||||
letest_block_num = letest_block.substr(0, letest_block.indexOf(" ")); // "72"
|
||||
letest_block_duration = letest_block.substr(letest_block.indexOf(" ") + 1); // "tocirah sneab"
|
||||
const SECOND_POW_EDGE_BITS = 29;
|
||||
const BASE_EDGE_BITS = 24;
|
||||
|
||||
if (BlockchainLatestBlockQuery[0].edge_bits == SECOND_POW_EDGE_BITS) {
|
||||
var hashvalue = BlockchainLatestBlockQuery[0].hash;
|
||||
var diff =
|
||||
(BlockchainLatestBlockQuery[0].secondary_scaling * 2 ** 64) /
|
||||
parseInt(hashvalue.substring(0, 16), 16);
|
||||
var result = Math.min(diff, 0xffffffffffffffff);
|
||||
var difficulty = Math.round(result);
|
||||
} else {
|
||||
var graph_weight =
|
||||
2 *
|
||||
2 ** (BlockchainLatestBlockQuery[0].edge_bits - BASE_EDGE_BITS) *
|
||||
BlockchainLatestBlockQuery[0].edge_bits;
|
||||
var hashvalue = BlockchainLatestBlockQuery[0].hash;
|
||||
var diff =
|
||||
(graph_weight * 2 ** 64) / parseInt(hashvalue.substring(0, 16), 16);
|
||||
var result = Math.min(diff, 0xffffffffffffffff);
|
||||
var difficulty = Math.round(result);
|
||||
}
|
||||
|
||||
if (BlockchainLatestBlockQuery[0].previous_id) {
|
||||
var targetdifficultycuckaroo =
|
||||
BlockchainLatestBlockQuery[0].total_difficulty_cuckaroo -
|
||||
BlockchainPreviousBlockQuery[0].total_difficulty_cuckaroo;
|
||||
var targetdifficultycuckatoo =
|
||||
BlockchainLatestBlockQuery[0].total_difficulty_cuckatoo -
|
||||
BlockchainPreviousBlockQuery[0].total_difficulty_cuckatoo;
|
||||
var targetdifficultyprogpow =
|
||||
BlockchainLatestBlockQuery[0].total_difficulty_progpow -
|
||||
BlockchainPreviousBlockQuery[0].total_difficulty_progpow;
|
||||
var targetdifficultyrandomx =
|
||||
BlockchainLatestBlockQuery[0].total_difficulty_randomx -
|
||||
BlockchainPreviousBlockQuery[0].total_difficulty_randomx;
|
||||
}
|
||||
|
||||
block_height = BlockchainLatestBlockQuery[0].height;
|
||||
var TotalCuckoo =
|
||||
parseInt(BlockchainLatestBlockQuery[0].total_difficulty_cuckatoo) +
|
||||
parseInt(BlockchainLatestBlockQuery[0].total_difficulty_cuckaroo);
|
||||
|
||||
socket.emit("latestblockdetail", {
|
||||
block_height,
|
||||
letest_block,
|
||||
letest_block_num,
|
||||
letest_block_duration,
|
||||
coin_existence,
|
||||
difficulty,
|
||||
targetdifficultycuckaroo,
|
||||
targetdifficultycuckatoo,
|
||||
targetdifficultyprogpow,
|
||||
targetdifficultyrandomx,
|
||||
TotalCuckoo,
|
||||
TotalDifficultyCuckaroo:
|
||||
BlockchainLatestBlockQuery[0].total_difficulty_cuckaroo,
|
||||
TotalDifficultyCuckatoo:
|
||||
BlockchainLatestBlockQuery[0].total_difficulty_cuckatoo,
|
||||
TotalDifficultyProgpow:
|
||||
BlockchainLatestBlockQuery[0].total_difficulty_progpow,
|
||||
TotalDifficultyRandomx:
|
||||
BlockchainLatestBlockQuery[0].total_difficulty_randomx
|
||||
});
|
||||
}
|
1
server/socket/index.ts
Normal file
1
server/socket/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from "./block";
|
@ -1,53 +1,53 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Injectable } from "@angular/core";
|
||||
import {
|
||||
HttpClient,
|
||||
HttpErrorResponse,
|
||||
HttpHeaders,
|
||||
} from '@angular/common/http';
|
||||
import { environment } from '../../../environments/environment';
|
||||
import { throwError, Observable, BehaviorSubject } from 'rxjs';
|
||||
import { map, catchError } from 'rxjs/operators';
|
||||
// import * as io from 'socket.io-client';
|
||||
HttpHeaders
|
||||
} from "@angular/common/http";
|
||||
import { environment } from "../../../environments/environment";
|
||||
import { throwError, Observable, BehaviorSubject } from "rxjs";
|
||||
import { map, catchError } from "rxjs/operators";
|
||||
import * as io from "socket.io-client";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
providedIn: "root"
|
||||
})
|
||||
export class ChartService {
|
||||
private server = environment.domain;
|
||||
private server = environment.domain;
|
||||
private socket;
|
||||
|
||||
|
||||
constructor(public http: HttpClient) {}
|
||||
|
||||
// public createSocketConnection() {
|
||||
// this.socket = io.connect(this.server);
|
||||
// this.socket.on('connect', function(socket) {
|
||||
// console.log('Connected!');
|
||||
// });
|
||||
// }
|
||||
|
||||
public createSocketConnection() {
|
||||
this.socket = io.connect(this.server);
|
||||
this.socket.on("connect", function(socket) {
|
||||
console.log("Connected!");
|
||||
});
|
||||
}
|
||||
|
||||
public apiGetRequest(request: any, reqUrl): Observable<any> {
|
||||
return this.http
|
||||
.get(`${environment.apiUrl}` + reqUrl, {
|
||||
params: request,
|
||||
params: request
|
||||
})
|
||||
.pipe(
|
||||
map(res => {
|
||||
return res;
|
||||
}),
|
||||
catchError((error: HttpErrorResponse): any => throwError(error)),
|
||||
catchError((error: HttpErrorResponse): any => throwError(error))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public getLatestblockdetails() {
|
||||
return Observable.create(observer => {
|
||||
this.socket.on('latestblockdetail', response => {
|
||||
this.socket.on("latestblockdetail", response => {
|
||||
observer.next(response);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public GetTimer() {
|
||||
var countDownDate = new Date('Aug 1, 2019 00:00:00').getTime();
|
||||
|
||||
public GetTimer() {
|
||||
var countDownDate = new Date("Aug 1, 2019 00:00:00").getTime();
|
||||
|
||||
// Get today's date and time
|
||||
var now = new Date().getTime();
|
||||
@ -58,7 +58,7 @@ private server = environment.domain;
|
||||
// Time calculations for days, hours, minutes and seconds
|
||||
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
|
||||
var hours = Math.floor(
|
||||
(distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60),
|
||||
(distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)
|
||||
);
|
||||
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
|
||||
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
|
||||
@ -68,5 +68,4 @@ private server = environment.domain;
|
||||
let timerarr = { d: days, h: hours, m: minutes, s: seconds };
|
||||
return timerarr;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,36 +26,71 @@
|
||||
</div> -->
|
||||
<div class="row" *ngIf="latestblockdetail">
|
||||
<div class="col-md-3">
|
||||
<div class="text-center detail_div" [ngStyle]="{'min-height.px': minHeight}">
|
||||
<p class="mb-0 desc">{{'home.BLOCKCHAIN_HEIGHT' | translate}}</p>
|
||||
<p class="count mb-0">{{ latestblockdetail.block_height | number }}</p>
|
||||
|
||||
<div
|
||||
class="text-center detail_div"
|
||||
[ngStyle]="{ 'min-height.px': minHeight }"
|
||||
>
|
||||
<p class="mb-0 desc">{{ "home.BLOCKCHAIN_HEIGHT" | translate }}</p>
|
||||
<p
|
||||
class="count mb-0"
|
||||
[ngClass]="latestblockdetail.blink == true ? 'item-highlight' : ''"
|
||||
>
|
||||
{{ latestblockdetail.block_height | number }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="text-center detail_div" [ngStyle]="{'min-height.px': minHeight}">
|
||||
<p class="mb-0 desc">{{'home.LATEST_BLOCK' | translate}}</p>
|
||||
<p class="count mb-0">{{latestblockdetail.letest_block_num}} <span class="">{{latestblockdetail.letest_block_duration}}</span></p>
|
||||
|
||||
<div
|
||||
class="text-center detail_div"
|
||||
[ngStyle]="{ 'min-height.px': minHeight }"
|
||||
>
|
||||
<p class="mb-0 desc">{{ "home.LATEST_BLOCK" | translate }}</p>
|
||||
<p
|
||||
class="count mb-0"
|
||||
[ngClass]="latestblockdetail.blink == true ? 'item-highlight' : ''"
|
||||
>
|
||||
{{ latestblockdetail.letest_block_num }}
|
||||
<span class="">{{ latestblockdetail.letest_block_duration }}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="text-center detail_div" #minhgt>
|
||||
<p class="mb-2 desc">{{'home.LATEST_BLOCK1' | translate}}</p>
|
||||
<div class=" text-left d-inline-block" title="Target / Total Block Difficulty">
|
||||
<p class="mb-2 desc">{{ "home.LATEST_BLOCK1" | translate }}</p>
|
||||
<div
|
||||
class=" text-left d-inline-block"
|
||||
title="Target / Total Block Difficulty"
|
||||
[ngClass]="latestblockdetail.blink == true ? 'item-highlight' : ''"
|
||||
>
|
||||
<!-- <p class="difficulty_datas">Cuckaroo : {{latestblockdetail.targetdifficultycuckaroo | number}} / {{latestblockdetail.TotalDifficultyCuckatoo | number}}</p> -->
|
||||
<p class="difficulty_datas">Cuckoo : {{latestblockdetail.targetdifficultycuckatoo | number}} / {{latestblockdetail.TotalDifficultyCuckatoo | number}}</p>
|
||||
<p class="difficulty_datas">ProgPow : {{latestblockdetail.targetdifficultyprogpow | number}} / {{latestblockdetail.TotalDifficultyProgpow | number}}</p>
|
||||
<p class="difficulty_datas">RandomX : {{latestblockdetail.targetdifficultyrandomx | number}} / {{latestblockdetail.TotalDifficultyRandomx | number}}</p>
|
||||
</div>
|
||||
|
||||
<p class="difficulty_datas">
|
||||
Cuckoo : {{ latestblockdetail.targetdifficultycuckatoo | number }} /
|
||||
{{ latestblockdetail.TotalDifficultyCuckatoo | number }}
|
||||
</p>
|
||||
<p class="difficulty_datas">
|
||||
ProgPow : {{ latestblockdetail.targetdifficultyprogpow | number }} /
|
||||
{{ latestblockdetail.TotalDifficultyProgpow | number }}
|
||||
</p>
|
||||
<p class="difficulty_datas">
|
||||
RandomX : {{ latestblockdetail.targetdifficultyrandomx | number }} /
|
||||
{{ latestblockdetail.TotalDifficultyRandomx | number }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="text-center detail_div" [ngStyle]="{'min-height.px': minHeight}">
|
||||
<p class="mb-0 desc">{{'home.COIN_IN' | translate}}</p>
|
||||
<p class="count mb-0">{{latestblockdetail.coin_existence | number}} <span class="">Epic</span></p>
|
||||
|
||||
<div
|
||||
class="text-center detail_div"
|
||||
[ngStyle]="{ 'min-height.px': minHeight }"
|
||||
>
|
||||
<p class="mb-0 desc">{{ "home.COIN_IN" | translate }}</p>
|
||||
<p
|
||||
class="count mb-0"
|
||||
[ngClass]="latestblockdetail.blink == true ? 'item-highlight' : ''"
|
||||
>
|
||||
{{ latestblockdetail.coin_existence | number }}
|
||||
<span class="">Epic</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,15 +1,15 @@
|
||||
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
|
||||
import { ChartService } from '../../../shared/services/chart.service';
|
||||
import { HttpParams } from '@angular/common/http';
|
||||
import * as io from 'socket.io-client';
|
||||
import { environment } from '../../../../environments/environment';
|
||||
import { BehaviorSubject, Observable, Subject } from 'rxjs';
|
||||
import { TransServiceService } from '../../../shared/services/trans-service.service';
|
||||
import { Component, OnInit, ViewChild, ElementRef } from "@angular/core";
|
||||
import { ChartService } from "../../../shared/services/chart.service";
|
||||
import { HttpParams } from "@angular/common/http";
|
||||
import * as io from "socket.io-client";
|
||||
import { environment } from "../../../../environments/environment";
|
||||
import { BehaviorSubject, Observable, Subject } from "rxjs";
|
||||
import { TransServiceService } from "../../../shared/services/trans-service.service";
|
||||
|
||||
@Component({
|
||||
selector: 'app-block-detail-list',
|
||||
templateUrl: './block-detail-list.component.html',
|
||||
styleUrls: ['./block-detail-list.component.css'],
|
||||
selector: "app-block-detail-list",
|
||||
templateUrl: "./block-detail-list.component.html",
|
||||
styleUrls: ["./block-detail-list.component.css"]
|
||||
})
|
||||
export class BlockDetailListComponent implements OnInit {
|
||||
public latestblockdetail: any = [];
|
||||
@ -17,25 +17,27 @@ export class BlockDetailListComponent implements OnInit {
|
||||
public latestblockdetailObservable: any;
|
||||
private server = environment.domain;
|
||||
private socket;
|
||||
@ViewChild('minhgt', {static: false}) elementView: ElementRef;
|
||||
@ViewChild("minhgt", { static: false }) elementView: ElementRef;
|
||||
|
||||
minHeight: number;
|
||||
|
||||
constructor(private chartService: ChartService,public translate: TransServiceService) {
|
||||
constructor(
|
||||
private chartService: ChartService,
|
||||
public translate: TransServiceService
|
||||
) {
|
||||
// this.chartService.createSocketConnection();
|
||||
}
|
||||
|
||||
|
||||
ngOnInit() {
|
||||
this.gettinglatesthashList();
|
||||
this.getBlockDetails();
|
||||
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.minHeight = this.elementView.nativeElement.offsetHeight;
|
||||
}
|
||||
|
||||
getBlockDetails() {
|
||||
getBlockDetails() {
|
||||
this.latestblockdetailObservable = this.chartService
|
||||
.getLatestblockdetails()
|
||||
.subscribe(response => {
|
||||
@ -45,28 +47,28 @@ getBlockDetails() {
|
||||
this.prevouslatestblockdetails.block_height !=
|
||||
this.latestblockdetail.block_height
|
||||
) {
|
||||
this.latestblockdetail['blink'] = true;
|
||||
this.latestblockdetail["blink"] = true;
|
||||
} else {
|
||||
this.latestblockdetail['blink'] = false;
|
||||
this.latestblockdetail["blink"] = false;
|
||||
}
|
||||
//console.log(this.latestblockdetail);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public gettinglatesthashList() {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.chartService
|
||||
.apiGetRequest('', '/blockchain_block/latesblockdetails')
|
||||
.apiGetRequest("", "/blockchain_block/latesblockdetails")
|
||||
.subscribe(
|
||||
res => {
|
||||
if (res['status'] == 200) {
|
||||
if (res["status"] == 200) {
|
||||
// var hasharray = res.response;
|
||||
this.latestblockdetail = res.response;
|
||||
this.latestblockdetail['blink'] = false;
|
||||
this.latestblockdetail["blink"] = false;
|
||||
resolve();
|
||||
}
|
||||
},
|
||||
error => {},
|
||||
error => {}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user