latest block

This commit is contained in:
raja.blaze 2019-08-29 10:44:05 +05:30
parent bd9a19e342
commit a01b2ca069
4 changed files with 152 additions and 15 deletions

View File

@ -189,7 +189,7 @@ console.log(__dirname);
console.log(`Node Express server listening on http://localhost:${PORT}`); console.log(`Node Express server listening on http://localhost:${PORT}`);
}); });
cron.schedule('* * * * * *', () => { cron.schedule('* * * * *', () => {
universalGetLatestBlockDetails('Testnet'); universalGetLatestBlockDetails('Testnet');
universalGetLatestBlockDetails('Floonet'); universalGetLatestBlockDetails('Floonet');
}); });

View File

@ -1,6 +1,8 @@
import { getConnection } from "typeorm"; import { getConnection } from "typeorm";
import { Global } from "../global"; import { Global } from "../global";
import {
BlockchainBlock,
} from '../entities';
var moment = require("moment"); var moment = require("moment");
moment.updateLocale('en', { moment.updateLocale('en', {
relativeTime: { relativeTime: {
@ -300,6 +302,105 @@ export async function universalGetLatestBlockDetails(current_network) {
BlockchainLatestBlockQuery[0].total_difficulty_randomx BlockchainLatestBlockQuery[0].total_difficulty_randomx
} }
const BlockchainBlockPaginationQuery = await getConnection(current_network).getRepository(
BlockchainBlock,
)
.createQueryBuilder('blockchain_block')
.select([
'blockchain_block.Hash',
'blockchain_block.Timestamp',
'(blockchain_block.TotalDifficultyCuckaroo + blockchain_block.TotalDifficultyCuckatoo) as TotalCuckoo',
'blockchain_block.TotalDifficultyCuckaroo',
'blockchain_block.TotalDifficultyCuckatoo',
'blockchain_block.TotalDifficultyProgpow',
'blockchain_block.TotalDifficultyRandomx',
'blockchain_block.previous_id',
'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.EdgeBits',
'COUNT(DISTINCT(blockchain_input.block_id)) AS input_count',
'COUNT(DISTINCT(blockchain_kernel.block_id)) AS kernal_count',
'COUNT(DISTINCT(blockchain_output.block_id)) AS output_count',
'blockchain_block.Proof As PoWAlgo',
])
.leftJoin('blockchain_block.BlockchainInputs', 'blockchain_input')
.leftJoin('blockchain_block.BlockchainKernels', 'blockchain_kernel')
.leftJoin('blockchain_block.BlockchainOutputs', 'blockchain_output')
.skip(0)
.take(20)
.orderBy('blockchain_block.Timestamp', 'DESC')
.groupBy('blockchain_block.Hash')
.getRawAndEntities();
//console.log(BlockchainBlockPaginationQuery.raw);
let BlockchainBlockResult = BlockchainBlockPaginationQuery.raw;
let lastElemt =
BlockchainBlockResult[BlockchainBlockResult.length - 1];
const BlockchainPreviousBlockFetchQuery = await getConnection(Global.network).getRepository(
BlockchainBlock,
).findOne({
select: ['TotalDifficultyCuckaroo', 'TotalDifficultyCuckatoo', 'TotalDifficultyProgpow', 'TotalDifficultyRandomx'],
where: { Hash: lastElemt.previous_id },
});
BlockchainBlockResult[BlockchainBlockResult.length - 1][
'target_difficulty_cuckaroo'
] = BlockchainPreviousBlockFetchQuery &&
BlockchainPreviousBlockFetchQuery != undefined ?
(parseInt(lastElemt.blockchain_block_total_difficulty_cuckaroo)
? parseInt(lastElemt.blockchain_block_total_difficulty_cuckaroo)
: 0) -
(parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficultyCuckaroo) ? parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficultyCuckaroo) : 0)
: 0;
BlockchainBlockResult[BlockchainBlockResult.length - 1][
'target_difficulty_cuckatoo'
] = BlockchainPreviousBlockFetchQuery &&
BlockchainPreviousBlockFetchQuery != undefined ?
(parseInt(lastElemt.blockchain_block_total_difficulty_cuckatoo)
? parseInt(lastElemt.blockchain_block_total_difficulty_cuckatoo)
: 0) -
(parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficultyCuckatoo) ? parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficultyCuckatoo) : 0)
: 0;
BlockchainBlockResult[BlockchainBlockResult.length - 1][
'target_difficulty_progpow'
] = BlockchainPreviousBlockFetchQuery &&
BlockchainPreviousBlockFetchQuery != undefined ?
(parseInt(lastElemt.blockchain_block_total_difficulty_progpow)
? parseInt(lastElemt.blockchain_block_total_difficulty_progpow)
: 0) -
(parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficultyProgpow) ? parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficultyProgpow) : 0)
: 0;
BlockchainBlockResult[BlockchainBlockResult.length - 1][
'target_difficulty_randomx'
] = BlockchainPreviousBlockFetchQuery &&
BlockchainPreviousBlockFetchQuery != undefined ?
(parseInt(lastElemt.blockchain_block_total_difficulty_randomx)
? parseInt(lastElemt.blockchain_block_total_difficulty_randomx)
: 0) -
(parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficultyRandomx) ? parseInt(BlockchainPreviousBlockFetchQuery.TotalDifficultyRandomx) : 0)
: 0;
BlockchainBlockResult.forEach(e => {
var latest_block = dateDiff(e.blockchain_block_timestamp);
e['hashstart'] = e.blockchain_block_hash.slice(0, 2);
e['hashend'] = e.blockchain_block_hash.slice(62, 64);
let balance = e.blockchain_block_hash.substring(2, 62);
let arr = balance.match(/.{1,6}/g);
e['hasharray'] = arr.map(i => '#' + i);
e['age'] = latest_block;
});
//console.log(BlockchainBlockResult);
final_result['BlockchainBlockResult']= BlockchainBlockResult;
Global.client.set(key, JSON.stringify(final_result), 'EX', parseInt(process.env.REDIS_EXPIRY), function(err){ Global.client.set(key, JSON.stringify(final_result), 'EX', parseInt(process.env.REDIS_EXPIRY), function(err){
//client.set(key, JSON.stringify(body)); //client.set(key, JSON.stringify(body));
}); });

