Commit - Network hashrate API
This commit is contained in:
parent
1faced0365
commit
8fda4d1e57
17
server.ts
17
server.ts
@ -56,7 +56,7 @@ BlockchainOutput
|
||||
import { universalGetLatestBlockDetails } from "./server/socket";
|
||||
import { dbConfig } from "./server/ormconfig";
|
||||
import { config } from "dotenv";
|
||||
import {latestBlockDetails, Details, GetBlocktime, averageblockdifficulty} from './server/utils';
|
||||
import {latestBlockDetails, Details, GetBlocktime, averageblockdifficulty, network_hashrate} from './server/utils';
|
||||
config({ path: resolve(__dirname, "../.env") });
|
||||
|
||||
// const connectionManager = getConnectionManager();
|
||||
@ -147,6 +147,21 @@ try {
|
||||
let data = await averageblockdifficulty();
|
||||
result = Number(data);
|
||||
}
|
||||
else if(option == "network-hashrate-cuckoo")
|
||||
{
|
||||
let data = await network_hashrate(blockDetails.block_height,31,blockDetails.targetdifficultycuckatoo);
|
||||
result = data;
|
||||
}
|
||||
else if(option == "network-hashrate-progpow")
|
||||
{
|
||||
let data = await network_hashrate(blockDetails.block_height,16,blockDetails.targetdifficultyprogpow);
|
||||
result = data;
|
||||
}
|
||||
else if(option == "network-hashrate-randomx")
|
||||
{
|
||||
let data = await network_hashrate(blockDetails.block_height,16,blockDetails.targetdifficultyrandomx);
|
||||
result = data;
|
||||
}
|
||||
else if(option == "getblockhash")
|
||||
{
|
||||
let height = req.query.height;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { getConnection } from "typeorm";
|
||||
import { getConnection, AdvancedConsoleLogger } from "typeorm";
|
||||
import { Global } from "../global";
|
||||
import { async } from '@angular/core/testing';
|
||||
|
||||
@ -363,6 +363,44 @@ const averageblockdifficulty = async() => {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
async function network_hashrate(height, edge_bits, difficulty) {
|
||||
let graph_wight = await graph_weight(height, edge_bits)
|
||||
return (42.0 * (difficulty / graph_wight) / 60.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
async function graph_weight(height, edge_bits) {
|
||||
let xpr_edge_bits = edge_bits;
|
||||
|
||||
let min_edge_bits = 19;
|
||||
if(min_edge_bits == 19) {
|
||||
min_edge_bits += 12;
|
||||
}
|
||||
|
||||
let bits_over_min =Math.max(0, (edge_bits - min_edge_bits));
|
||||
let expiry_height = (1 << bits_over_min) * 524160;
|
||||
|
||||
if(height >= expiry_height) {
|
||||
xpr_edge_bits = Math.max(0,(xpr_edge_bits-(1 + (height - expiry_height) / 10080)));
|
||||
}
|
||||
|
||||
let final_val;
|
||||
if(edge_bits > 24) {
|
||||
final_val = edge_bits - 24;
|
||||
} else {
|
||||
final_val = 24 - edge_bits;
|
||||
}
|
||||
|
||||
return (2 << final_val) * xpr_edge_bits;
|
||||
}
|
||||
|
||||
|
||||
export {network_hashrate};
|
||||
export {averageblockdifficulty};
|
||||
export {latestBlockDetails};
|
||||
export {GetBlocktime};
|
||||
|
Loading…
Reference in New Issue
Block a user