From 6641a6ad2192da635abf0fe0a4e1c60977b86a34 Mon Sep 17 00:00:00 2001 From: shunmugam Date: Wed, 18 Sep 2019 13:15:27 +0530 Subject: [PATCH] Query for new api --- server.ts | 7 ++++++- server/utils/common.ts | 21 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/server.ts b/server.ts index 6d34741..e382636 100644 --- a/server.ts +++ b/server.ts @@ -56,7 +56,7 @@ BlockchainOutput import { universalGetLatestBlockDetails } from "./server/socket"; import { dbConfig } from "./server/ormconfig"; import { config } from "dotenv"; -import {latestBlockDetails, Details, GetBlocktime} from './server/utils'; +import {latestBlockDetails, Details, GetBlocktime, averageblockdifficulty} from './server/utils'; config({ path: resolve(__dirname, "../.env") }); // const connectionManager = getConnectionManager(); @@ -142,6 +142,11 @@ try { result = Number(blockDetails.TotalDifficultyProgpow); else if(option == "totalcoins") result = 21000000 * 100000000; + else if(option == "average-blocktime") + { + let data = await averageblockdifficulty(); + result = Number(data); + } else if(option == "getblockhash") { let height = req.query.height; diff --git a/server/utils/common.ts b/server/utils/common.ts index 16cd5e4..14e0f9b 100644 --- a/server/utils/common.ts +++ b/server/utils/common.ts @@ -1,5 +1,6 @@ import { getConnection } from "typeorm"; import { Global } from "../global"; +import { async } from '@angular/core/testing'; function convertMinsToHrmin (millseconds,insec) { var seconds = Math.floor(millseconds / 1000); @@ -344,7 +345,25 @@ async function GetBlocktime(height){ return BlockchainLatestBlockQuery3; } } - + + +const averageblockdifficulty = async() => { + + + const BlockchainBlockPerSecondQuery = await getConnection(Global.network) + .query( + "select 86400/count(hash) as period \ + from blockchain_block \ + where height != 0 AND timestamp < NOW() - INTERVAL '24 HOURS' " + ) + .catch(err_msg => { + return(err_msg); + }); + return BlockchainBlockPerSecondQuery[0]['period']; + +} + +export {averageblockdifficulty}; export {latestBlockDetails}; export {GetBlocktime}; export {Details}; \ No newline at end of file