server changes

This commit is contained in:
KarthiKeyanZ 2022-12-23 10:16:03 +00:00
parent 3fb35b3f3b
commit bf7430d36f
6 changed files with 739 additions and 295 deletions

View File

@ -22,7 +22,10 @@ import {
TotalDifficultyNBlockDto,
} from '../dtos';
import { Paginate } from '../utils';
import {latestBlockDetails} from '../utils/common';
import {
latestBlockDetails,
previousBlockDetails
} from '../utils/common';
var moment = require('moment');
moment.updateLocale('en', {
relativeTime: {
@ -256,6 +259,12 @@ export class BlockchainBlockController {
this.TotalDifficultyNBlock,
);
this.router.get(
`${this.path}/get51poolapi`,
redisMiddleware(process.env.REDIS_EXPIRY),
this.get51poolapi,
);
/**
* @swagger
* /epic_explorer/v1/blockchain_block/blockcount:
@ -446,6 +455,7 @@ export class BlockchainBlockController {
* 200:
* description: Total Difficulty and No. of blocks fetched successfully
*/
// Last Block home page function
this.router.get(
`${this.path}/latesblockdetails`,
validationMiddleware(TotalDifficultyNBlockDto, true),
@ -453,6 +463,14 @@ export class BlockchainBlockController {
this.LatestDifficultyNBlock,
);
// Previous Block home page function
this.router.get(
`${this.path}/previousblockdetails`,
validationMiddleware(TotalDifficultyNBlockDto, true),
redisMiddleware(process.env.REDIS_EXPIRY),
this.PreviousDifficultyNBlock,
);
/**
* @swagger
* /epic_explorer/v1/blockchain_block/blockspersec:
@ -684,6 +702,33 @@ export class BlockchainBlockController {
);
}
// get 51poolapi
private get51poolapi = ( request: Request,res: Response) => {
// var request = require('request');
var axios = require('axios');
try {
var config = {
method: 'get',
url: 'https://51pool.online/api',
headers: { }
};
axios(config).then(function (response) {
console.log('response.body----------');
console.log(JSON.stringify(response.data));
res.status(200).json({
status: 200,
response: response.data
});
})
.catch(function (error) {
console.log('axios-error');
console.log(error);
});
} catch (error) {
console.log(error);
}
};
private BlockchainBlockCreate = async (
request: Request,
response: Response,
@ -1738,7 +1783,8 @@ export class BlockchainBlockController {
next(new InternalServerErrorException(error));
}
};
// Last Block home page function
private LatestDifficultyNBlock = async (
request: Request,
response: Response,
@ -1758,6 +1804,28 @@ export class BlockchainBlockController {
next(new InternalServerErrorException(error));
}
};
// Previous Block home page function
private PreviousDifficultyNBlock = async (
request: Request,
response: Response,
next: NextFunction,
) => {
try {
let result = await previousBlockDetails()
response.status(200).json({
status: 200,
timestamp: Date.now(),
message: 'Previous Block Details fetched Successfully',
response: {
...result
},
});
} catch (error) {
next(new InternalServerErrorException(error));
}
};
private BlockchainBlockPerSecond = async (
request: Request,

View File

@ -32,9 +32,9 @@ export class BlockchainKernelController {
IsJsonString(str) {
try {
var dataJson = JSON.parse(str);
var dataJson = JSON.parse(str);
} catch (e) {
return [];
return [];
}
return dataJson;
}
@ -149,29 +149,30 @@ export class BlockchainKernelController {
);
/**
* @swagger
* /epic_explorer/v1/network:
* get:
* tags:
* - name: Network | Network CONTROLLER
* summary: change a network
* description: change a network
* consumes:
* - application/json
* produces:
* - application/json
* parameters:
* - name: network
* responses:
* 200:
* description: Network Changed successfully
*/
/**
* @swagger
* /epic_explorer/v1/network:
* get:
* tags:
* - name: Network | Network CONTROLLER
* summary: change a network
* description: change a network
* consumes:
* - application/json
* produces:
* - application/json
* parameters:
* - name: network
* responses:
* 200:
* description: Network Changed successfully
*/
this.router.get(
`${this.path}/network`,
this.changeNetwok,
);
/**
* @swagger
* /epic_explorer/v1/getpeers:
@ -562,6 +563,212 @@ export class BlockchainKernelController {
}
};
/*
private getPeersLocation = async (
request: Request,
response: Response,
next: NextFunction,
) => {
var self = this;
try {
if (Global.network == "Floonet") {
var peer_url = process.env.FLOONET_PEER_URL;
} else {
var peer_url = process.env.TESTNET_PEER_URL;
}
let finalresult = await request_promise(peer_url);
if (finalresult) {
var jsonresponse = JSON.parse(finalresult);
}
let getAllIp = [];
let getExistingIp = [];
let result = jsonresponse.map(function (value, i) {
value['id'] = i;
let getIP = value['addr'].split(':')[0];
getAllIp.push(getIP);
return value;
});
const fetchAllIps = await getConnection(Global.network).query(`SELECT ip, longitude, latitude FROM public.peer_ip`);
// const fetchAllIps = await getConnection(Global.network).getRepository(
// PeerIp,
// ).find({
// select: ['IpAddress']
// });
let markers = [];
for (let ip = 0; ip < fetchAllIps.length; ip++) {
getExistingIp.push(fetchAllIps[ip]['ip'].replace(/['"]+/g, ''));
const mapMarker = {
"longitude": fetchAllIps[ip]['longitude'],
"latitude": fetchAllIps[ip]['latitude']
};
markers.push(mapMarker);
}
let users = {};
users['locations'] = markers;
response.status(200).json({
status: 200,
timestamp: Date.now(),
message: 'Peers location list fetched successfully',
response: {
dataJson: users
},
});
}
catch (error) {
console.log('getpeerslocation-error', error);
next(new InternalServerErrorException(error));
}
}
*/
/*
private getPeers = async (
request: Request,
response: Response,
next: NextFunction,
) => {
var self = this;
try {
if (Global.network == "Floonet") {
var peer_url = process.env.FLOONET_PEER_URL;
} else {
var peer_url = process.env.TESTNET_PEER_URL;
}
let finalresult = await request_promise(peer_url);
if (finalresult) {
var jsonresponse = JSON.parse(finalresult);
}
let getAllIp = [];
let getExistingIp = [];
let result = jsonresponse.map(function (value, i) {
value['id'] = i;
let getIP = value['addr'].split(':')[0];
getAllIp.push(getIP);
return value;
});
const fetchAllIps = await getConnection(Global.network).query(`SELECT ip, longitude, latitude FROM public.peer_ip`);
// const fetchAllIps = await getConnection(Global.network).getRepository(
// PeerIp,
// ).find({
// select: ['IpAddress']
// });
let markers = [];
for (let ip = 0; ip < fetchAllIps.length; ip++) {
getExistingIp.push(fetchAllIps[ip]['ip'].replace(/['"]+/g, ''));
const mapMarker = {
"longitude": fetchAllIps[ip]['longitude'],
"latitude": fetchAllIps[ip]['latitude']
};
markers.push(mapMarker);
}
let users = {};
users['locations'] = markers;
fs.writeFile(path.join(__dirname, "../../", "browser", "assets/geojson.json"), JSON.stringify(users), err => {
// Checking for errors
if (err) { throw err; }
});
const missingIp = getAllIp.filter(item => getExistingIp.indexOf(item) < 0);
if (missingIp.length > 0) {
fs.readFile(path.join(__dirname, "../../", "browser", "assets/geojson.json"), (err, data) => {
if (err) { throw err; }
const users = JSON.parse(data);
for (let i = 0; i < missingIp.length; i++) {
const markers = [];
const ips = missingIp[i];
httpRequest(`https://api.ipgeolocationapi.com/geolocate/${ips}`, async (error, response, resp) => {
if (error) { throw error; }
const ipResp = JSON.parse(resp);
const ipLatitude = ipResp.geo.latitude;
const ipLongitude = ipResp.geo.longitude;
const insertQuery = await getConnection(Global.network)
.query(`INSERT INTO public.peer_ip(ip, longitude, latitude) VALUES ('${ips}', '${ipLongitude}', '${ipLatitude}');`);
// let mapMarker = {
// "type": "Feature",
// "geometry": {
// "type": "Point",
// "coordinates": [ipLongitude, ipLatitude]
// }
// }
const mapMarker = {
"longitude": ipLongitude,
"latitude": ipLatitude
};
markers.push(mapMarker);
users.locations = markers;
fs.writeFile(path.join(__dirname, "../../", "browser", "assets/geojson.json"), JSON.stringify(users), err => {
// Checking for errors
if (err) { throw err; }
});
});
}
});
}
response.status(200).json({
status: 200,
timestamp: Date.now(),
message: 'Peers list fetched successfully',
response: {
dataJson: result
},
});
// http.get(peer_url,
// async (resp) => {
// // console.log('resp resp respresp',resp);
// let data = '';
// let result ;
// // A chunk of data has been recieved.
// await new Promise((resolve) => {
// resp.on('data', function (chunk) {
// data += chunk;
// let dataJson = self.IsJsonString(data);
// if(dataJson.length > 0){
// result = dataJson.map(function (value, i) {
// value['id'] = i;
// return value;
// });
// }
// resolve();
// });
// });
// response.status(200).json({
// status: 200,
// timestamp: Date.now(),
// message: 'Peers list fetched successfully',
// response: {
// dataJson: result
// },
// });
// });
} catch (error) {
console.log('error 3###########', error);
next(new InternalServerErrorException(error));
}
};
*/
private getPeers = async (
request: Request,
response: Response,
@ -651,7 +858,7 @@ export class BlockchainKernelController {
.utc()
.format('YYYY-MM-DD');
var timeIntervalQry =
var timeIntervalQry =
"timestamp at time zone '" +
process.env.TIME_ZONE +
"' BETWEEN SYMMETRIC '" +
@ -679,7 +886,7 @@ export class BlockchainKernelController {
Fee.push(e.fee);
});
if(date.length == 0){
if (date.length == 0) {
date = [moment(Date.now()).format('YYYY-MM-DD')];
Fee = [0];
}
@ -834,7 +1041,7 @@ LEFT JOIN (select block_id, count(block_id) as block_id_count from blockchain_ou
) => {
try {
const TransactionFeeRequestData: TransactionFeeDto = request.query;
if (TransactionFeeRequestData.Interval) {
if (TransactionFeeRequestData.Interval) {
var timeIntervalQry =
"blockchain_block.timestamp > current_date - interval '" +
TransactionFeeRequestData.Interval +
@ -853,7 +1060,7 @@ LEFT JOIN (select block_id, count(block_id) as block_id_count from blockchain_ou
// ' AND ' +
// TransactionFeeRequestData.ToDate;
var timeIntervalQry =
var timeIntervalQry =
"blockchain_block.timestamp at time zone '" +
process.env.TIME_ZONE +
"' BETWEEN SYMMETRIC '" +
@ -861,7 +1068,7 @@ LEFT JOIN (select block_id, count(block_id) as block_id_count from blockchain_ou
"' AND '" +
TransactionFeeRequestData.ToDate +
"'";
var seriesquery =
"'" +
TransactionFeeRequestData.FromDate +
@ -914,8 +1121,7 @@ LEFT JOIN (select block_id, count(block_id) as block_id_count from blockchain_ou
totaloutput = [];
TransactionHeatmapChartQuery.forEach(e => {
if(moment(e.hour).format('YYYY-MM-DD') >= moment('2019-09-03').format('YYYY-MM-DD'))
{
if (moment(e.hour).format('YYYY-MM-DD') >= moment('2019-09-03').format('YYYY-MM-DD')) {
date.push(moment(e.hour).format('YYYY-MM-DD'));
totalinput.push(e.totalinput != null ? e.totalinput : 0);
totalkernal.push(e.totalkernal != null ? e.totalkernal : 0);

41
server/entities/PeerIp.ts Normal file
View File

@ -0,0 +1,41 @@
import {
BaseEntity,
Column,
Entity,
Index,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
} from 'typeorm';
@Entity('peer_ip', { schema: 'public' })
export class PeerIp {
@PrimaryGeneratedColumn({
type: 'integer',
name: 'id',
})
Id: number;
@Column('character varying', {
nullable: false,
primary: true,
length: 142,
name: 'ip',
})
IpAddress: string;
@Column('character varying', {
nullable: false,
length: 142,
name: 'longitude',
})
Longitude: string;
@Column('character varying', {
nullable: false,
length: 142,
name: 'latitude',
})
Latitude: string;
}

View File

@ -103,6 +103,12 @@
"getdifficulty-randomx" : "Gibt die RandomX-Schwierigkeit als reine Textzeichenfolge zurück",
"getdifficulty-progpow" : "Gibt die ProgPoW-Schwierigkeit als reine Textzeichenfolge zurück",
"getdifficulty-cuckoo" : "Gibt die Cuckoo-Schwierigkeit als einfache Textzeichenfolge zurück",
"gettargetdifficulty-randomx" : "Gibt die RandomX-Zielschwierigkeit als Nur-Text-Zeichenfolge zurück",
"gettargetdifficulty-progpow" : "Gibt die ProgPoW-Zielschwierigkeit als Nur-Text-Zeichenfolge zurück",
"gettargetdifficulty-cuckoo" : "Gibt die Cuckoo-Zielschwierigkeit als Nur-Text-Zeichenfolge zurück",
"getnetworkhashrate-randomx" : "Gibt die RandomX-Netzwerk-Hashrate als Nur-Text-Zeichenfolge zurück",
"getnetworkhashrate-progpow" : "Gibt die ProgPoW-Netzwerk-Hashrate als Nur-Text-Zeichenfolge zurück",
"getnetworkhashrate-cuckoo" : "Gibt die Cuckoo-Netzwerk-Hashrate als Nur-Text-Zeichenfolge zurück",
"totalcoins" : "Gibt die ausstehende Anzahl von Münzen zurück",
"Block-Queries": "Block Abfragen",
"real-time-simple-query" : "Einfache Echtzeits abfragen",

View File

@ -20,7 +20,7 @@
"EXPLORE_IT": "Explore",
"blocks-by-algorithm" : "Blocks by Algorithm",
"VIEWALL": "View All Charts",
"BLOCKCHAIN_HEIGHT": "Blockchain Height",
"BLOCKCHAIN_HEIGHT": "Block Height",
"BLOCKCHAIN_SIZE":"Blockchain Size",
"LATEST_BLOCKS" : "Latest Blocks",
"LATEST_BLOCK_AGE": "Latest Block",
@ -103,6 +103,12 @@
"getdifficulty-randomx" : "returns the RandomX difficulty as a plain text string",
"getdifficulty-progpow" : "returns the ProgPoW difficulty as a plain text string",
"getdifficulty-cuckoo" : "returns the Cuckoo difficulty as a plain text string",
"gettargetdifficulty-randomx" : "returns the RandomX target difficulty as a plain text string",
"gettargetdifficulty-progpow" : "returns the ProgPoW target difficulty as a plain text string",
"gettargetdifficulty-cuckoo" : "returns the Cuckoo target difficulty as a plain text string",
"getnetworkhashrate-randomx" : "returns the RandomX network hashrate as a plain text string",
"getnetworkhashrate-progpow" : "returns the ProgPoW network hashrate as a plain text string",
"getnetworkhashrate-cuckoo" : "returns the Cuckoo network hashrate as a plain text string",
"totalcoins" : "returns the outstanding number of coins",
"Block-Queries": "Block Queries",
"real-time-simple-query" : "Real-Time Simple Queries",

View File

@ -225,154 +225,80 @@ else if(height < (first_duration + (7 * year_height)) ) {
// Last Block home page function
const latestBlockDetails = async()=> {
let block_height = '',
letest_block,
letest_block_num = '',
letest_block_duration = '';
let block_height = '',
letest_block,
letest_block_num = '',
letest_block_duration = '';
const BlockchainLatestBlockQuery = await getConnection(Global.network)
.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',
)
.catch(err_msg => {
return(err_msg);
});
const BlockchainPreviousBlockQuery = await getConnection(Global.network)
.query(
'SELECT total_difficulty_cuckaroo, total_difficulty_cuckatoo, total_difficulty_progpow, total_difficulty_randomx FROM blockchain_block WHERE hash=' +
"'" +
BlockchainLatestBlockQuery[0].previous_id +
"'",
).catch(err_msg => {
return(err_msg);
});
const BlockchainLatestBlockQuery = await getConnection(Global.network)
.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',
)
.catch(err_msg => {
return(err_msg);
});
const BlockchainPreviousBlockQuery = await getConnection(Global.network)
.query(
'SELECT total_difficulty_cuckaroo, total_difficulty_cuckatoo, total_difficulty_progpow, total_difficulty_randomx FROM blockchain_block WHERE hash=' +
"'" +
BlockchainLatestBlockQuery[0].previous_id +
"'",
)
.catch(err_msg => {
return(err_msg);
});
// const space = await exec('du -sh /root/.epic/main/chain_data/ --exclude=*.zip');
const space = "1.7G /var/www/html/"
// let disk_space = space.stdout.split('\t')[0];
const disk_space = "1.7"
const space = await exec('du -sh /root/.epic/main/chain_data/ --exclude=*.zip');
let disk_space = space.stdout.split('\t')[0];
// const space_new = await exec('du -sk /root/.epic/main/chain_data/ --exclude=*.zip');
const space_new = "1.7G /var/www/html/"
//let disk_space_kb = space_new.stdout.split('\t')[0];
// let disk_space_kb = (space_new.stdout.split('\t')[0] / 1000000).toFixed(2)+"G";
let disk_space_kb = "1.7G"
let height = BlockchainLatestBlockQuery[0].height;
var coin_existence;
let DAY_HEIGHT = 1440
/// Height of the first epic block emission era
const BLOCK_ERA_1 = DAY_HEIGHT * 334;
/// Height of the second epic block emission era
const BLOCK_ERA_2 = BLOCK_ERA_1 + (DAY_HEIGHT * 470);
/// Height of the third epic block emission era
const BLOCK_ERA_3 = BLOCK_ERA_2 + (DAY_HEIGHT * 601);
/// Height of the fourth epic block emission era
const BLOCK_ERA_4 = BLOCK_ERA_3 + (DAY_HEIGHT * 800);
/// Height of the fifth epic block emission era
const BLOCK_ERA_5 = BLOCK_ERA_4 + (DAY_HEIGHT * 1019);
/// After the epic block emission era 6, each era will last 4 years (approximately 1460 days)
const BLOCK_ERA_6_ONWARDS = DAY_HEIGHT * 1460;
/// Block Reward that will be assigned after we change from era 5 to era 6.
const BASE_REWARD_ERA_6_ONWARDS = 0.15625;
const space_new = await exec('du -sk /root/.epic/main/chain_data/ --exclude=*.zip');
//let disk_space_kb = space_new.stdout.split('\t')[0];
let disk_space_kb = (space_new.stdout.split('\t')[0] / 1000000).toFixed(2)+"G";
let height = BlockchainLatestBlockQuery[0].height;
var coin_existence;
// 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;
// }
let DAY_HEIGHT = 1440
/// Height of the first epic block emission era
const BLOCK_ERA_1 = DAY_HEIGHT * 334;
/// Height of the second epic block emission era
const BLOCK_ERA_2 = BLOCK_ERA_1 + (DAY_HEIGHT * 470);
/// Height of the third epic block emission era
const BLOCK_ERA_3 = BLOCK_ERA_2 + (DAY_HEIGHT * 601);
/// Height of the fourth epic block emission era
const BLOCK_ERA_4 = BLOCK_ERA_3 + (DAY_HEIGHT * 800);
/// Height of the fifth epic block emission era
const BLOCK_ERA_5 = BLOCK_ERA_4 + (DAY_HEIGHT * 1019);
/// After the epic block emission era 6, each era will last 4 years (approximately 1460 days)
const BLOCK_ERA_6_ONWARDS = DAY_HEIGHT * 1460;
/// Block Reward that will be assigned after we change from era 5 to era 6.
const BASE_REWARD_ERA_6_ONWARDS = 0.15625;
let remaining_height = 0;
let currentReward = 16;
/// Compute the total reward generated by each block in a given height.
let remaining_height = 0;
let currentReward = 16;
/// Compute the total reward generated by each block in a given height.
if (height <= BLOCK_ERA_1) {
coin_existence = height * 16;
currentReward = 16;
} else if (height <= BLOCK_ERA_2) {
remaining_height = height - BLOCK_ERA_1;
coin_existence = (16 * BLOCK_ERA_1) + 8 * remaining_height;
currentReward = 8;
} else if (height <= BLOCK_ERA_3) {
remaining_height = height - BLOCK_ERA_2;
coin_existence = (16 * BLOCK_ERA_1) + (8 * BLOCK_ERA_2) + 4 * remaining_height;
currentReward = 4;
} else if (height <= BLOCK_ERA_4) {
remaining_height = height - BLOCK_ERA_3;
coin_existence = (16 * BLOCK_ERA_1) + (8 * BLOCK_ERA_2) + (4 * BLOCK_ERA_3) + 2 * remaining_height;
currentReward = 2;
} else if (height <= BLOCK_ERA_5) {
remaining_height = height - BLOCK_ERA_4;
coin_existence = (16 * BLOCK_ERA_1) + (8 * BLOCK_ERA_2) + (4 * BLOCK_ERA_3) + (2 * BLOCK_ERA_4) +1 * remaining_height;
currentReward = 1;
} else {
coin_existence = height * 16;
currentReward = 16;
} else if (height <= BLOCK_ERA_2) {
remaining_height = height - BLOCK_ERA_1;
coin_existence = (16 * BLOCK_ERA_1) + 8 * remaining_height;
currentReward = 8;
} else if (height <= BLOCK_ERA_3) {
remaining_height = height - BLOCK_ERA_2;
coin_existence = (16 * BLOCK_ERA_1) + (8 * BLOCK_ERA_2) + 4 * remaining_height;
currentReward = 4;
} else if (height <= BLOCK_ERA_4) {
remaining_height = height - BLOCK_ERA_3;
coin_existence = (16 * BLOCK_ERA_1) + (8 * BLOCK_ERA_2) + (4 * BLOCK_ERA_3) + 2 * remaining_height;
currentReward = 2;
} else if (height <= BLOCK_ERA_5) {
remaining_height = height - BLOCK_ERA_4;
coin_existence = (16 * BLOCK_ERA_1) + (8 * BLOCK_ERA_2) + (4 * BLOCK_ERA_3) + (2 * BLOCK_ERA_4) +1 * remaining_height;
currentReward = 1;
} else {
// After the era 6, we reduce the block rewards by half each 1460 days.
// Minus 1 to include multiples in the same index
// (i.e changes greater than to greater or equals to)
@ -386,135 +312,325 @@ let currentReward = 16;
currentReward = reward_emission;
}
letest_block = dateDiff(BlockchainLatestBlockQuery[0].timestamp,true);
letest_block_num = letest_block; // "72"
letest_block_duration = letest_block == 1 ? 'second ago' : 'seconds ago';
const SECOND_POW_EDGE_BITS = 29;
const BASE_EDGE_BITS = 24;
letest_block = dateDiff(BlockchainLatestBlockQuery[0].timestamp,true);
letest_block_num = letest_block; // "72"
letest_block_duration = letest_block == 1 ? 'second ago' : 'seconds ago';
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].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;
}
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);
block_height = BlockchainLatestBlockQuery[0].height;
var TotalCuckoo=parseInt(BlockchainLatestBlockQuery[0].total_difficulty_cuckatoo) +
parseInt(BlockchainLatestBlockQuery[0].total_difficulty_cuckaroo);
let FOUNDATION_LEVY_ERA_1 = DAY_HEIGHT * 120;
/// After the first foundation levy era, we decrease the foundation levy each year
let FOUNDATION_LEVY_ERA_2_ONWARDS = DAY_HEIGHT * 365;
let FOUNDATION_LEVY_ERA_1 = DAY_HEIGHT * 120;
/// After the first foundation levy era, we decrease the foundation levy each year
let FOUNDATION_LEVY_ERA_2_ONWARDS = DAY_HEIGHT * 365;
/// The foundation levy in each era
let FOUNDATION_LEVY = [
0.0888, 0.0777, 0.0666, 0.0555, 0.0444, 0.0333, 0.0222, 0.0111, 0.0111,
];
/// Compute the foundation levy for each block.
let foundationReward = 16 * FOUNDATION_LEVY[0];
let userReward = 16 - (FOUNDATION_LEVY[0]);
if (height <= 0) {
foundationReward =0;
userReward = 0;
} else if (height <= FOUNDATION_LEVY_ERA_1) {
foundationReward = currentReward * FOUNDATION_LEVY[0];
userReward = currentReward -foundationReward;
} else {
// We subtract 1 to include the last block of an era.
let height_with_offset = height - FOUNDATION_LEVY_ERA_1 - 1;
// We used the index 0 in the first era, therefore we offset the index by 1
let index = (height_with_offset / FOUNDATION_LEVY_ERA_2_ONWARDS) + 1;
if (index < FOUNDATION_LEVY.length ) {
foundationReward = currentReward * FOUNDATION_LEVY[index];
userReward = currentReward -foundationReward;
} else {
foundationReward = 0;
userReward = 0;
}
}
let cuckoohashrate = await network_hashrate(block_height,31,targetdifficultycuckatoo+targetdifficultycuckaroo,"Cuckoo");
let progpowhashrate = await network_hashrate(block_height,16,targetdifficultyprogpow,"ProgPow");
let randomxhashrate = await network_hashrate(block_height,16,targetdifficultyrandomx,"RandomX");
cuckoohashrate = Math.round(cuckoohashrate)
progpowhashrate = Math.round(progpowhashrate)
randomxhashrate = Math.round(randomxhashrate)
// // Test purpose
// let test_cuckoo = await testavgBlockTime(block_height,"Cuckoo")
// let test_randomx = await testavgBlockTime(block_height,"RandomX")
// let test_progpow = await testavgBlockTime(block_height,"ProgPow")
// console.log("-----------------")
// console.log("Cuckoo avg block time ", test_cuckoo)
// console.log("randomx avg block time ", test_randomx)
// console.log("Progpow avg block time ", test_progpow)
// Total foundation reward
let totalFoundationReward = await circulationsupply(height)
return {
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,
currentReward,
foundationReward,
userReward,
cuckoohashrate,
progpowhashrate,
randomxhashrate,
totalFoundationReward,
diskSpace:disk_space_kb,
diskSpaceKb : disk_space_kb
};
/// The foundation levy in each era
let FOUNDATION_LEVY = [
0.0888, 0.0777, 0.0666, 0.0555, 0.0444, 0.0333, 0.0222, 0.0111, 0.0111,
];
/// Compute the foundation levy for each block.
let foundationReward = 16 * FOUNDATION_LEVY[0];
let userReward = 16 - (FOUNDATION_LEVY[0]);
if (height <= 0) {
foundationReward =0;
userReward = 0;
} else if (height <= FOUNDATION_LEVY_ERA_1) {
foundationReward = currentReward * FOUNDATION_LEVY[0];
userReward = currentReward -foundationReward;
} else {
// We subtract 1 to include the last block of an era.
let height_with_offset = height - FOUNDATION_LEVY_ERA_1 - 1;
// We used the index 0 in the first era, therefore we offset the index by 1
let index = (height_with_offset / FOUNDATION_LEVY_ERA_2_ONWARDS) + 1;
if (index < FOUNDATION_LEVY.length ) {
foundationReward = currentReward * FOUNDATION_LEVY[index];
userReward = currentReward -foundationReward;
} else {
foundationReward = 0;
userReward = 0;
}
}
let cuckoohashrate = await network_hashrate(block_height,31,targetdifficultycuckatoo+targetdifficultycuckaroo,"Cuckoo");
let progpowhashrate = await network_hashrate(block_height,16,targetdifficultyprogpow,"ProgPow");
let randomxhashrate = await network_hashrate(block_height,16,targetdifficultyrandomx,"RandomX");
cuckoohashrate = Math.round(cuckoohashrate)
progpowhashrate = Math.round(progpowhashrate)
randomxhashrate = Math.round(randomxhashrate)
let totalFoundationReward = await circulationsupply(height)
return {
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,
currentReward,
foundationReward,
userReward,
cuckoohashrate,
progpowhashrate,
randomxhashrate,
totalFoundationReward,
diskSpace:disk_space_kb,
diskSpaceKb : disk_space_kb
};
}
// Previous Block home page function
const previousBlockDetails = async() => {
let block_height = '',
letest_block,
letest_block_num = '',
letest_block_duration = '';
const CurrentBlock = await getConnection(Global.network)
.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',
).catch(err_msg => {
return(err_msg);
});
const BlockchainLatestBlockQuery = await getConnection(Global.network)
.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 WHERE hash=' +
"'" +
CurrentBlock[0].previous_id +
"'",
)
.catch(err_msg => {
return(err_msg);
});
const BlockchainPreviousBlockQuery = await getConnection(Global.network)
.query(
'SELECT total_difficulty_cuckaroo, total_difficulty_cuckatoo, total_difficulty_progpow, total_difficulty_randomx FROM blockchain_block WHERE hash=' +
"'" +
BlockchainLatestBlockQuery[0].previous_id +
"'",
).catch(err_msg => {
return(err_msg);
});
// const space = await exec('du -sh /root/.epic/main/chain_data/ --exclude=*.zip');
const space = "1.7G /var/www/html/"
// let disk_space = space.stdout.split('\t')[0];
const disk_space = "1.7"
// const space_new = await exec('du -sk /root/.epic/main/chain_data/ --exclude=*.zip');
const space_new = "1.7G /var/www/html/"
//let disk_space_kb = space_new.stdout.split('\t')[0];
// let disk_space_kb = (space_new.stdout.split('\t')[0] / 1000000).toFixed(2)+"G";
let disk_space_kb = "1.7G"
let height = BlockchainLatestBlockQuery[0].height;
var coin_existence;
let DAY_HEIGHT = 1440
/// Height of the first epic block emission era
const BLOCK_ERA_1 = DAY_HEIGHT * 334;
/// Height of the second epic block emission era
const BLOCK_ERA_2 = BLOCK_ERA_1 + (DAY_HEIGHT * 470);
/// Height of the third epic block emission era
const BLOCK_ERA_3 = BLOCK_ERA_2 + (DAY_HEIGHT * 601);
/// Height of the fourth epic block emission era
const BLOCK_ERA_4 = BLOCK_ERA_3 + (DAY_HEIGHT * 800);
/// Height of the fifth epic block emission era
const BLOCK_ERA_5 = BLOCK_ERA_4 + (DAY_HEIGHT * 1019);
/// After the epic block emission era 6, each era will last 4 years (approximately 1460 days)
const BLOCK_ERA_6_ONWARDS = DAY_HEIGHT * 1460;
/// Block Reward that will be assigned after we change from era 5 to era 6.
const BASE_REWARD_ERA_6_ONWARDS = 0.15625;
let remaining_height = 0;
let currentReward = 16;
/// Compute the total reward generated by each block in a given height.
if (height <= BLOCK_ERA_1) {
coin_existence = height * 16;
currentReward = 16;
} else if (height <= BLOCK_ERA_2) {
remaining_height = height - BLOCK_ERA_1;
coin_existence = (16 * BLOCK_ERA_1) + 8 * remaining_height;
currentReward = 8;
} else if (height <= BLOCK_ERA_3) {
remaining_height = height - BLOCK_ERA_2;
coin_existence = (16 * BLOCK_ERA_1) + (8 * BLOCK_ERA_2) + 4 * remaining_height;
currentReward = 4;
} else if (height <= BLOCK_ERA_4) {
remaining_height = height - BLOCK_ERA_3;
coin_existence = (16 * BLOCK_ERA_1) + (8 * BLOCK_ERA_2) + (4 * BLOCK_ERA_3) + 2 * remaining_height;
currentReward = 2;
} else if (height <= BLOCK_ERA_5) {
remaining_height = height - BLOCK_ERA_4;
coin_existence = (16 * BLOCK_ERA_1) + (8 * BLOCK_ERA_2) + (4 * BLOCK_ERA_3) + (2 * BLOCK_ERA_4) +1 * remaining_height;
currentReward = 1;
} else {
// After the era 6, we reduce the block rewards by half each 1460 days.
// Minus 1 to include multiples in the same index
// (i.e changes greater than to greater or equals to)
let preious_circulation = (16 * BLOCK_ERA_1) + (8 * BLOCK_ERA_2) + (4 * BLOCK_ERA_3) + (2 * BLOCK_ERA_4) + (1 * BLOCK_ERA_5);
let height_with_offset = height - (BLOCK_ERA_5 - 1);
let exp = height_with_offset / BLOCK_ERA_6_ONWARDS;
let reward_emission = BASE_REWARD_ERA_6_ONWARDS / (1 << exp);
coin_existence = preious_circulation + reward_emission ;
currentReward = reward_emission;
}
letest_block = dateDiff(BlockchainLatestBlockQuery[0].timestamp,true);
letest_block_num = letest_block; // "72"
letest_block_duration = letest_block == 1 ? 'second ago' : 'seconds ago';
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);
let FOUNDATION_LEVY_ERA_1 = DAY_HEIGHT * 120;
/// After the first foundation levy era, we decrease the foundation levy each year
let FOUNDATION_LEVY_ERA_2_ONWARDS = DAY_HEIGHT * 365;
/// The foundation levy in each era
let FOUNDATION_LEVY = [
0.0888, 0.0777, 0.0666, 0.0555, 0.0444, 0.0333, 0.0222, 0.0111, 0.0111,
];
/// Compute the foundation levy for each block.
let foundationReward = 16 * FOUNDATION_LEVY[0];
let userReward = 16 - (FOUNDATION_LEVY[0]);
if (height <= 0) {
foundationReward =0;
userReward = 0;
} else if (height <= FOUNDATION_LEVY_ERA_1) {
foundationReward = currentReward * FOUNDATION_LEVY[0];
userReward = currentReward -foundationReward;
} else {
// We subtract 1 to include the last block of an era.
let height_with_offset = height - FOUNDATION_LEVY_ERA_1 - 1;
// We used the index 0 in the first era, therefore we offset the index by 1
let index = (height_with_offset / FOUNDATION_LEVY_ERA_2_ONWARDS) + 1;
if (index < FOUNDATION_LEVY.length ) {
foundationReward = currentReward * FOUNDATION_LEVY[index];
userReward = currentReward -foundationReward;
} else {
foundationReward = 0;
userReward = 0;
}
}
let cuckoohashrate = await network_hashrate(block_height,31,targetdifficultycuckatoo+targetdifficultycuckaroo,"Cuckoo");
let progpowhashrate = await network_hashrate(block_height,16,targetdifficultyprogpow,"ProgPow");
let randomxhashrate = await network_hashrate(block_height,16,targetdifficultyrandomx,"RandomX");
cuckoohashrate = Math.round(cuckoohashrate)
progpowhashrate = Math.round(progpowhashrate)
randomxhashrate = Math.round(randomxhashrate)
let totalFoundationReward = await circulationsupply(height)
return {
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,
currentReward,
foundationReward,
userReward,
cuckoohashrate,
progpowhashrate,
randomxhashrate,
totalFoundationReward,
diskSpace:disk_space_kb,
diskSpaceKb : disk_space_kb
};
}
async function Details (height) {
if(height){
@ -648,5 +764,6 @@ async function network_hashrate(height, edge_bits, difficulty,proof) {
export {network_hashrate};
export {averageblockdifficulty};
export {latestBlockDetails};
export {previousBlockDetails};
export {GetBlocktime};
export {Details};