View File

@ -18,7 +18,7 @@
<div class="block_div"><h6 >Age</h6><span class="blck_value">{{ blockdetails.age }}</span></div> <div class="block_div"><h6 >Age</h6><span class="blck_value">{{ blockdetails.age }}</span></div>
</div> </div>
<div class="col-6 col-md-3 tble_col"> <div class="col-6 col-md-3 tble_col">
<div class="block_div"><h6>Difficulty</h6><span class="blck_value">{{ blockdetails.target_difficulty | number }}</span></div> <div class="block_div"><h6>Difficulty</h6><span class="blck_value">{{(blockdetails.PoWAlgo == 'Cuckoo') ? (blockdetails.target_difficulty_cuckatoo | number) : (blockdetails.PoWAlgo == 'RandomX') ? (blockdetails.target_difficulty_randomx | number) : (blockdetails.PoWAlgo == 'ProgPow') ? (blockdetails.target_difficulty_progpow | number) : 0}}</span></div>
</div> </div>
<div class="col-6 col-sm-6 col-md-3 tble_col"> <div class="col-6 col-sm-6 col-md-3 tble_col">
<div class="block_div"><h6 class="mb-0">Pow Algo</h6><span class="blck_value">{{ blockdetails.PoWAlgo }}</span></div> <div class="block_div"><h6 class="mb-0">Pow Algo</h6><span class="blck_value">{{ blockdetails.PoWAlgo }}</span></div>

View File

