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 { universalGetLatestBlockDetails } from "./server/socket";
|
||||||
import { dbConfig } from "./server/ormconfig";
|
import { dbConfig } from "./server/ormconfig";
|
||||||
import { config } from "dotenv";
|
import { config } from "dotenv";
|
||||||
import {latestBlockDetails, Details} from './server/utils';
|
import {latestBlockDetails, Details, GetBlocktime} from './server/utils';
|
||||||
config({ path: resolve(__dirname, "../.env") });
|
config({ path: resolve(__dirname, "../.env") });
|
||||||
|
|
||||||
// const connectionManager = getConnectionManager();
|
// const connectionManager = getConnectionManager();
|
||||||
@ -170,10 +170,21 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if(option == "getblockheight")
|
|
||||||
result = "";
|
else if(option == "getblocktime"){
|
||||||
else if(option == "getblocktime")
|
let height = req.query.height;
|
||||||
result = 60;
|
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")
|
else if(option == "info")
|
||||||
{
|
{
|
||||||
result = {
|
result = {
|
||||||
|
@ -326,7 +326,7 @@ async function GetBlocktime(height){
|
|||||||
if(height){
|
if(height){
|
||||||
const BlockchainLatestBlockQuery3 = await getConnection(Global.network)
|
const BlockchainLatestBlockQuery3 = await getConnection(Global.network)
|
||||||
.query(
|
.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 => {
|
.catch(err_msg => {
|
||||||
return(err_msg);
|
return(err_msg);
|
||||||
@ -336,4 +336,5 @@ async function GetBlocktime(height){
|
|||||||
}
|
}
|
||||||
|
|
||||||
export {latestBlockDetails};
|
export {latestBlockDetails};
|
||||||
|
export {GetBlocktime};
|
||||||
export {Details};
|
export {Details};
|
@ -1,9 +1,10 @@
|
|||||||
<p>api-view works!</p>
|
<div class="view_content py-4">
|
||||||
|
<div class="container">
|
||||||
<h3>Query API</h3>
|
<h3>Query API</h3>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
The API function to call is specified through the <code>q</code> parameter.<br>
|
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>
|
</p>
|
||||||
<h4>Real-Time Simple Queries</h4>
|
<h4>Real-Time Simple Queries</h4>
|
||||||
<ul>
|
<ul>
|
||||||
@ -23,4 +24,6 @@
|
|||||||
<li><b>getblockhash</b>: takes a <code>height</code> parameter and returns corresponding block hash.</li>
|
<li><b>getblockhash</b>: takes a <code>height</code> parameter and returns corresponding block hash.</li>
|
||||||
<li><b>getblockheight</b>: takes a <code>hash</code> parameter and returns corresponding block height.</li>
|
<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>
|
<li><b>getblocktime</b>: takes a <code>height</code> parameter and returns unixtime of the block.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
Loading…
Reference in New Issue
Block a user