This commit is contained in:
SuriyaR 2019-07-29 19:31:27 +05:30
parent 3174184928
commit a2b142d302
2 changed files with 114 additions and 45 deletions

View File

@ -540,11 +540,14 @@ export class BlockchainBlockController {
'Hash', 'Hash',
'Height', 'Height',
'Timestamp', 'Timestamp',
'TotalDifficulty', 'TotalDifficultyCuckaroo',
'TotalDifficultyCuckatoo',
'TotalDifficultyProgpow',
'TotalDifficultyRandomx',
'PreviousId', 'PreviousId',
'EdgeBits', 'EdgeBits',
'SecondaryScaling', 'SecondaryScaling',
'CuckooSolution', 'Proof',
], ],
where: { Hash: request.params.hash }, where: { Hash: request.params.hash },
}); });
@ -562,11 +565,14 @@ export class BlockchainBlockController {
'Hash', 'Hash',
'Height', 'Height',
'Timestamp', 'Timestamp',
'TotalDifficulty', 'TotalDifficultyCuckaroo',
'TotalDifficultyCuckatoo',
'TotalDifficultyProgpow',
'TotalDifficultyRandomx',
'PreviousId', 'PreviousId',
'EdgeBits', 'EdgeBits',
'SecondaryScaling', 'SecondaryScaling',
'CuckooSolution', 'Proof',
], ],
where: { Height: paramVal }, where: { Height: paramVal },
}); });
@ -595,11 +601,11 @@ export class BlockchainBlockController {
where: { BlockId: BlockchainBlockFetchQuery.Hash }, where: { BlockId: BlockchainBlockFetchQuery.Hash },
}); });
if (BlockchainBlockFetchQuery.EdgeBits == 29) { // if (BlockchainBlockFetchQuery.EdgeBits == 29) {
BlockchainBlockFetchQuery['PoWAlgorithm'] = 'CuckARoo29'; // BlockchainBlockFetchQuery['PoWAlgorithm'] = 'CuckARoo29';
} else { // } else {
BlockchainBlockFetchQuery['PoWAlgorithm'] = 'CuckAToo31'; // BlockchainBlockFetchQuery['PoWAlgorithm'] = 'CuckAToo31';
} // }
if (BlockchainBlockFetchQuery.Height <= 1440) { if (BlockchainBlockFetchQuery.Height <= 1440) {
BlockchainBlockFetchQuery['BlockReward'] = 200; BlockchainBlockFetchQuery['BlockReward'] = 200;
@ -627,14 +633,26 @@ export class BlockchainBlockController {
const BlockchainPreviousBlockFetchQuery = await getRepository( const BlockchainPreviousBlockFetchQuery = await getRepository(
BlockchainBlock, BlockchainBlock,
).findOne({ ).findOne({
select: ['TotalDifficulty'], select: ['TotalDifficultyCuckaroo','TotalDifficultyCuckatoo','TotalDifficultyProgpow','TotalDifficultyRandomx'],
where: { Hash: BlockchainBlockFetchQuery.PreviousId }, where: { Hash: BlockchainBlockFetchQuery.PreviousId },
}); });
BlockchainBlockFetchQuery['TargetDifficulty'] = BlockchainBlockFetchQuery['TargetDifficultyCuckaroo'] =
parseInt(BlockchainBlockFetchQuery.TotalDifficulty) - parseInt(BlockchainBlockFetchQuery.TotalDifficultyCuckaroo) -
parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficulty); parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficultyCuckaroo);
BlockchainBlockFetchQuery['TargetDifficultyCuckatoo'] =
parseInt(BlockchainBlockFetchQuery.TotalDifficultyCuckatoo) -
parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficultyCuckatoo);
BlockchainBlockFetchQuery['TargetDifficultyProgpow'] =
parseInt(BlockchainBlockFetchQuery.TotalDifficultyProgpow) -
parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficultyProgpow);
BlockchainBlockFetchQuery['TargetDifficultyRandomx'] =
parseInt(BlockchainBlockFetchQuery.TotalDifficultyRandomx) -
parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficultyRandomx);
} else { } else {
BlockchainBlockFetchQuery['TargetDifficulty'] = 'NULL'; BlockchainBlockFetchQuery['TargetDifficultyCuckaroo'] = 'NULL';
BlockchainBlockFetchQuery['TargetDifficultyCuckatoo'] = 'NULL';
BlockchainBlockFetchQuery['TargetDifficultyProgpow'] = 'NULL';
BlockchainBlockFetchQuery['TargetDifficultyRandomx'] = 'NULL';
} }
var Epicfee = 0; var Epicfee = 0;
BlockchainBlockKernalFetchQuery.forEach(e => { BlockchainBlockKernalFetchQuery.forEach(e => {
@ -672,6 +690,7 @@ export class BlockchainBlockController {
}) })
: next(new NoDataFoundException()); : next(new NoDataFoundException());
} catch (error) { } catch (error) {
console.log('error',error);
next(new InternalServerErrorException(error)); next(new InternalServerErrorException(error));
} }
}; };
@ -765,22 +784,29 @@ export class BlockchainBlockController {
.select([ .select([
'blockchain_block.Hash', 'blockchain_block.Hash',
'blockchain_block.Timestamp', 'blockchain_block.Timestamp',
'blockchain_block.TotalDifficulty', 'blockchain_block.TotalDifficultyCuckaroo',
'blockchain_block.TotalDifficultyCuckatoo',
'blockchain_block.TotalDifficultyProgpow',
'blockchain_block.TotalDifficultyRandomx',
'blockchain_block.previous_id', 'blockchain_block.previous_id',
'blockchain_block.total_difficulty - LAG(blockchain_block.total_difficulty) OVER (ORDER BY blockchain_block.total_difficulty) AS target_difficulty', 'blockchain_block.total_difficulty_cuckaroo - LAG(blockchain_block.total_difficulty_cuckaroo) OVER (ORDER BY blockchain_block.total_difficulty_cuckaroo) AS target_difficulty_cuckaroo',
'blockchain_block.total_difficulty_cuckatoo - LAG(blockchain_block.total_difficulty_cuckatoo) OVER (ORDER BY blockchain_block.total_difficulty_cuckatoo) AS target_difficulty_cuckatoo',
'blockchain_block.total_difficulty_progpow - LAG(blockchain_block.total_difficulty_progpow) OVER (ORDER BY blockchain_block.total_difficulty_progpow) AS target_difficulty_progpow',
'blockchain_block.total_difficulty_randomx - LAG(blockchain_block.total_difficulty_randomx) OVER (ORDER BY blockchain_block.total_difficulty_randomx) AS target_difficulty_randomx',
'blockchain_block.Height', 'blockchain_block.Height',
'blockchain_block.EdgeBits', 'blockchain_block.EdgeBits',
'COUNT(DISTINCT(blockchain_input.block_id)) AS input_count', 'COUNT(DISTINCT(blockchain_input.block_id)) AS input_count',
'COUNT(DISTINCT(blockchain_kernel.block_id)) AS kernal_count', 'COUNT(DISTINCT(blockchain_kernel.block_id)) AS kernal_count',
'COUNT(DISTINCT(blockchain_output.block_id)) AS output_count', 'COUNT(DISTINCT(blockchain_output.block_id)) AS output_count',
'blockchain_block.Proof As PoWAlgo',
]) ])
.addSelect( // .addSelect(
`CASE // `CASE
WHEN blockchain_block.EdgeBits = 29 THEN 'CuckARoo29' // WHEN blockchain_block.EdgeBits = 29 THEN 'CuckARoo29'
WHEN blockchain_block.EdgeBits = 31 THEN 'CuckAToo31' // WHEN blockchain_block.EdgeBits = 31 THEN 'CuckAToo31'
END`, // END`,
'PoWAlgo', // 'PoWAlgo',
) // )
.leftJoin('blockchain_block.BlockchainInputs', 'blockchain_input') .leftJoin('blockchain_block.BlockchainInputs', 'blockchain_input')
.leftJoin('blockchain_block.BlockchainKernels', 'blockchain_kernel') .leftJoin('blockchain_block.BlockchainKernels', 'blockchain_kernel')
.leftJoin('blockchain_block.BlockchainOutputs', 'blockchain_output') .leftJoin('blockchain_block.BlockchainOutputs', 'blockchain_output')
@ -798,17 +824,41 @@ export class BlockchainBlockController {
const BlockchainPreviousBlockFetchQuery = await getRepository( const BlockchainPreviousBlockFetchQuery = await getRepository(
BlockchainBlock, BlockchainBlock,
).findOne({ ).findOne({
select: ['TotalDifficulty'], select: ['TotalDifficultyCuckaroo','TotalDifficultyCuckatoo','TotalDifficultyProgpow','TotalDifficultyRandomx'],
where: { Hash: lastElemt.previous_id }, where: { Hash: lastElemt.previous_id },
}); });
BlockchainBlockResult[BlockchainBlockResult.length - 1][ BlockchainBlockResult[BlockchainBlockResult.length - 1][
'target_difficulty' 'target_difficulty_cuckaroo'
] = ] =
(parseInt(lastElemt.blockchain_block_total_difficulty) (parseInt(lastElemt.blockchain_block_total_difficulty_cuckaroo)
? parseInt(lastElemt.blockchain_block_total_difficulty) ? parseInt(lastElemt.blockchain_block_total_difficulty_cuckaroo)
: 0) - : 0) -
parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficulty); parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficultyCuckaroo);
BlockchainBlockResult[BlockchainBlockResult.length - 1][
'target_difficulty_cuckatoo'
] =
(parseInt(lastElemt.blockchain_block_total_difficulty_cuckatoo)
? parseInt(lastElemt.blockchain_block_total_difficulty_cuckatoo)
: 0) -
parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficultyCuckatoo);
BlockchainBlockResult[BlockchainBlockResult.length - 1][
'target_difficulty_progpow'
] =
(parseInt(lastElemt.blockchain_block_total_difficulty_progpow)
? parseInt(lastElemt.blockchain_block_total_difficulty_progpow)
: 0) -
parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficultyProgpow);
BlockchainBlockResult[BlockchainBlockResult.length - 1][
'target_difficulty_randomx'
] =
(parseInt(lastElemt.blockchain_block_total_difficulty_randomx)
? parseInt(lastElemt.blockchain_block_total_difficulty_randomx)
: 0) -
parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficultyRandomx);
BlockchainBlockResult.forEach(e => { BlockchainBlockResult.forEach(e => {
var latest_block = this.dateDiff(e.blockchain_block_timestamp); var latest_block = this.dateDiff(e.blockchain_block_timestamp);
@ -836,6 +886,7 @@ export class BlockchainBlockController {
} }
} }
} catch (error) { } catch (error) {
console.log('error',error);
next(new InternalServerErrorException(error)); next(new InternalServerErrorException(error));
} }
}; };
@ -1352,14 +1403,15 @@ export class BlockchainBlockController {
} }
const BlockMineChartQuery = await getConnection() const BlockMineChartQuery = await getConnection()
.query( .query(
"SELECT hash, date , total_edge_bits, RandomX, Cuckoo, ProgPow, Round(RandomX * 100.0 / total_edge_bits,2) AS RandomXper, Round(Cuckoo * 100.0 / total_edge_bits,2) AS Cuckooper,Round(ProgPow * 100.0 / total_edge_bits,2) AS ProgPowper \ "SELECT hash, date , total_edge_bits, RandomX, Cuckaroo, Cuckatoo, ProgPow, Round(RandomX * 100.0 / total_edge_bits,2) AS RandomXper, Round(Cuckaroo * 100.0 / total_edge_bits,2) AS Cuckarooper, Round(Cuckatoo * 100.0 / total_edge_bits,2) AS Cuckatooper, Round(ProgPow * 100.0 / total_edge_bits,2) AS ProgPowper \
FROM (SELECT 1 as hash, \ FROM (SELECT 1 as hash, \
date(DATE_TRUNC('day', timestamp at time zone '" + date(DATE_TRUNC('day', timestamp at time zone '" +
process.env.TIME_ZONE + process.env.TIME_ZONE +
"')) as date, \ "')) as date, \
COUNT(edge_bits) AS total_edge_bits, \ COUNT(edge_bits) AS total_edge_bits, \
Count( CASE WHEN proof = 'RandomX' THEN 1 ELSE NULL END) AS RandomX, \ Count( CASE WHEN proof = 'RandomX' THEN 1 ELSE NULL END) AS RandomX, \
Count( CASE WHEN proof = 'Cuckoo' THEN 1 ELSE NULL END) AS Cuckoo,\ Count( CASE WHEN proof = 'Cuckaroo' THEN 1 ELSE NULL END) AS Cuckaroo,\
Count( CASE WHEN proof = 'Cuckatoo' THEN 1 ELSE NULL END) AS Cuckatoo,\
Count( CASE WHEN proof = 'ProgPow' THEN 1 ELSE NULL END) AS ProgPow \ Count( CASE WHEN proof = 'ProgPow' THEN 1 ELSE NULL END) AS ProgPow \
FROM blockchain_block \ FROM blockchain_block \
where " + where " +
@ -1373,20 +1425,23 @@ export class BlockchainBlockController {
}); });
let date = [], let date = [],
RandomXper = [], RandomXper = [],
Cuckooper = [], Cuckarooper = [],
Cuckatooper = [],
ProgPowper = [], ProgPowper = [],
RandomX = [], RandomX = [],
Cuckoo = [], Cuckatoo = [],
Cuckaroo = [],
ProgPow = []; ProgPow = [];
BlockMineChartQuery.forEach(e => { BlockMineChartQuery.forEach(e => {
console.log('e', e);
date.push(moment(e.date).format('YYYY-MM-DD')); date.push(moment(e.date).format('YYYY-MM-DD'));
RandomXper.push(parseFloat(e.randomxper)); RandomXper.push(parseFloat(e.randomxper));
Cuckooper.push(parseFloat(e.cuckooper)); Cuckarooper.push(parseFloat(e.cuckarooper));
Cuckatooper.push(parseFloat(e.cuckatooper));
ProgPowper.push(parseFloat(e.progpowper)); ProgPowper.push(parseFloat(e.progpowper));
RandomX.push(parseInt(e.randomx)); RandomX.push(parseInt(e.randomx));
Cuckoo.push(parseInt(e.cuckoo)); Cuckatoo.push(parseInt(e.cuckatoo));
Cuckaroo.push(parseInt(e.cuckaroo));
ProgPow.push(parseInt(e.progpow)); ProgPow.push(parseInt(e.progpow));
}); });
@ -1397,9 +1452,12 @@ export class BlockchainBlockController {
response: { response: {
date, date,
RandomXper, RandomXper,
Cuckarooper,
Cuckatooper,
ProgPowper, ProgPowper,
RandomX, RandomX,
Cuckoo, Cuckatoo,
Cuckaroo,
ProgPow, ProgPow,
}, },
}); });

View File

@ -61,9 +61,27 @@ export class BlockchainBlock {
@Column('bigint', { @Column('bigint', {
nullable: false, nullable: false,
name: 'total_difficulty', name: 'total_difficulty_cuckaroo',
}) })
TotalDifficulty: string; TotalDifficultyCuckaroo: string;
@Column('bigint', {
nullable: false,
name: 'total_difficulty_cuckatoo',
})
TotalDifficultyCuckatoo: string;
@Column('bigint', {
nullable: false,
name: 'total_difficulty_progpow',
})
TotalDifficultyProgpow: string;
@Column('bigint', {
nullable: false,
name: 'total_difficulty_randomx',
})
TotalDifficultyRandomx: string;
@Column('character varying', { @Column('character varying', {
nullable: false, nullable: false,
@ -92,13 +110,6 @@ export class BlockchainBlock {
}) })
Proof: string; Proof: string;
@Column('int4', {
nullable: false,
array: true,
name: 'cuckoo_solution',
})
CuckooSolution: number[];
@Column('character varying', { @Column('character varying', {
nullable: false, nullable: false,
length: 64, length: 64,