Query for new api
This commit is contained in:
parent
9c13dcc459
commit
6641a6ad21
@ -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;
|
||||
|
@ -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);
|
||||
@ -344,7 +345,25 @@ async function GetBlocktime(height){
|
||||
return BlockchainLatestBlockQuery3;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
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};
|
Loading…
Reference in New Issue
Block a user