Target Difficulty

This commit is contained in:
root 2019-08-06 19:58:31 +05:30
parent c4a26852b5
commit fb806d162f
2 changed files with 47 additions and 38 deletions

View File

@ -215,6 +215,10 @@ export class BlockchainBlockController {
* description: Try to give Intevals such as 1 week/ 15 days/ 30 days/ 60 days/ 3 months * description: Try to give Intevals such as 1 week/ 15 days/ 30 days/ 60 days/ 3 months
* in: query * in: query
* type: string * type: string
* - name: Type
* description: Enter the Algorithm Type
* in: query
* type: string
* responses: * responses:
* 200: * 200:
* description: Total Difficulty fetched successfully * description: Total Difficulty fetched successfully
@ -224,7 +228,7 @@ export class BlockchainBlockController {
validationMiddleware(TotalDifficultyNBlockDto, true), validationMiddleware(TotalDifficultyNBlockDto, true),
this.TotalDifficultyNBlock, this.TotalDifficultyNBlock,
); );
/** /**
* @swagger * @swagger
* /epic_explorer/v1/blockchain_block/blockcount: * /epic_explorer/v1/blockchain_block/blockcount:
@ -329,7 +333,7 @@ export class BlockchainBlockController {
validationMiddleware(TotalDifficultyNBlockDto, true), validationMiddleware(TotalDifficultyNBlockDto, true),
this.BlockPieChart, this.BlockPieChart,
); );
/** /**
* @swagger * @swagger
* /epic_explorer/v1/blockchain_block/hashrate: * /epic_explorer/v1/blockchain_block/hashrate:
@ -711,7 +715,7 @@ export class BlockchainBlockController {
// } else { // } else {
// BlockchainBlockFetchQuery['PoWAlgorithm'] = 'CuckAToo31'; // BlockchainBlockFetchQuery['PoWAlgorithm'] = 'CuckAToo31';
// } // }
BlockchainBlockFetchQuery['TotalCuckoo']=parseInt(BlockchainBlockFetchQuery.TotalDifficultyCuckaroo) + BlockchainBlockFetchQuery['TotalCuckoo']=parseInt(BlockchainBlockFetchQuery.TotalDifficultyCuckaroo) +
parseInt(BlockchainBlockFetchQuery.TotalDifficultyCuckatoo); parseInt(BlockchainBlockFetchQuery.TotalDifficultyCuckatoo);
if (BlockchainBlockFetchQuery.Height <= 1440) { if (BlockchainBlockFetchQuery.Height <= 1440) {
BlockchainBlockFetchQuery['BlockReward'] = 200; BlockchainBlockFetchQuery['BlockReward'] = 200;
@ -1005,7 +1009,7 @@ export class BlockchainBlockController {
next(new InternalServerErrorException(error)); next(new InternalServerErrorException(error));
} }
}; };
private BlockCount = async ( private BlockCount = async (
request: Request, request: Request,
response: Response, response: Response,
@ -1126,57 +1130,58 @@ export class BlockchainBlockController {
"timestamp at time zone '" + "timestamp at time zone '" +
process.env.TIME_ZONE + process.env.TIME_ZONE +
"' > current_date - interval '1 day'"; "' > current_date - interval '1 day'";
} }
var alog_type = TotalDifficultyNBlockRequestData.Type;
const TotalDifficultyNBlockQuery = await getConnection() const TotalDifficultyNBlockQuery = await getConnection()
.query( .query(
"select 1 as hash, total_difficulty_cuckaroo as total_difficulty_cuckaroo, \ "SELECT a.hash, a.tarket_difficulty, a.date FROM(select 1 as hash, (total_difficulty_"+alog_type+" - LAG(total_difficulty_"+alog_type+") OVER (ORDER BY total_difficulty_"+alog_type+")) AS tarket_difficulty, \
total_difficulty_cuckatoo as total_difficulty_cuckatoo, \ DATE_TRUNC('minute', timestamp at time zone '" +
total_difficulty_progpow as total_difficulty_progpow, \ process.env.TIME_ZONE +
total_difficulty_randomx as total_difficulty_randomx, DATE_TRUNC('minute', timestamp at time zone '" + "') as date \
process.env.TIME_ZONE + from blockchain_block where " +
"') as date \ timeIntervalQry +
from blockchain_block where " + " order by height) as a WHERE a.tarket_difficulty IS NOT NULL",
timeIntervalQry +
" order by date",
) )
.catch(err_msg => { .catch(err_msg => {
next(err_msg); next(err_msg);
}); });
console.log( "select 1 as hash, total_difficulty_cuckaroo as total_difficulty_cuckaroo, \ console.log("SELECT a.hash, a.tarket_difficulty, a.date FROM(select 1 as hash, (total_difficulty_"+alog_type+" - LAG(total_difficulty_"+alog_type+") OVER (ORDER BY total_difficulty_"+alog_type+")) AS tarket_difficulty, \
total_difficulty_cuckatoo as total_difficulty_cuckatoo, \ DATE_TRUNC('minute', timestamp at time zone '" +
total_difficulty_progpow as total_difficulty_progpow, \ process.env.TIME_ZONE +
total_difficulty_randomx as total_difficulty_randomx, DATE_TRUNC('minute', timestamp at time zone '" + "') as date \
process.env.TIME_ZONE + from blockchain_block where " +
"') as date \ timeIntervalQry +
from blockchain_block where " + " order by height) as a WHERE a.tarket_difficulty IS NOT NULL");
timeIntervalQry +
" order by date");
let date = [], let date = [],
DifficultyCuckaroo = [], //DifficultyCuckaroo = [],
DifficultyCuckatoo = [], //DifficultyCuckatoo = [],
DifficultyProgpow = [], //DifficultyProgpow = [],
DifficultyRandomx = []; //DifficultyRandomx = [];
TargetDifficulty = [];
TotalDifficultyNBlockQuery.forEach(e => { TotalDifficultyNBlockQuery.forEach(e => {
//date.indexOf(moment(e.date).format('YYYY-MM-DD')) < 0 ? //date.indexOf(moment(e.date).format('YYYY-MM-DD')) < 0 ?
date.push(moment(e.date).format('YYYY-MM-DD')); date.push(moment(e.date).format('YYYY-MM-DD'));
DifficultyCuckaroo.push(parseInt(e.total_difficulty_cuckaroo)); // DifficultyCuckaroo.push(parseInt(e.total_difficulty_cuckaroo));
DifficultyCuckatoo.push(parseInt(e.total_difficulty_cuckatoo)); // DifficultyCuckatoo.push(parseInt(e.total_difficulty_cuckatoo));
DifficultyProgpow.push(parseInt(e.total_difficulty_progpow)); // DifficultyProgpow.push(parseInt(e.total_difficulty_progpow));
DifficultyRandomx.push(parseInt(e.total_difficulty_randomx)); // DifficultyRandomx.push(parseInt(e.total_difficulty_randomx));
TargetDifficulty.push(parseInt(e.tarket_difficulty));
}); });
response.status(200).json({ response.status(200).json({
status: 200, status: 200,
timestamp: Date.now(), timestamp: Date.now(),
message: 'Total Difficulty and Blocks Data fetched Successfully', message: 'Total Difficulty and Blocks Data fetched Successfully',
response: { response: {
Date: date, Date: date,
DifficultyCuckaroo: DifficultyCuckaroo, // DifficultyCuckaroo: DifficultyCuckaroo,
DifficultyCuckatoo: DifficultyCuckatoo, // DifficultyCuckatoo: DifficultyCuckatoo,
DifficultyProgpow: DifficultyProgpow, // DifficultyProgpow: DifficultyProgpow,
DifficultyRandomx: DifficultyRandomx TargetDifficulty: TargetDifficulty
}, },
}); });
} catch (error) { } catch (error) {
@ -1586,7 +1591,7 @@ export class BlockchainBlockController {
} }
block_height = BlockchainLatestBlockQuery[0].height; block_height = BlockchainLatestBlockQuery[0].height;
var TotalCuckoo=parseInt(BlockchainLatestBlockQuery[0].total_difficulty_cuckatoo) + var TotalCuckoo=parseInt(BlockchainLatestBlockQuery[0].total_difficulty_cuckatoo) +
parseInt(BlockchainLatestBlockQuery[0].total_difficulty_cuckaroo); parseInt(BlockchainLatestBlockQuery[0].total_difficulty_cuckaroo);
response.status(200).json({ response.status(200).json({

View File

@ -135,4 +135,8 @@ export class TotalDifficultyNBlockDto {
@IsString() @IsString()
public Interval: string; public Interval: string;
@IsString()
public Type: string;
} }