From 5fc90e7d91cebbd617c57a29320aee857a760c82 Mon Sep 17 00:00:00 2001 From: shunmugam Date: Wed, 8 Jan 2020 14:50:39 +0530 Subject: [PATCH] Modifications --- server/utils/common.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/server/utils/common.ts b/server/utils/common.ts index 1f59e46..eb9c9ee 100644 --- a/server/utils/common.ts +++ b/server/utils/common.ts @@ -375,25 +375,28 @@ async function avgBlockTime(height) { const blockaveragetime = await getConnection(Global.network) .query( - 'SELECT coalesce(avg(bb.alter), 0) as alter FROM (SELECT EXTRACT(EPOCH FROM (timestamp - LAG(timestamp) OVER (ORDER BY timestamp))) AS alter FROM blockchain_block where height < 1145 AND height > 2154 ) as bb', + 'SELECT coalesce(avg(bb.alter), 0) as alter FROM (SELECT EXTRACT(EPOCH FROM (timestamp - LAG(timestamp) OVER (ORDER BY timestamp))) AS alter FROM blockchain_block where height > '+(height - 1440)+' AND height < '+height+' ) as bb', ) .catch(err_msg => { return(err_msg); }); - - console.log("_________________________________"); - console.log("Block Average time is ",blockaveragetime) + return blockaveragetime['alter'] } async function network_hashrate(height, edge_bits, difficulty) { + let graph_wight = await avgBlockTime(height) + return (difficulty / graph_wight); + } + + + async function network_hashrate_old(height, edge_bits, difficulty) { let graph_wight = await graph_weight(height, edge_bits) return (42.0 * (difficulty / graph_wight) / 60.0); } - async function graph_weight(height, edge_bits) { let xpr_edge_bits = edge_bits;