diff --git a/server.ts b/server.ts index 70d2a4a..ef6f543 100644 --- a/server.ts +++ b/server.ts @@ -32,7 +32,7 @@ import { Request, Response, NextFunction } from "express"; import bodyParser from "body-parser"; //import { logger } from "./server/utils"; import swaggerJSDoc from "swagger-jsdoc"; -import { errorMiddleware } from "./server/middlewares"; +import { errorMiddleware, redisMiddleware } from "./server/middlewares"; import { getRepository, In, @@ -121,7 +121,7 @@ controllers.forEach(controller => { // Example Express Rest API endpoints import request from 'request-promise'; -app.get("/api", async (req, res) => { +app.get("/api", redisMiddleware('60'), async (req, res) => { try { let option = req.query.q; let blockDetails = await latestBlockDetails(); @@ -129,7 +129,9 @@ try { { let result; //500 if(option == "circulating") - result= blockDetails.coin_existence; + result= blockDetails.coin_existence * 100000000; + else if(option == "reward") + result= blockDetails.currentReward * 100000000; else if(option == "getblockcount") result= blockDetails.block_height; else if(option == "getdifficulty-randomx") @@ -139,7 +141,7 @@ try { else if(option == "getdifficulty-progpow") result = Number(blockDetails.TotalDifficultyProgpow); else if(option == "totalcoins") - result = 21000000; + result = 21000000 * 100000000; else if(option == "getblockhash") { let height = req.query.height; @@ -235,7 +237,7 @@ try { else { //let result= 5; - //window.redirect('/'); + res.redirect('/api-index'); } } @@ -318,9 +320,8 @@ console.log(__dirname); console.log(`Node Express server listening on http://localhost:${PORT}`); }); - cron.schedule('* * * * * *', () => { + cron.schedule('*/30 * * * * *', () => { universalGetLatestBlockDetails('Testnet'); - universalGetLatestBlockDetails('Floonet'); }); var interval; const io = require("socket.io").listen(server); diff --git a/server/controllers/BlockchainBlock.ts b/server/controllers/BlockchainBlock.ts index 1b7f4ec..57aae6e 100644 --- a/server/controllers/BlockchainBlock.ts +++ b/server/controllers/BlockchainBlock.ts @@ -63,7 +63,7 @@ export class BlockchainBlockController { if (fee == 0) { return this.epic(0); } else if (fee < 1000) { - return (fee * 1000000) / 1000000000; + return fee / 1000000; } else { return this.milliEpic(parseFloat(fee) / 1000); } @@ -73,7 +73,7 @@ export class BlockchainBlockController { if (fee == 0) { return this.epic(0); } else if (fee < 1000) { - return (fee * 1000) / 1000000000; + return fee / 1000; } else { return this.epic(parseFloat(fee) / 1000); } @@ -1012,6 +1012,7 @@ export class BlockchainBlockController { // MaxPages, PageSize, }: BlockchainBlockPaginationDto = request.query; + if (parseInt(CurrentPage) == NaN) { next(new IntegerValidationException('CurrentPage')); } else if (parseInt(PageSize) == NaN) { @@ -1053,6 +1054,7 @@ export class BlockchainBlockController { 'blockchain_block.TotalDifficultyProgpow', 'blockchain_block.TotalDifficultyRandomx', 'blockchain_block.previous_id', + 'EXTRACT(EPOCH FROM (blockchain_block.timestamp - LAG(blockchain_block.timestamp) OVER (ORDER BY blockchain_block.timestamp))) as timetaken', 'blockchain_block.total_difficulty_cuckaroo - LAG(blockchain_block.total_difficulty_cuckaroo) OVER (ORDER BY blockchain_block.total_difficulty_cuckaroo) AS target_difficulty_cuckaroo', 'blockchain_block.total_difficulty_cuckatoo - LAG(blockchain_block.total_difficulty_cuckatoo) OVER (ORDER BY blockchain_block.total_difficulty_cuckatoo) AS target_difficulty_cuckatoo', 'blockchain_block.total_difficulty_progpow - LAG(blockchain_block.total_difficulty_progpow) OVER (ORDER BY blockchain_block.total_difficulty_progpow) AS target_difficulty_progpow', @@ -1075,14 +1077,14 @@ export class BlockchainBlockController { .leftJoin('blockchain_block.BlockchainKernels', 'blockchain_kernel') .leftJoin('blockchain_block.BlockchainOutputs', 'blockchain_output') .skip(PaginationReponseData.startIndex) - .take(PaginationReponseData.pageSize) + .take(PaginationReponseData.pageSize+1) .orderBy('blockchain_block.Timestamp', 'DESC') .groupBy('blockchain_block.Hash') .getRawAndEntities(); - //console.log(BlockchainBlockPaginationQuery.raw); let BlockchainBlockResult = BlockchainBlockPaginationQuery.raw; + BlockchainBlockResult.splice(-1,1); let lastElemt = BlockchainBlockResult[BlockchainBlockResult.length - 1]; const BlockchainPreviousBlockFetchQuery = await getConnection(Global.network).getRepository( @@ -1201,7 +1203,7 @@ export class BlockchainBlockController { var timeIntervalQry = "timestamp at time zone '" + process.env.TIME_ZONE + - "' > current_date - interval '1 day'"; + "' > current_date - interval '1 week'"; } const BlockQuery = await getConnection(Global.network) .query( diff --git a/server/global.ts b/server/global.ts index a1014f2..d148ebf 100644 --- a/server/global.ts +++ b/server/global.ts @@ -1,7 +1,7 @@ import * as redis from 'redis'; var REDIS_URL = process.env.REDIS_URL; export namespace Global { - export var network: string = 'Floonet'; + export var network: string = 'Testnet'; // connect to Redis export var client = redis.createClient(REDIS_URL); -} \ No newline at end of file +} diff --git a/server/i18n/de.json b/server/i18n/de.json index 581a87f..cc9bc2c 100644 --- a/server/i18n/de.json +++ b/server/i18n/de.json @@ -14,6 +14,7 @@ "avg-block-interval" : "Durchschnittliches Sperrintervall", "home": { "HEADER_TEXT": "Sie befinden sich in Beta", + "TIMETAKEN": "Genomen tijd (sec)", "COUNTDOWN": "Mainnet-Countdown", "EXPLORE_IT": "Entdecke", "VIEWALL": "Alle Diagramme anzeigen", @@ -83,5 +84,35 @@ "ADDR" : "Adr", "DIRECTION" : "Richtung", "SPENT" : "Verbraucht" + }, + "api-view": { + "query-api" : "Abfrage-API", + "query-api-line1" : "Die aufzurufende API-Funktion wird über den Parameter q angegeben.", + "query-api-line2" : "Zum Beispiel können Sie die Gesamtmünzen des epischen Bargeldes mit fragen ", + "circulating" : "Gibt die Anzahl der umlaufenden Münzen zurück", + "getblockcount":"Gibt die aktuelle Blockhöhe als reine Textzeichenfolge zurück", + "getdifficulty-randomx" : "Gibt die RandomX-Schwierigkeit als reine Textzeichenfolge zurück", + "getdifficulty-progpow" : "Gibt die Schwierigkeit ProgPow als reine Textzeichenfolge zurück", + "getdifficulty-cuckoo" : "returns the Cuckoo difficulty as a plain text string", + "totalcoins" : "Gibt die Cuckoo-Schwierigkeit als reine Textzeichenfolge zurück", + "Block-Queries": "Abfragen blockieren", + "real-time-simple-query" : "Einfache Echtzeitabfragen", + "block-query-text" : "Block-APIs berücksichtigen nur Blöcke in der 'Haupt'-Kette (wie in der Explorer-Brieftasche festgelegt).", + "getblockhash" : "Nimmt einen Höhenparameter und gibt den entsprechenden Block-Hash zurück", + "getblockheight" : "Nimmt einen Hash-Parameter und gibt die entsprechende Blockhöhe zurück.", + "getblocktime" : "Nimmt einen Höhenparameter und gibt die unixtime des Blocks zurück.", + "takes":"nimmt ein", + "Note" : "Hinweis", + "reward" : "Gibt die aktuelle Blockbelohnung zurück" + }, + "commit-id-view": { + "output-commit":"Output Commit", + "created-at-block":"Erstellt am Block", + "created-at":"Hergestellt in", + "output-type" : "Ausgabetyp", + "proof" : "Beweis", + "proof-hash" : "Beweis-Hash", + "merkle-proof" : "Merkle Beweis", + "mmr-index" : "MMR Index" } } diff --git a/server/i18n/en.json b/server/i18n/en.json index c5c53b6..8e13f88 100644 --- a/server/i18n/en.json +++ b/server/i18n/en.json @@ -1,6 +1,6 @@ { "difficulty" : "Difficulty", - "transactions-over-time" : "Transactions over time", + "transactions-over-time" : "Transactions over Time", "blocks-by-algorithm" : "Blocks by Algorithm", "blocks" : "Blocks", "transaction-fees" : "Average Transaction Fee", @@ -15,6 +15,7 @@ "home": { "HEADER_TEXT": "You are on Beta", "COUNTDOWN": "Mainnet Countdown", + "TIMETAKEN": "Time Taken (sec)", "EXPLORE_IT": "Explore", "VIEWALL": "View All Charts", "BLOCKCHAIN_HEIGHT": "Blockchain Height", @@ -42,7 +43,7 @@ "MINUTE" : "minute", "TOTAL_DIFFICULTY" : "Total Difficulty", "TARGET_DIFFICULTY" : "Target Difficulty", - "TRANSACTIONS_BY_TIME" : "Transactions over time", + "TRANSACTIONS_BY_TIME" : "Transactions over Time", "BLOCKS" : "Blocks", "BLOCKSINTERVAL" : "Block Interval", "SUPPLY_GROWTH_HOVER" : "Current Block Reward", @@ -61,7 +62,7 @@ "DAYS" : "days", "MONTHS" : "months", "WEEK" : "week", - "SEARCH_TEXT" : "Search by hash, or block height or output commit id", + "SEARCH_TEXT" : "Search by hash, or block height or output commit ID", "BLOCK_REWARD" : "Block Reward", "NOT_FOUND" : "Page Not Found", "NOT_FOUND1" : "Page you are looking for is not found", @@ -83,5 +84,35 @@ "ADDR" : "Addr", "DIRECTION" : "Direction", "SPENT" : "Spent" + }, + "api-view": { + "query-api" : "Query API", + "query-api-line1" : "The API function to call is specified through the q parameter.", + "query-api-line2" : "For instance you can ask the totalcoins of epic cash with ", + "circulating" : "returns the number of circulating coins", + "getblockcount":"returns the current block height as a plain text string", + "getdifficulty-randomx" : "returns the RandomX difficulty as a plain text string", + "getdifficulty-progpow" : "returns the ProgPow difficulty as a plain text string", + "getdifficulty-cuckoo" : "returns the Cuckoo difficulty as a plain text string", + "totalcoins" : "returns the outstanding number of coins", + "Block-Queries": "Block Queries", + "real-time-simple-query" : "Real-Time Simple Queries", + "block-query-text" : "Block APIs only consider blocks in the 'main' chain (as determined by the explorer wallet).", + "getblockhash" : " parameter and returns corresponding block hash.", + "getblockheight" : " parameter and returns corresponding block height.", + "getblocktime" : " parameter and returns unixtime of the block.", + "takes" : "takes a", + "Note" : "Note", + "reward" : "returns current block reward" + }, + "commit-id-view": { + "output-commit":"Output Commit", + "created-at-block":"Created at block", + "created-at":"Created At", + "output-type" : "Output Type", + "proof" : "Proof", + "proof-hash" : "Proof hash", + "merkle-proof" : "Merkle Proof", + "mmr-index" : "MMR Index" } } diff --git a/server/socket/block.ts b/server/socket/block.ts index 5e7f31a..dc808a9 100644 --- a/server/socket/block.ts +++ b/server/socket/block.ts @@ -316,6 +316,7 @@ export async function universalGetLatestBlockDetails(current_network) { 'blockchain_block.TotalDifficultyProgpow', 'blockchain_block.TotalDifficultyRandomx', 'blockchain_block.previous_id', + 'EXTRACT(EPOCH FROM (blockchain_block.timestamp - LAG(blockchain_block.timestamp) OVER (ORDER BY blockchain_block.timestamp))) as timetaken', 'blockchain_block.total_difficulty_cuckaroo - LAG(blockchain_block.total_difficulty_cuckaroo) OVER (ORDER BY blockchain_block.total_difficulty_cuckaroo) AS target_difficulty_cuckaroo', 'blockchain_block.total_difficulty_cuckatoo - LAG(blockchain_block.total_difficulty_cuckatoo) OVER (ORDER BY blockchain_block.total_difficulty_cuckatoo) AS target_difficulty_cuckatoo', 'blockchain_block.total_difficulty_progpow - LAG(blockchain_block.total_difficulty_progpow) OVER (ORDER BY blockchain_block.total_difficulty_progpow) AS target_difficulty_progpow', diff --git a/server/utils/common.ts b/server/utils/common.ts index 7120389..16cd5e4 100644 --- a/server/utils/common.ts +++ b/server/utils/common.ts @@ -324,13 +324,23 @@ async function Details (height) { async function GetBlocktime(height){ if(height){ + // const BlockchainLatestBlockQuery3 = await getConnection(Global.network) + // .query( + // "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 => { + // return(err_msg); + // }); + const BlockchainLatestBlockQuery3 = await getConnection(Global.network) .query( - "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", + "SELECT extract(epoch from timestamp at time zone '" +process.env.TIME_ZONE+ "') AS alter FROM blockchain_block where height="+height, ) .catch(err_msg => { return(err_msg); }); + + return BlockchainLatestBlockQuery3; } } diff --git a/src/app/shared/components/footer/footer.component.html b/src/app/shared/components/footer/footer.component.html index aee28de..da2cf45 100644 --- a/src/app/shared/components/footer/footer.component.html +++ b/src/app/shared/components/footer/footer.component.html @@ -27,7 +27,7 @@
- API + API