diff --git a/server.ts b/server.ts index d81001b..ca28fe8 100644 --- a/server.ts +++ b/server.ts @@ -141,7 +141,7 @@ try { else if(option == "getdifficulty-progpow") result = Number(blockDetails.TotalDifficultyProgpow); else if(option == "totalcoins") - result = 21000000 * 100000000; + result = blockDetails.coin_existence; else if(option == "maxcoins") result = 21000000; else if(option == "average-blocktime") @@ -342,9 +342,9 @@ console.log(__dirname); console.log(`Node Express server listening on http://localhost:${PORT}`); }); - cron.schedule('*/30 * * * * *', () => { - universalGetLatestBlockDetails('Testnet'); - }); + // cron.schedule('*/30 * * * * *', () => { + // universalGetLatestBlockDetails('Testnet'); + // }); var interval; const io = require("socket.io").listen(server); io.sockets.on("connection", socket => { @@ -356,7 +356,7 @@ console.log(__dirname); let key = process.env.REDIS_KEY + socket.handshake.query.network + 'Latest_Block_details' interval = setInterval(function() { Global.client.get(key, function(err, reply){ - socket.emit("latestblockdetail", JSON.parse(reply) ); + // socket.emit("latestblockdetail", JSON.parse(reply) ); }); },10000); //socket.on("disconnect", () => console.log("Client disconnected")); diff --git a/server/i18n/de.json b/server/i18n/de.json index af6bbe7..0874658 100644 --- a/server/i18n/de.json +++ b/server/i18n/de.json @@ -89,6 +89,7 @@ }, "api-view": { "query-api" : "Abfrage-API", + "maxcoins" : "Maximale Versorgung zurückgeben", "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", diff --git a/server/i18n/en.json b/server/i18n/en.json index dfa5b37..551a43f 100644 --- a/server/i18n/en.json +++ b/server/i18n/en.json @@ -89,6 +89,7 @@ }, "api-view": { "query-api" : "Query API", + "maxcoins" : "Return maximum supply", "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", diff --git a/server/utils/common.ts b/server/utils/common.ts index e9fc561..3a04213 100644 --- a/server/utils/common.ts +++ b/server/utils/common.ts @@ -49,6 +49,178 @@ function dateDiff(date2, insec = false) { // } } +/** + * Function returns total coins based on height + */ + +const getTotalRewardByHeight= async(height) => { + + var coin_existence; + + let DAY_HEIGHT = 1440 + /// Height of the first epic block emission era + const BLOCK_ERA_1 = DAY_HEIGHT * 334; + /// Height of the second epic block emission era + const BLOCK_ERA_2 = BLOCK_ERA_1 + (DAY_HEIGHT * 470); + /// Height of the third epic block emission era + const BLOCK_ERA_3 = BLOCK_ERA_2 + (DAY_HEIGHT * 601); + /// Height of the fourth epic block emission era + const BLOCK_ERA_4 = BLOCK_ERA_3 + (DAY_HEIGHT * 800); + /// Height of the fifth epic block emission era + const BLOCK_ERA_5 = BLOCK_ERA_4 + (DAY_HEIGHT * 1019); + /// After the epic block emission era 6, each era will last 4 years (approximately 1460 days) + 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; + + let remaining_height = 0; + let currentReward = 16; + /// Compute the total reward generated by each block in a given height. + if (height <= BLOCK_ERA_1) { + coin_existence = height * 16; + currentReward = 16; + } else if (height <= BLOCK_ERA_2) { + remaining_height = height - BLOCK_ERA_1; + coin_existence = (16 * BLOCK_ERA_1) + 8 * remaining_height; + currentReward = 8; + } else if (height <= BLOCK_ERA_3) { + remaining_height = height - BLOCK_ERA_2; + coin_existence = (16 * BLOCK_ERA_1) + (8 * BLOCK_ERA_2) + 4 * remaining_height; + currentReward = 4; + } else if (height <= BLOCK_ERA_4) { + remaining_height = height - BLOCK_ERA_3; + coin_existence = (16 * BLOCK_ERA_1) + (8 * BLOCK_ERA_2) + (4 * BLOCK_ERA_3) + 2 * remaining_height; + currentReward = 2; + } else if (height <= BLOCK_ERA_5) { + remaining_height = height - BLOCK_ERA_4; + coin_existence = (16 * BLOCK_ERA_1) + (8 * BLOCK_ERA_2) + (4 * BLOCK_ERA_3) + (2 * BLOCK_ERA_4) +1 * remaining_height; + currentReward = 1; + } else { + // After the era 6, we reduce the block rewards by half each 1460 days. + // Minus 1 to include multiples in the same index + // (i.e changes greater than to greater or equals to) + + let preious_circulation = (16 * BLOCK_ERA_1) + (8 * BLOCK_ERA_2) + (4 * BLOCK_ERA_3) + (2 * BLOCK_ERA_4) + (1 * BLOCK_ERA_5); + + let height_with_offset = height - (BLOCK_ERA_5 - 1); + let exp = height_with_offset / BLOCK_ERA_6_ONWARDS; + let reward_emission = BASE_REWARD_ERA_6_ONWARDS / (1 << exp); + coin_existence = preious_circulation + reward_emission ; + currentReward = reward_emission; + } + + return coin_existence; +} + +// function returns foundation reward + +const circulationsupply = async(height) => { + let first_duration = 1440 * 120; + let year_height = 365 * 1440; + let foundationpercentage = [8.8,7.7,6.6,5.5,4.4,3.3,2.2,1.1] + let circulatingsuppy = 0 + if(height < first_duration) { + let coin = await getTotalRewardByHeight(height) + circulatingsuppy = (coin / 100) * foundationpercentage[0] + } + else if(height < (first_duration + year_height) ) { + let firstyear = await getTotalRewardByHeight(first_duration) + let firstyearcoin = (firstyear / 100) * foundationpercentage[0] + let secondyear = await getTotalRewardByHeight(height) + let secondyearcoin = ( (secondyear -firstyear) / 100) * foundationpercentage[1] + circulatingsuppy = firstyearcoin + secondyearcoin + } + else if(height < (first_duration + (2 * year_height)) ) { + let firstyear = await getTotalRewardByHeight(first_duration) + let firstyearcoin = (firstyear / 100) * foundationpercentage[0] + let secondyear = await getTotalRewardByHeight(first_duration + year_height) + let secondyearcoin = ( (secondyear -firstyear) / 100) * foundationpercentage[1] + let thirdyear = await getTotalRewardByHeight(height) + let thirdyearcoin = ( (thirdyear -secondyear) / 100) * foundationpercentage[2] + circulatingsuppy = firstyearcoin + secondyearcoin + thirdyearcoin +} +else if(height < (first_duration + (3 * year_height)) ) { + let firstyear = await getTotalRewardByHeight(first_duration) + let firstyearcoin = (firstyear / 100) * foundationpercentage[0] + let secondyear = await getTotalRewardByHeight(first_duration + year_height) + let secondyearcoin = ( (secondyear -firstyear) / 100) * foundationpercentage[1] + let thirdyear = await getTotalRewardByHeight(first_duration + (2 * year_height)) + let thirdyearcoin = ( (thirdyear -secondyear) / 100) * foundationpercentage[2] + let forthyear = await getTotalRewardByHeight(height) + let forthyearcoin = ( (forthyear -thirdyear) / 100) * foundationpercentage[3] + circulatingsuppy = firstyearcoin + secondyearcoin + thirdyearcoin + forthyearcoin +} +else if(height < (first_duration + (4 * year_height)) ) { + let firstyear = await getTotalRewardByHeight(first_duration) + let firstyearcoin = (firstyear / 100) * foundationpercentage[0] + let secondyear = await getTotalRewardByHeight(first_duration + year_height) + let secondyearcoin = ( (secondyear -firstyear) / 100) * foundationpercentage[1] + let thirdyear = await getTotalRewardByHeight(first_duration + (2 * year_height)) + let thirdyearcoin = ( (thirdyear -secondyear) / 100) * foundationpercentage[2] + let forthyear = await getTotalRewardByHeight(first_duration + (3 * year_height)) + let forthyearcoin = ( (forthyear -thirdyear) / 100) * foundationpercentage[3] + let fifthyear = await getTotalRewardByHeight(height) + let fifthyearcoin = ( (fifthyear - forthyear) / 100) * foundationpercentage[4] + circulatingsuppy = firstyearcoin + secondyearcoin + thirdyearcoin + forthyearcoin+fifthyearcoin +} +else if(height < (first_duration + (5 * year_height)) ) { + let firstyear = await getTotalRewardByHeight(first_duration) + let firstyearcoin = (firstyear / 100) * foundationpercentage[0] + let secondyear = await getTotalRewardByHeight(first_duration + year_height) + let secondyearcoin = ( (secondyear -firstyear) / 100) * foundationpercentage[1] + let thirdyear = await getTotalRewardByHeight(first_duration + (2 * year_height)) + let thirdyearcoin = ( (thirdyear -secondyear) / 100) * foundationpercentage[2] + let forthyear = await getTotalRewardByHeight(first_duration + (3 * year_height)) + let forthyearcoin = ( (forthyear -thirdyear) / 100) * foundationpercentage[3] + let fifthyear = await getTotalRewardByHeight(first_duration + (4 * year_height)) + let fifthyearcoin = ( (fifthyear - forthyear) / 100) * foundationpercentage[4] + let sixthyear = await getTotalRewardByHeight(height) + let sixthyearcoin = ( (sixthyear - fifthyear) / 100) * foundationpercentage[5] + circulatingsuppy = firstyearcoin + secondyearcoin + thirdyearcoin + forthyearcoin+fifthyearcoin+sixthyearcoin +} + +else if(height < (first_duration + (6 * year_height)) ) { + let firstyear = await getTotalRewardByHeight(first_duration) + let firstyearcoin = (firstyear / 100) * foundationpercentage[0] + let secondyear = await getTotalRewardByHeight(first_duration + year_height) + let secondyearcoin = ( (secondyear -firstyear) / 100) * foundationpercentage[1] + let thirdyear = await getTotalRewardByHeight(first_duration + (2 * year_height)) + let thirdyearcoin = ( (thirdyear -secondyear) / 100) * foundationpercentage[2] + let forthyear = await getTotalRewardByHeight(first_duration + (3 * year_height)) + let forthyearcoin = ( (forthyear -thirdyear) / 100) * foundationpercentage[3] + let fifthyear = await getTotalRewardByHeight(first_duration + (4 * year_height)) + let fifthyearcoin = ( (fifthyear - forthyear) / 100) * foundationpercentage[4] + let sixthyear = await getTotalRewardByHeight(first_duration + (5 * year_height)) + let sixthyearcoin = ( (sixthyear - fifthyear) / 100) * foundationpercentage[5] + let seventhyear = await getTotalRewardByHeight(height) + let seventhyearcoin = ( (seventhyear - sixthyear) / 100) * foundationpercentage[6] + circulatingsuppy = firstyearcoin + secondyearcoin + thirdyearcoin + forthyearcoin+fifthyearcoin+sixthyearcoin+seventhyearcoin +} + +else if(height < (first_duration + (7 * year_height)) ) { + let firstyear = await getTotalRewardByHeight(first_duration) + let firstyearcoin = (firstyear / 100) * foundationpercentage[0] + let secondyear = await getTotalRewardByHeight(first_duration + year_height) + let secondyearcoin = ( (secondyear -firstyear) / 100) * foundationpercentage[1] + let thirdyear = await getTotalRewardByHeight(first_duration + (2 * year_height)) + let thirdyearcoin = ( (thirdyear -secondyear) / 100) * foundationpercentage[2] + let forthyear = await getTotalRewardByHeight(first_duration + (3 * year_height)) + let forthyearcoin = ( (forthyear -thirdyear) / 100) * foundationpercentage[3] + let fifthyear = await getTotalRewardByHeight(first_duration + (4 * year_height)) + let fifthyearcoin = ( (fifthyear - forthyear) / 100) * foundationpercentage[4] + let sixthyear = await getTotalRewardByHeight(first_duration + (5 * year_height)) + let sixthyearcoin = ( (sixthyear - fifthyear) / 100) * foundationpercentage[5] + let seventhyear = await getTotalRewardByHeight(first_duration + (6 * year_height)) + let seventhyearcoin = ( (seventhyear - sixthyear) / 100) * foundationpercentage[6] + let eigthyear = await getTotalRewardByHeight(height) + let eigthyearcoin = ( (eigthyear - seventhyear) / 100) * foundationpercentage[7] + circulatingsuppy = firstyearcoin + secondyearcoin + thirdyearcoin + forthyearcoin+fifthyearcoin+sixthyearcoin+seventhyearcoin + eigthyearcoin +} + return circulatingsuppy +} + + + const latestBlockDetails = async()=> { let block_height = '', @@ -290,6 +462,12 @@ let currentReward = 16; cuckoohashrate = Math.round(cuckoohashrate) progpowhashrate = Math.round(progpowhashrate) randomxhashrate = Math.round(randomxhashrate) + + // Total foundation reward + let totalFoundationReward = await circulationsupply(height) + console.log("------------------------------------------------------------------"); + console.log("Current foundation reward is ", totalFoundationReward) + return { block_height, letest_block, @@ -311,7 +489,8 @@ let currentReward = 16; userReward, cuckoohashrate, progpowhashrate, - randomxhashrate + randomxhashrate, + totalFoundationReward }; } diff --git a/src/app/view/api-view/api-view.component.html b/src/app/view/api-view/api-view.component.html index e72eac6..4ad7a30 100644 --- a/src/app/view/api-view/api-view.component.html +++ b/src/app/view/api-view/api-view.component.html @@ -14,6 +14,7 @@