From a9de2c22679e1862d2ad1d3616312391364746dc Mon Sep 17 00:00:00 2001 From: shunmugam Date: Mon, 13 Jan 2020 13:32:25 +0530 Subject: [PATCH] Commit for avg block time testing --- server/i18n/en.json | 2 +- server/utils/common.ts | 31 ++++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/server/i18n/en.json b/server/i18n/en.json index 551a43f..a76cf6d 100644 --- a/server/i18n/en.json +++ b/server/i18n/en.json @@ -89,7 +89,7 @@ }, "api-view": { "query-api" : "Query API", - "maxcoins" : "Return maximum supply", + "maxcoins" : "returns maximum supply", "query-api-line1" : "The API function to call is specified through the q parameter.", "query-api-line2" : "For instance you can ask the totalcoins of epic cash with ", "circulating" : "returns the number of circulating coins", diff --git a/server/utils/common.ts b/server/utils/common.ts index 55cf9f8..53b8e09 100644 --- a/server/utils/common.ts +++ b/server/utils/common.ts @@ -463,12 +463,21 @@ let currentReward = 16; progpowhashrate = Math.round(progpowhashrate) randomxhashrate = Math.round(randomxhashrate) + // Test purpose + let test_cuckoo = await testavgBlockTime(block_height,"Cuckoo") + let test_randomx = await testavgBlockTime(block_height,"RandomX") + let test_progpow = await testavgBlockTime(block_height,"ProgPow") + + console.log("-----------------") + console.log("Cuckoo avg block time ", test_cuckoo) + console.log("randomx avg block time ", test_randomx) + console.log("Progpow avg block time ", test_progpow) + + + // Total foundation reward let totalFoundationReward = await circulationsupply(height) - console.log("-----------------------------------------------------------------------") - console.log("Function is calling") - return { block_height, letest_block, @@ -552,6 +561,22 @@ const averageblockdifficulty = async() => { +async function testavgBlockTime(height,proof) { + + // let query1 = "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" + let query1 = "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+" and proof = '"+proof+"' ) as bb" + const blockaveragetime = await getConnection(Global.network) + .query( + query1, + ) + .catch(err_msg => { + return(err_msg); + }); + + + return blockaveragetime[0]['alter'] +} + async function avgBlockTime(height,proof) {