Query for new api

This commit is contained in:
shunmugam 2019-09-18 13:15:27 +05:30
parent 9c13dcc459
commit 6641a6ad21
2 changed files with 26 additions and 2 deletions

View File

@ -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;

View File

@ -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);
@ -345,6 +346,24 @@ async function GetBlocktime(height){
}
}
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};