@ -15,6 +15,9 @@ import { BlockAppendComponent } from '../block-append/block-append.component';
export class LatestblocksComponent implements OnInit { export class LatestblocksComponent implements OnInit {
public hashvalues: any; public hashvalues: any;
public pagedata: any = []; public pagedata: any = [];
public CurrentpageNumber: Number;
public FirstPageListData: any = [];
public DifferentList: any = [];
public blockAppend: any; public blockAppend: any;
public blockdetails: any; public blockdetails: any;
public lastblock: any; public lastblock: any;
@ -41,6 +44,7 @@ export class LatestblocksComponent implements OnInit {
public gettinghashList(CurrentPage, PageSize) { public gettinghashList(CurrentPage, PageSize) {
let params = new HttpParams(); let params = new HttpParams();
this.CurrentpageNumber = CurrentPage;
params = params.append('CurrentPage', CurrentPage); params = params.append('CurrentPage', CurrentPage);
params = params.append('PageSize', PageSize); params = params.append('PageSize', PageSize);
this.chartService.apiGetRequest(params, '/blockchain_block/list').subscribe( this.chartService.apiGetRequest(params, '/blockchain_block/list').subscribe(
@ -49,6 +53,7 @@ export class LatestblocksComponent implements OnInit {
this.pagedata = res.response; this.pagedata = res.response;
this.hashvalues = res.response.BlockchainBlockResult; this.hashvalues = res.response.BlockchainBlockResult;
if(CurrentPage == 1){ if(CurrentPage == 1){
this.FirstPageListData = res.response.BlockchainBlockResult;
this.lastblock = res.response.BlockchainBlockResult[0].blockchain_block_height; this.lastblock = res.response.BlockchainBlockResult[0].blockchain_block_height;
//console.log(this.lastblock); //console.log(this.lastblock);
@ -67,30 +72,61 @@ export class LatestblocksComponent implements OnInit {
//console.log('Create'); //console.log('Create');
//this.createBlock(); //this.createBlock();
} }
if (this.CurrentpageNumber == 1) {
// console.log("Enter If");
// console.log(this.blockdetails);
console.log(this.FirstPageListData);
var onlyInA = this.FirstPageListData.filter(this.comparer(this.blockdetails.BlockchainBlockResult));
var onlyInB = this.blockdetails.BlockchainBlockResult.filter(this.comparer(this.FirstPageListData));
this.DifferentList = onlyInA.concat(onlyInB);
this.DifferentList.forEach(DifferentList => {
this.createBlock(DifferentList)
});
console.log(this.DifferentList);
}
this.lastblock = this.blockdetails.block_height; this.lastblock = this.blockdetails.block_height;
//console.log(this.lastblock); //console.log(this.lastblock);
}); });
} }
public createBlock() { public comparer(otherArray){
return function(current){
return otherArray.filter(function(other){
return other.blockchain_block_height == current.blockchain_block_height
}).length == 0;
}
}
public createBlock(DifferentList) {
this.FirstPageListData.unshift(DifferentList);
const blockFactory = this.resolver.resolveComponentFactory( const blockFactory = this.resolver.resolveComponentFactory(
BlockAppendComponent, BlockAppendComponent,
); );
const block = this.block.createComponent(blockFactory, 0); const block = this.block.createComponent(blockFactory, 0);
this.blockAppend = {}; this.blockAppend = {};
this.blockAppend['blockchain_block_hash'] = this.blockdetails.hash; this.blockAppend['blockchain_block_hash'] = DifferentList.blockchain_block_hash;
this.blockAppend[ this.blockAppend[
'blockchain_block_height' 'blockchain_block_height'
] = this.blockdetails.block_height; ] = DifferentList.blockchain_block_height;
this.blockAppend['age'] = this.blockdetails.age; this.blockAppend['age'] = DifferentList.age;
this.blockAppend['target_difficulty'] = this.blockdetails.Difficulty; //this.blockAppend['target_difficulty'] = 0;
this.blockAppend['PoWAlgo'] = this.blockdetails.proof; this.blockAppend['PoWAlgo'] = DifferentList.powalgo;
this.blockAppend['input_count'] = this.blockdetails.input_count; this.blockAppend['input_count'] = DifferentList.input_count;
this.blockAppend['output_count'] = this.blockdetails.output_count; this.blockAppend['output_count'] = DifferentList.output_count;
this.blockAppend['kernal_count'] = this.blockdetails.kernel_count; this.blockAppend['kernal_count'] = DifferentList.kernal_count;
this.blockAppend['hashstart'] = this.blockdetails.hashstart; this.blockAppend['hashstart'] = DifferentList.hashstart;
this.blockAppend['hashend'] = this.blockdetails.hashend; this.blockAppend['hashend'] = DifferentList.hashend;
this.blockAppend['hasharray'] = this.blockdetails.hasharray; this.blockAppend['hasharray'] = DifferentList.hasharray;
this.blockAppend['target_difficulty_cuckaroo'] = DifferentList.target_difficulty_cuckaroo;
this.blockAppend['target_difficulty_cuckatoo'] = DifferentList.target_difficulty_cuckatoo;
this.blockAppend['target_difficulty_progpow'] = DifferentList.target_difficulty_progpow;
this.blockAppend['target_difficulty_randomx'] = DifferentList.target_difficulty_randomx;
//console.log( this.blockAppend);
block.instance.blockdetails = this.blockAppend; block.instance.blockdetails = this.blockAppend;
} }