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;