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

\ No newline at end of file + +
+
\ No newline at end of file