Database Changed
This commit is contained in:
parent
15dcd6b30d
commit
395d3a2471
52
server.ts
52
server.ts
@ -20,6 +20,7 @@ Object.defineProperty(window.document.body.style, "transform", {
|
||||
global["document"] = window.document;
|
||||
|
||||
import { enableProdMode } from "@angular/core";
|
||||
import { Global } from "./server/global";
|
||||
|
||||
// Express Engine
|
||||
import { ngExpressEngine } from "@nguniversal/express-engine";
|
||||
@ -36,7 +37,8 @@ import {
|
||||
getRepository,
|
||||
In,
|
||||
getConnection,
|
||||
getConnectionManager
|
||||
getConnectionManager,
|
||||
createConnections
|
||||
} from "typeorm";
|
||||
import { resolve } from "path";
|
||||
import {
|
||||
@ -45,14 +47,20 @@ import {
|
||||
BlockchainKernelController,
|
||||
BlockchainOutputController
|
||||
} from "./server/controllers";
|
||||
import {
|
||||
BlockchainBlock,
|
||||
BlockchainInput,
|
||||
BlockchainKernel,
|
||||
BlockchainOutput
|
||||
} from "./server/entities";
|
||||
import { universalGetLatestBlockDetails } from "./server/socket";
|
||||
import { dbConfig } from "./server/ormconfig";
|
||||
import { config } from "dotenv";
|
||||
|
||||
config({ path: resolve(__dirname, "../.env") });
|
||||
|
||||
const connectionManager = getConnectionManager();
|
||||
const connection = connectionManager.create(dbConfig);
|
||||
// const connectionManager = getConnectionManager();
|
||||
// const connection = connectionManager.create(dbConfig);
|
||||
|
||||
import { join } from "path";
|
||||
|
||||
@ -140,17 +148,47 @@ app.get("*", (req, res) => {
|
||||
});
|
||||
|
||||
// Start up the Node server
|
||||
console.log(__dirname);
|
||||
// connection
|
||||
// .connect()
|
||||
// .then(() => {
|
||||
createConnections([ {
|
||||
name: 'Floonet',
|
||||
type: 'postgres',
|
||||
host: process.env.FLOONET_DB_HOST,
|
||||
port: Number(process.env.FLOONET_DB_PORT),
|
||||
username: process.env.FLOONET_DB_USERNAME,
|
||||
password: process.env.FLOONET_DB_PASSWORD,
|
||||
database: process.env.FLOONET_DB_DATABASE,
|
||||
synchronize: false,
|
||||
logging: false,
|
||||
entities: [BlockchainBlock,
|
||||
BlockchainInput,
|
||||
BlockchainKernel,
|
||||
BlockchainOutput],
|
||||
}, {
|
||||
name: 'Testnet',
|
||||
type: 'postgres',
|
||||
host: process.env.TESTNET_DB_HOST,
|
||||
port: Number(process.env.TESTNET_DB_PORT),
|
||||
username: process.env.TESTNET_DB_USERNAME,
|
||||
password: process.env.TESTNET_DB_PASSWORD,
|
||||
database: process.env.TESTNET_DB_DATABASE,
|
||||
synchronize: false,
|
||||
logging: false,
|
||||
entities: [BlockchainBlock,
|
||||
BlockchainInput,
|
||||
BlockchainKernel,
|
||||
BlockchainOutput],
|
||||
}]).then(async () => {
|
||||
|
||||
connection
|
||||
.connect()
|
||||
.then(() => {
|
||||
const server = app.listen(PORT, () => {
|
||||
console.log(`Node Express server listening on http://localhost:${PORT}`);
|
||||
});
|
||||
const io = require("socket.io").listen(server);
|
||||
io.sockets.on("connection", socket => {
|
||||
// setInterval(function() {
|
||||
// //universalGetLatestBlockDetails(socket);
|
||||
// universalGetLatestBlockDetails(socket);
|
||||
// },1000);
|
||||
});
|
||||
})
|
||||
|
@ -1,4 +1,5 @@
|
||||
import express from 'express';
|
||||
import { Global } from "../global";
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { getRepository, getConnection } from 'typeorm';
|
||||
import { validationMiddleware } from '../middlewares';
|
||||
@ -646,7 +647,7 @@ export class BlockchainBlockController {
|
||||
) => {
|
||||
try {
|
||||
const BlockchainBlockRequestData: BlockchainBlockCreateDto = request.body;
|
||||
const BlockchainBlockCreateQuery = await getRepository(
|
||||
const BlockchainBlockCreateQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainBlock,
|
||||
).save(BlockchainBlockRequestData);
|
||||
response.status(200).json({
|
||||
@ -658,7 +659,7 @@ export class BlockchainBlockController {
|
||||
} catch (error) {
|
||||
next(new InternalServerErrorException(error));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
private BlockchainBlockFetch = async (
|
||||
request: Request,
|
||||
@ -666,7 +667,7 @@ export class BlockchainBlockController {
|
||||
next: NextFunction,
|
||||
) => {
|
||||
try {
|
||||
var BlockchainBlockFetchQuery = await getRepository(
|
||||
var BlockchainBlockFetchQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainBlock,
|
||||
).findOne({
|
||||
select: [
|
||||
@ -691,7 +692,7 @@ export class BlockchainBlockController {
|
||||
paramVal.length <= 10 &&
|
||||
paramVal <= 2147483647
|
||||
) {
|
||||
var BlockchainBlockFetchQuery = await getRepository(
|
||||
var BlockchainBlockFetchQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainBlock,
|
||||
).findOne({
|
||||
select: [
|
||||
@ -713,21 +714,21 @@ export class BlockchainBlockController {
|
||||
if (!BlockchainBlockFetchQuery) {
|
||||
next(new NoDataFoundException());
|
||||
}else{
|
||||
const BlockchainBlockInputFetchQuery = await getRepository(
|
||||
const BlockchainBlockInputFetchQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainInput,
|
||||
).find({
|
||||
select: ['Data'],
|
||||
where: { BlockId: BlockchainBlockFetchQuery.Hash },
|
||||
});
|
||||
|
||||
const BlockchainBlockOutputFetchQuery = await getRepository(
|
||||
const BlockchainBlockOutputFetchQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainOutput,
|
||||
).find({
|
||||
select: ['OutputType', 'Commit', 'Spent'],
|
||||
where: { BlockId: BlockchainBlockFetchQuery.Hash },
|
||||
});
|
||||
|
||||
const BlockchainBlockKernalFetchQuery = await getRepository(
|
||||
const BlockchainBlockKernalFetchQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainKernel,
|
||||
).find({
|
||||
select: ['Features', 'Fee', 'LockHeight'],
|
||||
@ -801,7 +802,7 @@ export class BlockchainBlockController {
|
||||
// }
|
||||
|
||||
if (BlockchainBlockFetchQuery.PreviousId) {
|
||||
const BlockchainPreviousBlockFetchQuery = await getRepository(
|
||||
const BlockchainPreviousBlockFetchQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainBlock,
|
||||
).findOne({
|
||||
select: ['TotalDifficultyCuckaroo', 'TotalDifficultyCuckatoo', 'TotalDifficultyProgpow', 'TotalDifficultyRandomx'],
|
||||
@ -875,7 +876,7 @@ export class BlockchainBlockController {
|
||||
) => {
|
||||
try {
|
||||
const BlockchainBlockRequestData: BlockchainBlockUpdateDto = request.body;
|
||||
const BlockchainBlockUpdateQuery = await getRepository(
|
||||
const BlockchainBlockUpdateQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainBlock,
|
||||
).update(BlockchainBlockRequestData.Hash, BlockchainBlockRequestData);
|
||||
response.status(200).json({
|
||||
@ -895,7 +896,7 @@ export class BlockchainBlockController {
|
||||
next: NextFunction,
|
||||
) => {
|
||||
try {
|
||||
const BlockchainBlockDeleteQuery = await getRepository(
|
||||
const BlockchainBlockDeleteQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainBlock,
|
||||
).delete(request.params.Hash);
|
||||
BlockchainBlockDeleteQuery
|
||||
@ -931,7 +932,7 @@ export class BlockchainBlockController {
|
||||
// next(new IntegerValidationException('MaxPages'));
|
||||
// }
|
||||
else {
|
||||
const BlockchainBlockCountQuery = await getRepository(BlockchainBlock)
|
||||
const BlockchainBlockCountQuery = await getConnection(Global.network).getRepository(BlockchainBlock)
|
||||
.createQueryBuilder()
|
||||
.getCount();
|
||||
if (BlockchainBlockCountQuery) {
|
||||
@ -950,7 +951,7 @@ export class BlockchainBlockController {
|
||||
// Hash: 'DESC',
|
||||
// },
|
||||
// });
|
||||
const BlockchainBlockPaginationQuery = await getRepository(
|
||||
const BlockchainBlockPaginationQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainBlock,
|
||||
)
|
||||
.createQueryBuilder('blockchain_block')
|
||||
@ -995,7 +996,7 @@ export class BlockchainBlockController {
|
||||
let BlockchainBlockResult = BlockchainBlockPaginationQuery.raw;
|
||||
let lastElemt =
|
||||
BlockchainBlockResult[BlockchainBlockResult.length - 1];
|
||||
const BlockchainPreviousBlockFetchQuery = await getRepository(
|
||||
const BlockchainPreviousBlockFetchQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainBlock,
|
||||
).findOne({
|
||||
select: ['TotalDifficultyCuckaroo', 'TotalDifficultyCuckatoo', 'TotalDifficultyProgpow', 'TotalDifficultyRandomx'],
|
||||
@ -1113,7 +1114,7 @@ export class BlockchainBlockController {
|
||||
process.env.TIME_ZONE +
|
||||
"' > current_date - interval '1 day'";
|
||||
}
|
||||
const BlockQuery = await getConnection()
|
||||
const BlockQuery = await getConnection(Global.network)
|
||||
.query(
|
||||
"select 1 as hash, max(total_difficulty_cuckaroo) as total_difficulty_cuckaroo, \
|
||||
max(total_difficulty_cuckatoo) as total_difficulty_cuckatoo, \
|
||||
@ -1205,7 +1206,7 @@ export class BlockchainBlockController {
|
||||
var tickFormat = '%H-%M';
|
||||
}
|
||||
if(Difftype == "target"){
|
||||
var TotalDifficultyNBlockQuery = await getConnection()
|
||||
var TotalDifficultyNBlockQuery = await getConnection(Global.network)
|
||||
.query(
|
||||
"SELECT a.hash, a.total_difficulty_randomx, a.total_difficulty_cuckatoo,a.total_difficulty_progpow, a.date FROM(select 1 as hash, (total_difficulty_cuckatoo - LAG(total_difficulty_cuckatoo) OVER (ORDER BY total_difficulty_cuckatoo)) AS total_difficulty_cuckatoo, \
|
||||
(total_difficulty_progpow - LAG(total_difficulty_progpow) OVER (ORDER BY total_difficulty_progpow)) AS total_difficulty_progpow , \
|
||||
@ -1221,7 +1222,7 @@ export class BlockchainBlockController {
|
||||
next(err_msg);
|
||||
});
|
||||
}else if(Difftype == "total"){
|
||||
var TotalDifficultyNBlockQuery = await getConnection()
|
||||
var TotalDifficultyNBlockQuery = await getConnection(Global.network)
|
||||
.query(
|
||||
"select 1 as hash, total_difficulty_cuckatoo,total_difficulty_progpow,total_difficulty_randomx, \
|
||||
DATE_TRUNC('minute', timestamp at time zone '" +
|
||||
@ -1361,7 +1362,7 @@ export class BlockchainBlockController {
|
||||
process.env.TIME_ZONE +
|
||||
"' > current_date - interval '30 days'";
|
||||
}
|
||||
const stackNBlockQuery = await getConnection()
|
||||
const stackNBlockQuery = await getConnection(Global.network)
|
||||
.query(
|
||||
"select 1 as hash, date(DATE_TRUNC('day', timestamp at time zone '" +
|
||||
process.env.TIME_ZONE +
|
||||
@ -1445,7 +1446,7 @@ export class BlockchainBlockController {
|
||||
process.env.TIME_ZONE +
|
||||
"' > current_date - interval '30 days'";
|
||||
}
|
||||
const stackNBlockQuery = await getConnection()
|
||||
const stackNBlockQuery = await getConnection(Global.network)
|
||||
.query(
|
||||
"SELECT hash,total_edge_bits, RandomX, Cuckoo, ProgPow, Round(RandomX * 100.0 / total_edge_bits,2) AS RandomXper, Round(Cuckoo * 100.0 / total_edge_bits,2) AS Cuckooper, Round(ProgPow * 100.0 / total_edge_bits,2) AS ProgPowper from (select 1 as hash, COUNT(edge_bits) AS total_edge_bits, \
|
||||
Count( CASE WHEN proof = 'RandomX' THEN 1 ELSE NULL END) AS RandomX,\
|
||||
@ -1516,7 +1517,7 @@ export class BlockchainBlockController {
|
||||
var seriesquery = "now() - interval '30 days', now()";
|
||||
}
|
||||
|
||||
const HashRateQueryAR29 = await getConnection()
|
||||
const HashRateQueryAR29 = await getConnection(Global.network)
|
||||
.query(
|
||||
'with hours as ( SELECT hour::date from generate_series(' +
|
||||
seriesquery +
|
||||
@ -1527,7 +1528,7 @@ export class BlockchainBlockController {
|
||||
.catch(err_msg => {
|
||||
next(err_msg);
|
||||
});
|
||||
const HashRateQueryAT31 = await getConnection()
|
||||
const HashRateQueryAT31 = await getConnection(Global.network)
|
||||
.query(
|
||||
'with hours as ( SELECT hour::date from generate_series(' +
|
||||
seriesquery +
|
||||
@ -1583,14 +1584,14 @@ export class BlockchainBlockController {
|
||||
letest_block_num = '',
|
||||
letest_block_duration = '';
|
||||
|
||||
const BlockchainLatestBlockQuery = await getConnection()
|
||||
const BlockchainLatestBlockQuery = await getConnection(Global.network)
|
||||
.query(
|
||||
'SELECT timestamp,height,edge_bits,hash,secondary_scaling, previous_id, total_difficulty_cuckaroo, total_difficulty_cuckatoo, total_difficulty_progpow, total_difficulty_randomx FROM blockchain_block ORDER BY timestamp DESC LIMIT 1',
|
||||
)
|
||||
.catch(err_msg => {
|
||||
next(err_msg);
|
||||
});
|
||||
const BlockchainPreviousBlockQuery = await getConnection()
|
||||
const BlockchainPreviousBlockQuery = await getConnection(Global.network)
|
||||
.query(
|
||||
'SELECT total_difficulty_cuckaroo, total_difficulty_cuckatoo, total_difficulty_progpow, total_difficulty_randomx FROM blockchain_block WHERE hash=' +
|
||||
"'" +
|
||||
@ -1825,7 +1826,7 @@ let remaining_height = 0;
|
||||
} else {
|
||||
var timeIntervalQry = "timestamp > current_date - interval '30 days'";
|
||||
}
|
||||
const BlockchainBlockPerSecondQuery = await getConnection()
|
||||
const BlockchainBlockPerSecondQuery = await getConnection(Global.network)
|
||||
.query(
|
||||
"select date(DATE_TRUNC('day', timestamp)) as date, count(hash) as blocks, 86400/count(hash) as period \
|
||||
from blockchain_block where " +
|
||||
@ -1900,7 +1901,7 @@ let remaining_height = 0;
|
||||
const BLOCK_ERA_6_ONWARDS = DAY_HEIGHT * 1460;
|
||||
/// Block Reward that will be assigned after we change from era 5 to era 6.
|
||||
const BASE_REWARD_ERA_6_ONWARDS = 0.15625;
|
||||
const BlockchainBlockPerSecondQuery = await getConnection()
|
||||
const BlockchainBlockPerSecondQuery = await getConnection(Global.network)
|
||||
.query(
|
||||
'select x.timestamp, SUM(x.reward) as total_reward_per_day \
|
||||
from (SELECT DISTINCT height, hash, CAST(timestamp AS DATE), \
|
||||
@ -2008,7 +2009,7 @@ let remaining_height = 0;
|
||||
process.env.TIME_ZONE +
|
||||
"' > current_date - interval '30 days'";
|
||||
}
|
||||
const BlockMineChartQuery = await getConnection()
|
||||
const BlockMineChartQuery = await getConnection(Global.network)
|
||||
.query(
|
||||
"SELECT hash, date , total_edge_bits, RandomX, Cuckoo, ProgPow, Round(RandomX * 100.0 / total_edge_bits,2) AS RandomXper, Round(Cuckoo * 100.0 / total_edge_bits,2) AS Cuckooper, Round(ProgPow * 100.0 / total_edge_bits,2) AS ProgPowper \
|
||||
FROM (SELECT 1 as hash, \
|
||||
@ -2043,7 +2044,7 @@ let remaining_height = 0;
|
||||
Cuckooper.push(parseFloat(e.cuckooper));
|
||||
ProgPowper.push(parseFloat(e.progpowper));
|
||||
RandomX.push(parseInt(e.randomx));
|
||||
Cuckoo.push(parseInt(e.cuckatoo));
|
||||
Cuckoo.push(parseInt(e.cuckoo));
|
||||
ProgPow.push(parseInt(e.progpow));
|
||||
});
|
||||
|
||||
|
@ -1,11 +1,13 @@
|
||||
import express from 'express';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { getRepository } from 'typeorm';
|
||||
import { getRepository,getConnection } from 'typeorm';
|
||||
import { validationMiddleware } from '../middlewares';
|
||||
import {
|
||||
InternalServerErrorException,
|
||||
NoDataFoundException,
|
||||
} from '../exceptions';
|
||||
import { Global } from "../global";
|
||||
|
||||
import { BlockchainInput } from '../entities';
|
||||
import {
|
||||
BlockchainInputCreateDto,
|
||||
@ -195,7 +197,7 @@ export class BlockchainInputController {
|
||||
) => {
|
||||
try {
|
||||
const BlockchainInputRequestData: BlockchainInputCreateDto = request.body;
|
||||
const BlockchainInputCreateQuery = await getRepository(
|
||||
const BlockchainInputCreateQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainInput,
|
||||
).save(BlockchainInputRequestData);
|
||||
response.status(200).json({
|
||||
@ -215,7 +217,7 @@ export class BlockchainInputController {
|
||||
next: NextFunction,
|
||||
) => {
|
||||
try {
|
||||
const BlockchainInputFetchQuery = await getRepository(
|
||||
const BlockchainInputFetchQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainInput,
|
||||
).findOne({
|
||||
where: { id: request.params.id },
|
||||
@ -240,7 +242,7 @@ export class BlockchainInputController {
|
||||
) => {
|
||||
try {
|
||||
const BlockchainInputRequestData: BlockchainInputUpdateDto = request.body;
|
||||
const BlockchainInputUpdateQuery = await getRepository(
|
||||
const BlockchainInputUpdateQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainInput,
|
||||
).update(BlockchainInputRequestData.Id, BlockchainInputRequestData);
|
||||
response.status(200).json({
|
||||
@ -260,7 +262,7 @@ export class BlockchainInputController {
|
||||
next: NextFunction,
|
||||
) => {
|
||||
try {
|
||||
const BlockchainInputDeleteQuery = await getRepository(
|
||||
const BlockchainInputDeleteQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainInput,
|
||||
).delete(request.params.Id);
|
||||
BlockchainInputDeleteQuery
|
||||
@ -284,7 +286,7 @@ export class BlockchainInputController {
|
||||
try {
|
||||
const BlockchainInputRequestData: BlockchainInputPaginationDto =
|
||||
request.query;
|
||||
const BlockchainInputCountQuery = await getRepository(
|
||||
const BlockchainInputCountQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainInput,
|
||||
).findAndCount({});
|
||||
if (BlockchainInputCountQuery[1]) {
|
||||
@ -294,7 +296,7 @@ export class BlockchainInputController {
|
||||
BlockchainInputRequestData.PageSize,
|
||||
BlockchainInputRequestData.MaxPages,
|
||||
);
|
||||
const BlockchainInputPaginationQuery = await getRepository(
|
||||
const BlockchainInputPaginationQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainInput,
|
||||
).find({
|
||||
skip: PaginationReponseData.startIndex,
|
||||
|
@ -2,6 +2,7 @@ import express from 'express';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { getRepository, getConnection } from 'typeorm';
|
||||
import { validationMiddleware } from '../middlewares';
|
||||
import { Global } from "../global";
|
||||
import * as path from 'path';
|
||||
import {
|
||||
InternalServerErrorException,
|
||||
@ -144,6 +145,30 @@ export class BlockchainKernelController {
|
||||
this.Translator,
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /epic_explorer/v1/network:
|
||||
* get:
|
||||
* tags:
|
||||
* - name: Network | Network CONTROLLER
|
||||
* summary: change a network
|
||||
* description: change a network
|
||||
* consumes:
|
||||
* - application/json
|
||||
* produces:
|
||||
* - application/json
|
||||
* parameters:
|
||||
* - name: network
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Network Changed successfully
|
||||
*/
|
||||
this.router.get(
|
||||
`${this.path}/network`,
|
||||
this.changeNetwok,
|
||||
);
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /epic_explorer/v1/getpeers:
|
||||
@ -356,7 +381,7 @@ export class BlockchainKernelController {
|
||||
try {
|
||||
const BlockchainKernelRequestData: BlockchainKernelCreateDto =
|
||||
request.body;
|
||||
const BlockchainKernelCreateQuery = await getRepository(
|
||||
const BlockchainKernelCreateQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainKernel,
|
||||
).save(BlockchainKernelRequestData);
|
||||
response.status(200).json({
|
||||
@ -376,7 +401,7 @@ export class BlockchainKernelController {
|
||||
next: NextFunction,
|
||||
) => {
|
||||
try {
|
||||
const BlockchainKernelFetchQuery = await getRepository(
|
||||
const BlockchainKernelFetchQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainKernel,
|
||||
).findOne({
|
||||
where: { id: request.params.id },
|
||||
@ -402,7 +427,7 @@ export class BlockchainKernelController {
|
||||
try {
|
||||
const BlockchainKernelRequestData: BlockchainKernelUpdateDto =
|
||||
request.body;
|
||||
const BlockchainKernelUpdateQuery = await getRepository(
|
||||
const BlockchainKernelUpdateQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainKernel,
|
||||
).update(BlockchainKernelRequestData.Id, BlockchainKernelRequestData);
|
||||
response.status(200).json({
|
||||
@ -422,7 +447,7 @@ export class BlockchainKernelController {
|
||||
next: NextFunction,
|
||||
) => {
|
||||
try {
|
||||
const BlockchainKernelDeleteQuery = await getRepository(
|
||||
const BlockchainKernelDeleteQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainKernel,
|
||||
).delete(request.params.Id);
|
||||
BlockchainKernelDeleteQuery
|
||||
@ -446,7 +471,7 @@ export class BlockchainKernelController {
|
||||
try {
|
||||
const BlockchainKernelRequestData: BlockchainKernelPaginationDto =
|
||||
request.query;
|
||||
const BlockchainKernelCountQuery = await getRepository(
|
||||
const BlockchainKernelCountQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainKernel,
|
||||
).findAndCount({});
|
||||
if (BlockchainKernelCountQuery[1]) {
|
||||
@ -456,7 +481,7 @@ export class BlockchainKernelController {
|
||||
BlockchainKernelRequestData.PageSize,
|
||||
BlockchainKernelRequestData.MaxPages,
|
||||
);
|
||||
const BlockchainKernelPaginationQuery = await getRepository(
|
||||
const BlockchainKernelPaginationQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainKernel,
|
||||
).find({
|
||||
skip: PaginationReponseData.startIndex,
|
||||
@ -482,7 +507,25 @@ export class BlockchainKernelController {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private changeNetwok = async (
|
||||
request: Request,
|
||||
response: Response,
|
||||
next: NextFunction,
|
||||
) => {
|
||||
try {
|
||||
Global.network = request.query.network;
|
||||
console.log(Global.network);
|
||||
//const network = request.query.network;
|
||||
response.status(200).json({
|
||||
status: 200,
|
||||
timestamp: Date.now(),
|
||||
message: 'Network Changed successfully',
|
||||
response: request.query.network,
|
||||
});
|
||||
} catch (error) {
|
||||
next(new InternalServerErrorException(error));
|
||||
}
|
||||
};
|
||||
private Translator = async (
|
||||
request: Request,
|
||||
response: Response,
|
||||
@ -582,7 +625,7 @@ export class BlockchainKernelController {
|
||||
} else {
|
||||
var timeIntervalQry = "timestamp > current_date - interval '30 days'";
|
||||
}
|
||||
const TransactionFeeQuery = await getConnection()
|
||||
const TransactionFeeQuery = await getConnection(Global.network)
|
||||
.query(
|
||||
"select 1 as hash, date(DATE_TRUNC('day', timestamp)) as date, sum(fee)/1000000 as fee \
|
||||
from blockchain_block t1 join blockchain_kernel t2 on t2.block_id=t1.hash where " +
|
||||
@ -640,7 +683,7 @@ export class BlockchainKernelController {
|
||||
// } else {
|
||||
// var timeIntervalQry = "timestamp > current_date - interval '30 days'";
|
||||
// }
|
||||
const TransactionHeatmapChartQuery = await getConnection()
|
||||
const TransactionHeatmapChartQuery = await getConnection(Global.network)
|
||||
.query(
|
||||
"with hours as ( \
|
||||
SELECT generate_series('" +
|
||||
@ -778,7 +821,7 @@ LEFT JOIN (select block_id, count(block_id) as block_id_count from blockchain_ou
|
||||
"blockchain_block.timestamp > current_date - interval '30 days'";
|
||||
var seriesquery = "now() - interval '30 days', now()";
|
||||
}
|
||||
const TransactionHeatmapChartQuery = await getConnection()
|
||||
const TransactionHeatmapChartQuery = await getConnection(Global.network)
|
||||
.query(
|
||||
'with hours as ( SELECT hour::date from generate_series(' +
|
||||
seriesquery +
|
||||
|
@ -1,7 +1,9 @@
|
||||
import express from 'express';
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { getRepository } from 'typeorm';
|
||||
import { getRepository, getConnection } from 'typeorm';
|
||||
import { validationMiddleware } from '../middlewares';
|
||||
import { Global } from "../global";
|
||||
|
||||
import {
|
||||
InternalServerErrorException,
|
||||
NoDataFoundException,
|
||||
@ -210,7 +212,7 @@ export class BlockchainOutputController {
|
||||
try {
|
||||
const BlockchainOutputRequestData: BlockchainOutputCreateDto =
|
||||
request.body;
|
||||
const BlockchainOutputCreateQuery = await getRepository(
|
||||
const BlockchainOutputCreateQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainOutput,
|
||||
).save(BlockchainOutputRequestData);
|
||||
response.status(200).json({
|
||||
@ -230,7 +232,7 @@ export class BlockchainOutputController {
|
||||
next: NextFunction,
|
||||
) => {
|
||||
try {
|
||||
const BlockchainOutputFetchQuery = await getRepository(
|
||||
const BlockchainOutputFetchQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainOutput,
|
||||
).findOne({
|
||||
where: { id: request.params.id },
|
||||
@ -256,7 +258,7 @@ export class BlockchainOutputController {
|
||||
try {
|
||||
const BlockchainOutputRequestData: BlockchainOutputUpdateDto =
|
||||
request.body;
|
||||
const BlockchainOutputUpdateQuery = await getRepository(
|
||||
const BlockchainOutputUpdateQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainOutput,
|
||||
).update(BlockchainOutputRequestData.Id, BlockchainOutputRequestData);
|
||||
response.status(200).json({
|
||||
@ -276,7 +278,7 @@ export class BlockchainOutputController {
|
||||
next: NextFunction,
|
||||
) => {
|
||||
try {
|
||||
const BlockchainOutputDeleteQuery = await getRepository(
|
||||
const BlockchainOutputDeleteQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainOutput,
|
||||
).delete(request.params.Id);
|
||||
BlockchainOutputDeleteQuery
|
||||
@ -300,7 +302,7 @@ export class BlockchainOutputController {
|
||||
try {
|
||||
const BlockchainOutputRequestData: BlockchainOutputPaginationDto =
|
||||
request.query;
|
||||
const BlockchainOutputCountQuery = await getRepository(
|
||||
const BlockchainOutputCountQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainOutput,
|
||||
).findAndCount({});
|
||||
if (BlockchainOutputCountQuery[1]) {
|
||||
@ -310,7 +312,7 @@ export class BlockchainOutputController {
|
||||
BlockchainOutputRequestData.PageSize,
|
||||
BlockchainOutputRequestData.MaxPages,
|
||||
);
|
||||
const BlockchainOutputPaginationQuery = await getRepository(
|
||||
const BlockchainOutputPaginationQuery = await getConnection(Global.network).getRepository(
|
||||
BlockchainOutput,
|
||||
).find({
|
||||
skip: PaginationReponseData.startIndex,
|
||||
|
3
server/global.ts
Normal file
3
server/global.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export namespace Global {
|
||||
export var network: string = 'Floonet';
|
||||
}
|
@ -3,12 +3,14 @@ import { validate, ValidationError } from 'class-validator';
|
||||
import * as express from 'express';
|
||||
import { NextFunction, Request, Response } from 'express';
|
||||
import { HttpException } from '../exceptions/index';
|
||||
import { Global } from "../global";
|
||||
|
||||
export function validationMiddleware<T>(
|
||||
type: any,
|
||||
skipMissingProperties = false,
|
||||
): express.RequestHandler {
|
||||
return (request: Request, response: Response, next: NextFunction) => {
|
||||
Global.network = request.headers.network;
|
||||
validate(
|
||||
plainToClass(type, {
|
||||
...request.body,
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { getConnection } from "typeorm";
|
||||
import { Global } from "../global";
|
||||
|
||||
var moment = require("moment");
|
||||
moment.updateLocale('en', {
|
||||
@ -77,9 +78,9 @@ export async function universalGetLatestBlockDetails(socket) {
|
||||
letest_block_num = "",
|
||||
letest_block_duration = "";
|
||||
|
||||
const BlockchainLatestBlockQuery = await getConnection().query(
|
||||
const BlockchainLatestBlockQuery = await getConnection(Global.network).query(
|
||||
"SELECT bb.timestamp,bb.proof,bb.height,bb.edge_bits,bb.hash,bb.secondary_scaling, bb.previous_id, bb.total_difficulty_cuckaroo, bb.total_difficulty_cuckatoo, bb.total_difficulty_progpow, bb.total_difficulty_randomx, COUNT(DISTINCT(bi.block_id)) AS input_count, COUNT(DISTINCT(bk.block_id)) AS kernel_count, COUNT(DISTINCT(bo.block_id)) AS output_count FROM blockchain_block bb LEFT JOIN blockchain_input bi ON bi.block_id = bb.hash LEFT JOIN blockchain_kernel bk ON bk.block_id = bb.hash LEFT JOIN blockchain_output bo ON bo.block_id = bb.hash group by bb.hash, bb.timestamp ORDER BY bb.timestamp DESC LIMIT 1");
|
||||
const BlockchainPreviousBlockQuery = await getConnection().query(
|
||||
const BlockchainPreviousBlockQuery = await getConnection(Global.network).query(
|
||||
"SELECT total_difficulty_cuckaroo, total_difficulty_cuckatoo, total_difficulty_progpow, total_difficulty_randomx FROM blockchain_block WHERE hash=" +
|
||||
"'" +
|
||||
BlockchainLatestBlockQuery[0].previous_id +
|
||||
|
@ -2,6 +2,7 @@
|
||||
<nav class="navbar navbar-expand navbar-light bg-transparent">
|
||||
<div class="container-fluid">
|
||||
<div class="collapse navbar-collapse home_mble_hdr" id="navbarSupportedContent">
|
||||
|
||||
|
||||
<ul class="navbar-nav ml-auto">
|
||||
<!-- <li *ngIf="TimeArr" class="d-none d-sm-inline-block"><h1 class="test_msg d-inline-block mb-0 align-middle mr-3">{{'home.HEADER_TEXT' | translate}}</h1>
|
||||
@ -17,7 +18,13 @@
|
||||
<li class="home_tst_net mr-3">
|
||||
<a href="https://epic.tech/" target="_blank" class="text_underline mr-2">Epic Cash</a>
|
||||
<span>You are viewing </span>
|
||||
<ul class="list-unstyled d-inline-block mb-0">
|
||||
<select (change)="onChangeNetwork($event.target.value)">
|
||||
<option value="Floonet" [selected]="'Floonet' == getNetwork()" >FlooNet</option>
|
||||
<option value="Testnet" [selected]="'Testnet' == getNetwork()">TestNet</option>
|
||||
<option disabled value="Mainnet">MainNet</option>
|
||||
</select>
|
||||
|
||||
<!-- <ul class="list-unstyled d-inline-block mb-0">
|
||||
<li class="nav-item dropdown">
|
||||
<a
|
||||
class="nav-link dropdown-toggle bg-white"
|
||||
@ -36,7 +43,7 @@
|
||||
>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</ul> -->
|
||||
|
||||
</li>
|
||||
<li class="nav-item px-2 dropdown bg-white">
|
||||
|
@ -2,6 +2,7 @@ import { Component, OnInit, Inject } from '@angular/core';
|
||||
import { DOCUMENT } from '@angular/common';
|
||||
import { ChartService } from '../../services/chart.service';
|
||||
import { TransServiceService } from '../../services/trans-service.service';
|
||||
import { HttpParams } from '@angular/common/http';
|
||||
|
||||
@Component({
|
||||
selector: 'epic-explorer-header',
|
||||
@ -25,6 +26,15 @@ export class HeaderComponent implements OnInit {
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
public getNetwork(){
|
||||
return localStorage.getItem('network');
|
||||
}
|
||||
|
||||
public onChangeNetwork(networkValue){
|
||||
localStorage.setItem('network', networkValue);
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
public ChangeTheme() {
|
||||
this.document.body.classList.toggle('dark_theme');
|
||||
}
|
||||
|
@ -8,7 +8,12 @@
|
||||
<a class="chart_heading d-sm-none" routerLink="/"><span class="txt_primary">Epic</span><span>Explorer</span></a>
|
||||
<div class=" d-none d-sm-inline-block mr-3">
|
||||
<span>You are viewing </span>
|
||||
<ul class="list-unstyled d-inline-block">
|
||||
<select (change)="onChangeNetwork($event.target.value)">
|
||||
<option value="Floonet" [selected]="'Floonet' == getNetwork()" >FlooNet</option>
|
||||
<option value="Testnet" [selected]="'Testnet' == getNetwork()">TestNet</option>
|
||||
<option disabled value="Mainnet">MainNet</option>
|
||||
</select>
|
||||
<!-- <ul class="list-unstyled d-inline-block">
|
||||
<li class="nav-item dropdown">
|
||||
|
||||
<a class="nav-link dropdown-toggle bg-white" href="#" id="navbarDropdown" role="button"
|
||||
@ -21,8 +26,8 @@
|
||||
<a class="dropdown-item p-2 disabled" href="#">MainNet</a>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<span> Network </span>
|
||||
</ul> -->
|
||||
<!-- <span> Network </span> -->
|
||||
</div>
|
||||
<div class="position-relative d-none d-sm-inline-block">
|
||||
<input type="text" [(ngModel)]="search" #ctrl="ngModel" class="form-control search_input"
|
||||
@ -61,7 +66,12 @@
|
||||
</div>
|
||||
<div class="d-block d-sm-none text-center mt-3 mx-auto">
|
||||
<span>You are viewing </span>
|
||||
<ul class="list-unstyled d-inline-block">
|
||||
<select (change)="onChangeNetwork($event.target.value)">
|
||||
<option value="Floonet" [selected]="'Floonet' == getNetwork()" >FlooNet</option>
|
||||
<option value="Testnet" [selected]="'Testnet' == getNetwork()">TestNet</option>
|
||||
<option disabled value="Mainnet">MainNet</option>
|
||||
</select>
|
||||
<!-- <ul class="list-unstyled d-inline-block">
|
||||
<li class="nav-item dropdown">
|
||||
|
||||
<a class="nav-link dropdown-toggle bg-white" href="#" id="navbarDropdown" role="button"
|
||||
@ -74,8 +84,8 @@
|
||||
<a class="dropdown-item p-2 disabled" href="#">MainNet</a>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
<span> Network </span>
|
||||
</ul> -->
|
||||
<!-- <span> Network </span> -->
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
@ -23,6 +23,16 @@ export class SiteheaderComponent implements OnInit {
|
||||
this.document.body.classList.toggle('dark_theme');
|
||||
}
|
||||
|
||||
public getNetwork(){
|
||||
return localStorage.getItem('network');
|
||||
}
|
||||
|
||||
public onChangeNetwork(networkValue){
|
||||
localStorage.setItem('network', networkValue);
|
||||
window.location.reload();
|
||||
|
||||
}
|
||||
|
||||
onSearch(hash) {
|
||||
this.router.navigate(['blockdetail', hash]);
|
||||
}
|
||||
|
@ -31,7 +31,8 @@ export class ChartService {
|
||||
public apiGetRequest(request: any, reqUrl): Observable<any> {
|
||||
return this.http
|
||||
.get(`${environment.apiUrl}` + reqUrl, {
|
||||
params: request
|
||||
params: request,
|
||||
headers: this.getHttpheader()
|
||||
})
|
||||
.pipe(
|
||||
map(res => {
|
||||
@ -41,6 +42,17 @@ export class ChartService {
|
||||
);
|
||||
}
|
||||
|
||||
public getHttpheader(){
|
||||
var network;
|
||||
if(localStorage.getItem('network') == null){
|
||||
network = "Floonet"
|
||||
}else{
|
||||
network = localStorage.getItem('network')
|
||||
}
|
||||
return new HttpHeaders().set('network', network);
|
||||
}
|
||||
|
||||
|
||||
public getLatestblockdetails() {
|
||||
return Observable.create(observer => {
|
||||
this.socket.on("latestblockdetail", response => {
|
||||
|
Loading…
Reference in New Issue
Block a user