Updated
This commit is contained in:
parent
b375aaa153
commit
e8d1ce2b0a
21
server.ts
21
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 = {
|
||||
|
@ -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};
|
@ -1,9 +1,10 @@
|
||||
<p>api-view works!</p>
|
||||
<div class="view_content py-4">
|
||||
<div class="container">
|
||||
<h3>Query API</h3>
|
||||
|
||||
<p>
|
||||
The API function to call is specified through the <code>q</code> parameter.<br>
|
||||
For instance you can ask the current difficulty of Riecoin with "<i>https://explorer.epic.tech/api?q=totalcoins</i>".
|
||||
For instance you can ask the totalcoins of epic cash with "<i>https://explorer.epic.tech/api?q=totalcoins</i>".
|
||||
</p>
|
||||
<h4>Real-Time Simple Queries</h4>
|
||||
<ul>
|
||||
@ -24,3 +25,5 @@
|
||||
<li><b>getblockheight</b>: takes a <code>hash</code> parameter and returns corresponding block height.</li>
|
||||
<li><b>getblocktime</b>: takes a <code>height</code> parameter and returns unixtime of the block.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user