From e8d1ce2b0a50a91c605fc44f927963a6c90a1cd8 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 6 Sep 2019 19:19:43 +0530 Subject: [PATCH] Updated --- server.ts | 21 ++++++++++++++----- server/utils/common.ts | 3 ++- src/app/view/api-view/api-view.component.html | 9 +++++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/server.ts b/server.ts index 225cb52..0e922d0 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} from './server/utils'; +import {latestBlockDetails, Details, GetBlocktime} from './server/utils'; config({ path: resolve(__dirname, "../.env") }); // const connectionManager = getConnectionManager(); @@ -170,10 +170,21 @@ try { } } - else if(option == "getblockheight") - result = ""; - else if(option == "getblocktime") - result = 60; + + else if(option == "getblocktime"){ + let height = req.query.height; + if(height) { + let blockTime = await GetBlocktime(height); + if(blockTime[0].alter) + result = blockTime[0].alter; + else + result = 'Invalid height'; + } else if(height < 0) { + result = '"height" parameter missing or invalid'; + } else { + result = '"height" parameter missing or invalid'; + } + } else if(option == "info") { result = { diff --git a/server/utils/common.ts b/server/utils/common.ts index 438830a..7120389 100644 --- a/server/utils/common.ts +++ b/server/utils/common.ts @@ -326,7 +326,7 @@ async function GetBlocktime(height){ if(height){ const BlockchainLatestBlockQuery3 = await getConnection(Global.network) .query( - "SELECT height, EXTRACT(EPOCH FROM (timestamp - LAG(timestamp) OVER (ORDER BY timestamp))) AS alter FROM blockchain_block where height="+height, + "SELECT coalesce(max(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+" OR height="+(height-1)+") as bb", ) .catch(err_msg => { return(err_msg); @@ -336,4 +336,5 @@ async function GetBlocktime(height){ } export {latestBlockDetails}; +export {GetBlocktime}; export {Details}; \ No newline at end of file diff --git a/src/app/view/api-view/api-view.component.html b/src/app/view/api-view/api-view.component.html index 010ced1..5cae3de 100644 --- a/src/app/view/api-view/api-view.component.html +++ b/src/app/view/api-view/api-view.component.html @@ -1,9 +1,10 @@ -

api-view works!

+
+

Query API

The API function to call is specified through the q parameter.
- For instance you can ask the current difficulty of Riecoin with "https://explorer.epic.tech/api?q=totalcoins". + For instance you can ask the totalcoins of epic cash with "https://explorer.epic.tech/api?q=totalcoins".

Real-Time Simple Queries

    @@ -23,4 +24,6 @@
  • getblockhash: takes a height parameter and returns corresponding block hash.
  • getblockheight: takes a hash parameter and returns corresponding block height.
  • getblocktime: takes a height parameter and returns unixtime of the block.
  • -
\ No newline at end of file + +
+
\ No newline at end of file