diff --git a/server.ts b/server.ts index 4c8cff4..4010b60 100644 --- a/server.ts +++ b/server.ts @@ -149,9 +149,9 @@ connection }); const io = require("socket.io").listen(server); io.sockets.on("connection", socket => { - setInterval(function() { - universalGetLatestBlockDetails(socket); - },1000); + // setInterval(function() { + // //universalGetLatestBlockDetails(socket); + // },1000); }); }) .catch(error => { diff --git a/server/controllers/BlockchainBlock.ts b/server/controllers/BlockchainBlock.ts index f0bb6ce..cbdd5ca 100644 --- a/server/controllers/BlockchainBlock.ts +++ b/server/controllers/BlockchainBlock.ts @@ -707,7 +707,7 @@ export class BlockchainBlockController { 'SecondaryScaling', 'Proof', ], - where: { Height: paramVal }, + where: { Height: paramVal }, }); } if (!BlockchainBlockFetchQuery) { @@ -741,27 +741,64 @@ export class BlockchainBlockController { // } BlockchainBlockFetchQuery['TotalCuckoo']=parseInt(BlockchainBlockFetchQuery.TotalDifficultyCuckaroo) + parseInt(BlockchainBlockFetchQuery.TotalDifficultyCuckatoo); - if (BlockchainBlockFetchQuery.Height <= 1440) { - BlockchainBlockFetchQuery['BlockReward'] = 200; - } else if (BlockchainBlockFetchQuery.Height <= 2880) { - BlockchainBlockFetchQuery['BlockReward'] = 180; - } else if (BlockchainBlockFetchQuery.Height <= 4320) { - BlockchainBlockFetchQuery['BlockReward'] = 160; - } else if (BlockchainBlockFetchQuery.Height <= 5760) { - BlockchainBlockFetchQuery['BlockReward'] = 140; - } else if (BlockchainBlockFetchQuery.Height <= 7200) { - BlockchainBlockFetchQuery['BlockReward'] = 120; - } else if (BlockchainBlockFetchQuery.Height <= 8640) { - BlockchainBlockFetchQuery['BlockReward'] = 100; - } else if (BlockchainBlockFetchQuery.Height <= 10080) { - BlockchainBlockFetchQuery['BlockReward'] = 80; - } else if (BlockchainBlockFetchQuery.Height <= 11520) { - BlockchainBlockFetchQuery['BlockReward'] = 60; - } else if (BlockchainBlockFetchQuery.Height <= 12960) { - BlockchainBlockFetchQuery['BlockReward'] = 50; - } else { - BlockchainBlockFetchQuery['BlockReward'] = 25; - } + 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; + /// Compute the total reward generated by each block in a given height. + if(BlockchainBlockFetchQuery.Height == 0) { + BlockchainBlockFetchQuery['BlockReward'] = 0; + }else if (BlockchainBlockFetchQuery.Height <= BLOCK_ERA_1) { + BlockchainBlockFetchQuery['BlockReward'] = 16; + } else if (BlockchainBlockFetchQuery.Height <= BLOCK_ERA_2) { + BlockchainBlockFetchQuery['BlockReward'] = 8; + } else if (BlockchainBlockFetchQuery.Height <= BLOCK_ERA_3) { + BlockchainBlockFetchQuery['BlockReward'] = 4; + } else if (BlockchainBlockFetchQuery.Height <= BLOCK_ERA_4) { + BlockchainBlockFetchQuery['BlockReward'] = 2; + } else if (BlockchainBlockFetchQuery.Height <= BLOCK_ERA_5) { + BlockchainBlockFetchQuery['BlockReward'] = 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 height_with_offset = BlockchainBlockFetchQuery.Height - (BLOCK_ERA_5 - 1); + let exp = height_with_offset / BLOCK_ERA_6_ONWARDS; + BlockchainBlockFetchQuery['BlockReward'] = BASE_REWARD_ERA_6_ONWARDS / (1 << exp); + } + // if (BlockchainBlockFetchQuery.Height <= 1440) { + // BlockchainBlockFetchQuery['BlockReward'] = 200; + // } else if (BlockchainBlockFetchQuery.Height <= 2880) { + // BlockchainBlockFetchQuery['BlockReward'] = 180; + // } else if (BlockchainBlockFetchQuery.Height <= 4320) { + // BlockchainBlockFetchQuery['BlockReward'] = 160; + // } else if (BlockchainBlockFetchQuery.Height <= 5760) { + // BlockchainBlockFetchQuery['BlockReward'] = 140; + // } else if (BlockchainBlockFetchQuery.Height <= 7200) { + // BlockchainBlockFetchQuery['BlockReward'] = 120; + // } else if (BlockchainBlockFetchQuery.Height <= 8640) { + // BlockchainBlockFetchQuery['BlockReward'] = 100; + // } else if (BlockchainBlockFetchQuery.Height <= 10080) { + // BlockchainBlockFetchQuery['BlockReward'] = 80; + // } else if (BlockchainBlockFetchQuery.Height <= 11520) { + // BlockchainBlockFetchQuery['BlockReward'] = 60; + // } else if (BlockchainBlockFetchQuery.Height <= 12960) { + // BlockchainBlockFetchQuery['BlockReward'] = 50; + // } else { + // BlockchainBlockFetchQuery['BlockReward'] = 25; + // } if (BlockchainBlockFetchQuery.PreviousId) { const BlockchainPreviousBlockFetchQuery = await getRepository( @@ -828,7 +865,7 @@ export class BlockchainBlockController { console.log('error', error); next(new InternalServerErrorException(error)); } - + }; private BlockchainBlockUpdate = async ( @@ -1167,30 +1204,18 @@ export class BlockchainBlockController { var dateFormat = 'YYYY-MM-DD HH:mm:ss'; var tickFormat = '%H-%M'; } - if(Difftype == "target"){ - var TotalDifficultyNBlockQuery = await getConnection() - .query( - "SELECT a.hash, a.tarket_difficulty, a.date FROM(select 1 as hash, (total_difficulty_"+alog_type+" - LAG(total_difficulty_"+alog_type+") OVER (ORDER BY total_difficulty_"+alog_type+")) AS tarket_difficulty, \ - DATE_TRUNC('minute', timestamp at time zone '" + - process.env.TIME_ZONE + - "') as date \ - from blockchain_block where " + - timeIntervalQry + - " order by height) as a WHERE a.tarket_difficulty IS NOT NULL", - ) - .catch(err_msg => { - next(err_msg); - }); - }else if(Difftype == "solution"){ + if(Difftype == "target"){ var TotalDifficultyNBlockQuery = await getConnection() .query( - "SELECT a.hash, a.tarket_difficulty, a.date FROM(select 1 as hash, (total_difficulty_"+alog_type+" - LAG(total_difficulty_"+alog_type+") OVER (ORDER BY total_difficulty_"+alog_type+")) AS tarket_difficulty, \ + "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 , \ + (total_difficulty_randomx - LAG(total_difficulty_randomx) OVER (ORDER BY total_difficulty_randomx)) AS total_difficulty_randomx, \ DATE_TRUNC('minute', timestamp at time zone '" + process.env.TIME_ZONE + "') as date \ from blockchain_block where " + timeIntervalQry + - " order by height) as a WHERE a.tarket_difficulty IS NOT NULL", + " order by height) as a WHERE a.total_difficulty_randomx IS NOT NULL AND a.total_difficulty_progpow IS NOT NULL AND a.total_difficulty_cuckatoo IS NOT NULL AND a.total_difficulty_cuckatoo != '0' AND a.total_difficulty_randomx != '0' AND a.total_difficulty_progpow != '0'", ) .catch(err_msg => { next(err_msg); @@ -1198,7 +1223,7 @@ export class BlockchainBlockController { }else if(Difftype == "total"){ var TotalDifficultyNBlockQuery = await getConnection() .query( - "select 1 as hash, total_difficulty_"+alog_type+" as tarket_difficulty, \ + "select 1 as hash, total_difficulty_cuckatoo,total_difficulty_progpow,total_difficulty_randomx, \ DATE_TRUNC('minute', timestamp at time zone '" + process.env.TIME_ZONE + "') as date \ @@ -1209,45 +1234,71 @@ export class BlockchainBlockController { .catch(err_msg => { next(err_msg); }); - }else{ - var TotalDifficultyNBlockQuery = await getConnection() - .query( - "SELECT a.hash, a.tarket_difficulty, a.date FROM(select 1 as hash, (total_difficulty_"+alog_type+" - LAG(total_difficulty_"+alog_type+") OVER (ORDER BY total_difficulty_"+alog_type+")) AS tarket_difficulty, \ - DATE_TRUNC('minute', timestamp at time zone '" + - process.env.TIME_ZONE + - "') as date \ - from blockchain_block where " + - timeIntervalQry + - " order by height) as a WHERE a.tarket_difficulty IS NOT NULL", - ) - .catch(err_msg => { - next(err_msg); - }); } - let date = [], - //DifficultyCuckaroo = [], - //DifficultyCuckatoo = [], - //DifficultyProgpow = [], - //DifficultyRandomx = []; + // let date = [], + // DifficultyCuckatoo = [], + // DifficultyProgpow = [], + // DifficultyRandomx = []; - TargetDifficulty = []; - - TotalDifficultyNBlockQuery.forEach(e => { - //date.indexOf(moment(e.date).format('YYYY-MM-DD')) < 0 ? - date.push(moment(e.date).format(dateFormat)); - // DifficultyCuckaroo.push(parseInt(e.total_difficulty_cuckaroo)); - // DifficultyCuckatoo.push(parseInt(e.total_difficulty_cuckatoo)); - // DifficultyProgpow.push(parseInt(e.total_difficulty_progpow)); - // DifficultyRandomx.push(parseInt(e.total_difficulty_randomx)); - TargetDifficulty.push(parseInt(e.tarket_difficulty)); + var DifficultyCuckatoo = TotalDifficultyNBlockQuery.map(function (e) { + return parseInt(e.total_difficulty_cuckatoo); }); - var Maxrange = Math.max.apply(Math, TotalDifficultyNBlockQuery.map(function(o) { return o.tarket_difficulty; })); - var Minrange = Math.min.apply(Math, TotalDifficultyNBlockQuery.map(function(o) { return o.tarket_difficulty; })); - if(Minrange != 0){ - Minrange = (Minrange - (Minrange * 0.2)); - } - Maxrange = (Maxrange + (Maxrange * 0.2)); + var DifficultyProgpow = TotalDifficultyNBlockQuery.map(function (e) { + return parseInt(e.total_difficulty_progpow); + }); + + var DifficultyRandomx = TotalDifficultyNBlockQuery.map(function (e) { + return parseInt(e.total_difficulty_randomx); + }); + + var date = TotalDifficultyNBlockQuery.map(function (e) { + return moment(e.date).format(dateFormat); + }); + + // TotalDifficultyNBlockQuery.forEach(e => { + // date.push(moment(e.date).format(dateFormat)); + // DifficultyCuckatoo.push(parseInt(e.total_difficulty_cuckatoo)); + // DifficultyProgpow.push(parseInt(e.total_difficulty_progpow)); + // DifficultyRandomx.push(parseInt(e.total_difficulty_randomx)); + // }); + // var Maxrange; + // var Minrange; + // if(alog_type == "cuckatoo"){ + // Maxrange = Math.max.apply(Math, DifficultyCuckatoo); + // Minrange = Math.min.apply(Math, DifficultyCuckatoo); + // if(Minrange != 0){ + // Minrange = (Minrange - (Minrange * 0.2)); + // } + // Maxrange = (Maxrange + (Maxrange * 0.2)); + // }else if(alog_type == "progpow"){ + // Maxrange = Math.max.apply(Math, DifficultyProgpow); + // Minrange = Math.min.apply(Math, DifficultyProgpow); + // if(Minrange != 0){ + // Minrange = (Minrange - (Minrange * 0.2)); + // } + // Maxrange = (Maxrange + (Maxrange * 0.2)); + // }else if(alog_type == "randomx"){ + // Maxrange = Math.max.apply(Math, DifficultyRandomx); + // Minrange = Math.min.apply(Math, DifficultyRandomx); + // if(Minrange != 0){ + // Minrange = (Minrange - (Minrange * 0.2)); + // } + // Maxrange = (Maxrange + (Maxrange * 0.2)); + // }else{ + // var Maxrange1 = Math.max.apply(Math, TotalDifficultyNBlockQuery.map(function(o) { return o.total_difficulty_cuckatoo; })); + // var Minrange1 = Math.min.apply(Math, TotalDifficultyNBlockQuery.map(function(o) { return o.total_difficulty_cuckatoo; })); + // var Maxrange2 = Math.max.apply(Math, TotalDifficultyNBlockQuery.map(function(o) { return o.total_difficulty_progpow; })); + // var Minrange2 = Math.min.apply(Math, TotalDifficultyNBlockQuery.map(function(o) { return o.total_difficulty_progpow; })); + // var Maxrange3 = Math.max.apply(Math, TotalDifficultyNBlockQuery.map(function(o) { return o.total_difficulty_randomx; })); + // var Minrange3 = Math.min.apply(Math, TotalDifficultyNBlockQuery.map(function(o) { return o.total_difficulty_randomx; })); + // Maxrange = Math.max(Maxrange1, Maxrange2, Maxrange3); + // Minrange = Math.min(Minrange1, Minrange2, Minrange3); + // if(Minrange != 0){ + // Minrange = (Minrange - (Minrange * 0.2)); + // } + // Maxrange = (Maxrange + (Maxrange * 0.2)); + // } // Minrange = parseInt(Minrange); // var Minrange2 = parseInt(Minrange * 0.3); @@ -1257,12 +1308,11 @@ export class BlockchainBlockController { message: 'Difficulty and Blocks Data fetched Successfully', response: { Date: date, - // DifficultyCuckaroo: DifficultyCuckaroo, - // DifficultyCuckatoo: DifficultyCuckatoo, - // DifficultyProgpow: DifficultyProgpow, - Maxrange: Maxrange, - Minrange: Minrange, - TargetDifficulty: TargetDifficulty, + DifficultyCuckatoo: DifficultyCuckatoo, + DifficultyRandomx: DifficultyRandomx, + DifficultyProgpow: DifficultyProgpow, + //Maxrange: Maxrange, + //Minrange: Minrange, tickFormat: tickFormat }, }); @@ -1552,83 +1602,128 @@ export class BlockchainBlockController { }); let height = BlockchainLatestBlockQuery[0].height; + var coin_existence; + // if (height > 12960) { + // var remain_block = height - 12960; + // var coin_existence = + // 1440 * 200 + + // 1440 * 180 + + // 1440 * 160 + + // 1440 * 140 + + // 1440 * 120 + + // 1440 * 100 + + // 1440 * 80 + + // 1440 * 60 + + // 1440 * 50 + + // 25 * remain_block; + // } else if (height > 11520) { + // var remain_block = height - 11520; + // var coin_existence = + // 1440 * 200 + + // 1440 * 180 + + // 1440 * 160 + + // 1440 * 140 + + // 1440 * 120 + + // 1440 * 100 + + // 1440 * 80 + + // 1440 * 60 + + // remain_block * 50; + // } else if (height > 10080) { + // var remain_block = height - 10080; + // var coin_existence = + // 1440 * 200 + + // 1440 * 180 + + // 1440 * 160 + + // 1440 * 140 + + // 1440 * 120 + + // 1440 * 100 + + // 1440 * 80 + + // remain_block * 60; + // } else if (height > 8640) { + // var remain_block = height - 8640; + // var coin_existence = + // 1440 * 200 + + // 1440 * 180 + + // 1440 * 160 + + // 1440 * 140 + + // 1440 * 120 + + // 1440 * 100 + + // remain_block * 80; + // } else if (height > 7200) { + // var remain_block = height - 7200; + // var coin_existence = + // 1440 * 200 + + // 1440 * 180 + + // 1440 * 160 + + // 1440 * 140 + + // 1440 * 120 + + // remain_block * 100; + // } else if (height > 5760) { + // var remain_block = height - 5760; + // var coin_existence = + // 1440 * 200 + + // 1440 * 180 + + // 1440 * 160 + + // 1440 * 140 + + // remain_block * 120; + // } else if (height > 4320) { + // var remain_block = height - 4320; + // var coin_existence = + // 1440 * 200 + 1440 * 180 + 1440 * 160 + remain_block * 140; + // } else if (height > 2880) { + // var remain_block = height - 2880; + // var coin_existence = 1440 * 200 + 1440 * 180 + remain_block * 160; + // } else if (height > 1440) { + // var remain_block = height - 1440; + // var coin_existence = 1440 * 200 + remain_block * 180; + // } else { + // var coin_existence = height * 200; + // } + + 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; - if (height > 12960) { - var remain_block = height - 12960; - var coin_existence = - 1440 * 200 + - 1440 * 180 + - 1440 * 160 + - 1440 * 140 + - 1440 * 120 + - 1440 * 100 + - 1440 * 80 + - 1440 * 60 + - 1440 * 50 + - 25 * remain_block; - } else if (height > 11520) { - var remain_block = height - 11520; - var coin_existence = - 1440 * 200 + - 1440 * 180 + - 1440 * 160 + - 1440 * 140 + - 1440 * 120 + - 1440 * 100 + - 1440 * 80 + - 1440 * 60 + - remain_block * 50; - } else if (height > 10080) { - var remain_block = height - 10080; - var coin_existence = - 1440 * 200 + - 1440 * 180 + - 1440 * 160 + - 1440 * 140 + - 1440 * 120 + - 1440 * 100 + - 1440 * 80 + - remain_block * 60; - } else if (height > 8640) { - var remain_block = height - 8640; - var coin_existence = - 1440 * 200 + - 1440 * 180 + - 1440 * 160 + - 1440 * 140 + - 1440 * 120 + - 1440 * 100 + - remain_block * 80; - } else if (height > 7200) { - var remain_block = height - 7200; - var coin_existence = - 1440 * 200 + - 1440 * 180 + - 1440 * 160 + - 1440 * 140 + - 1440 * 120 + - remain_block * 100; - } else if (height > 5760) { - var remain_block = height - 5760; - var coin_existence = - 1440 * 200 + - 1440 * 180 + - 1440 * 160 + - 1440 * 140 + - remain_block * 120; - } else if (height > 4320) { - var remain_block = height - 4320; - var coin_existence = - 1440 * 200 + 1440 * 180 + 1440 * 160 + remain_block * 140; - } else if (height > 2880) { - var remain_block = height - 2880; - var coin_existence = 1440 * 200 + 1440 * 180 + remain_block * 160; - } else if (height > 1440) { - var remain_block = height - 1440; - var coin_existence = 1440 * 200 + remain_block * 180; - } else { - var coin_existence = height * 200; - } +let remaining_height = 0; +/// Compute the total reward generated by each block in a given height. + if (height <= BLOCK_ERA_1) { + coin_existence = height * 16; + } else if (height <= BLOCK_ERA_2) { + remaining_height = height - BLOCK_ERA_1; + coin_existence = (16 * BLOCK_ERA_1) + 8 * remaining_height; + } 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; + } 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; + } 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; + } 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 ; + } letest_block = this.dateDiff(BlockchainLatestBlockQuery[0].timestamp,true); letest_block_num = letest_block; // "72" @@ -1790,23 +1885,34 @@ export class BlockchainBlockController { } else { var timeIntervalQry = "timestamp > current_date - interval '30 days'"; } + 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; const BlockchainBlockPerSecondQuery = await getConnection() .query( 'select x.timestamp, SUM(x.reward) as total_reward_per_day \ - from (SELECT hash, height, CAST(timestamp AS DATE), \ + from (SELECT DISTINCT height, hash, CAST(timestamp AS DATE), \ CASE \ - WHEN height <= 1440 THEN 200 \ - WHEN height <= 2880 THEN 180 \ - WHEN height <= 4320 THEN 160 \ - WHEN height <= 5760 THEN 140 \ - WHEN height <= 7200 THEN 120 \ - WHEN height <= 8640 THEN 100 \ - WHEN height <= 10080 THEN 80 \ - WHEN height <= 11520 THEN 60 \ - WHEN height <= 12960 THEN 50 \ - ELSE 25 \ + WHEN height <= '+BLOCK_ERA_1+' THEN 16 \ + WHEN height <= '+BLOCK_ERA_2+' THEN 8 \ + WHEN height <= '+BLOCK_ERA_3+' THEN 4 \ + WHEN height <= '+BLOCK_ERA_4+' THEN 2 \ + WHEN height <= '+BLOCK_ERA_5+' THEN 1 \ + ELSE '+BASE_REWARD_ERA_6_ONWARDS+' / (1 << ((height - ('+BLOCK_ERA_5+'- 1))/'+BLOCK_ERA_6_ONWARDS+'))\ END AS reward \ - FROM blockchain_block where ' + + FROM blockchain_block where height > 0 AND ' + timeIntervalQry + ') as x group by x.timestamp Order by x.timestamp ASC', ) @@ -1814,6 +1920,28 @@ export class BlockchainBlockController { next(err_msg); }); + + + /// Compute the total reward generated by each block in a given height. + // if (BlockchainBlockFetchQuery.Height <= BLOCK_ERA_1) { + // BlockchainBlockFetchQuery['BlockReward'] = 16; + // } else if (BlockchainBlockFetchQuery.Height <= BLOCK_ERA_2) { + // BlockchainBlockFetchQuery['BlockReward'] = 8; + // } else if (BlockchainBlockFetchQuery.Height <= BLOCK_ERA_3) { + // BlockchainBlockFetchQuery['BlockReward'] = 4; + // } else if (BlockchainBlockFetchQuery.Height <= BLOCK_ERA_4) { + // BlockchainBlockFetchQuery['BlockReward'] = 2; + // } else if (BlockchainBlockFetchQuery.Height <= BLOCK_ERA_5) { + // BlockchainBlockFetchQuery['BlockReward'] = 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 height_with_offset = BlockchainBlockFetchQuery.Height - (BLOCK_ERA_5 - 1); + // let exp = height_with_offset / BLOCK_ERA_6_ONWARDS; + // BlockchainBlockFetchQuery['BlockReward'] = BASE_REWARD_ERA_6_ONWARDS / (1 << exp); + // } + let date = [], total_reward_per_day = [], addedreward = [], diff --git a/server/controllers/BlockchainKernel.ts b/server/controllers/BlockchainKernel.ts index 71cfcc0..3c80927 100644 --- a/server/controllers/BlockchainKernel.ts +++ b/server/controllers/BlockchainKernel.ts @@ -516,7 +516,7 @@ export class BlockchainKernelController { ) => { var self = this; try { - http.get('http://116.203.152.58:3413/v1/peers/connected', + http.get('http://116.203.152.58:13413/v1/peers/connected', async (resp) => { // console.log('resp resp respresp',resp); let data = ''; diff --git a/server/i18n/de.json b/server/i18n/de.json index d63a9c1..606ebf5 100644 --- a/server/i18n/de.json +++ b/server/i18n/de.json @@ -17,6 +17,7 @@ "EXPLORE_IT": "Entdecke", "VIEWALL": "Alle Diagramme anzeigen", "BLOCKCHAIN_HEIGHT": "Blockchain Höhe", + "LATEST_BLOCKS" : "Letzter Blocks", "LATEST_BLOCK": "Letzter Block", "LATEST_BLOCK1": "Aktuelle Zielschwierigkeit", "LATEST_BLOCK2": "Aktuelle Gesamtschwierigkeit", diff --git a/server/i18n/en.json b/server/i18n/en.json index 4685ce7..4d71e11 100644 --- a/server/i18n/en.json +++ b/server/i18n/en.json @@ -17,6 +17,7 @@ "EXPLORE_IT": "Explore", "VIEWALL": "View All Charts", "BLOCKCHAIN_HEIGHT": "Blockchain Height", + "LATEST_BLOCKS" : "Latest Blocks", "LATEST_BLOCK": "Latest Block", "LATEST_BLOCK1": "Current Target Difficulty", "LATEST_BLOCK2": "Current Total Difficulty", diff --git a/server/socket/block.ts b/server/socket/block.ts index f542d2e..efb9da2 100644 --- a/server/socket/block.ts +++ b/server/socket/block.ts @@ -3,20 +3,20 @@ import { getConnection } from "typeorm"; var moment = require("moment"); moment.updateLocale('en', { relativeTime: { - future: "in %s", - past: "%s ago", - s: "seconds", - m: "1 minute", - mm: "%d minutes", - h: "1 hour", - hh: "%d hours", - d: "1 day", - dd: "%d days", - M: "1 month", - MM: "%d months", - y: "1 year", - yy: "%d years" - } + future: "in %s", + past: "%s ago", + s: "seconds", + m: "1 minute", + mm: "%d minutes", + h: "1 hour", + hh: "%d hours", + d: "1 day", + dd: "%d days", + M: "1 month", + MM: "%d months", + y: "1 year", + yy: "%d years" + } }); function dateDiff(date2, insec = false) { @@ -29,7 +29,7 @@ function dateDiff(date2, insec = false) { var enddayrnd = Math.round(enddaydif); // if(enddayrnd < 1) { var time = convertMinsToHrmin( - Math.abs(date2.getTime() - current_date.getTime()),insec + Math.abs(date2.getTime() - current_date.getTime()), insec ); return time; // } else if(enddayrnd == 1) { @@ -40,9 +40,9 @@ function dateDiff(date2, insec = false) { } -function convertMinsToHrmin(millseconds,insec) { +function convertMinsToHrmin(millseconds, insec) { var seconds = Math.floor(millseconds / 1000); - if(insec){ + if (insec) { let sec = Math.floor(millseconds / 1000); return sec; } @@ -81,84 +81,129 @@ export async function universalGetLatestBlockDetails(socket) { "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( "SELECT total_difficulty_cuckaroo, total_difficulty_cuckatoo, total_difficulty_progpow, total_difficulty_randomx FROM blockchain_block WHERE hash=" + - "'" + - BlockchainLatestBlockQuery[0].previous_id + - "'" + "'" + + BlockchainLatestBlockQuery[0].previous_id + + "'" ); let height = BlockchainLatestBlockQuery[0].height; - if (height > 12960) { - var remain_block = height - 12960; - var coin_existence = - 1440 * 200 + - 1440 * 180 + - 1440 * 160 + - 1440 * 140 + - 1440 * 120 + - 1440 * 100 + - 1440 * 80 + - 1440 * 60 + - 1440 * 50 + - 25 * remain_block; - } else if (height > 11520) { - var remain_block = height - 11520; - var coin_existence = - 1440 * 200 + - 1440 * 180 + - 1440 * 160 + - 1440 * 140 + - 1440 * 120 + - 1440 * 100 + - 1440 * 80 + - 1440 * 60 + - remain_block * 50; - } else if (height > 10080) { - var remain_block = height - 10080; - var coin_existence = - 1440 * 200 + - 1440 * 180 + - 1440 * 160 + - 1440 * 140 + - 1440 * 120 + - 1440 * 100 + - 1440 * 80 + - remain_block * 60; - } else if (height > 8640) { - var remain_block = height - 8640; - var coin_existence = - 1440 * 200 + - 1440 * 180 + - 1440 * 160 + - 1440 * 140 + - 1440 * 120 + - 1440 * 100 + - remain_block * 80; - } else if (height > 7200) { - var remain_block = height - 7200; - var coin_existence = - 1440 * 200 + - 1440 * 180 + - 1440 * 160 + - 1440 * 140 + - 1440 * 120 + - remain_block * 100; - } else if (height > 5760) { - var remain_block = height - 5760; - var coin_existence = - 1440 * 200 + 1440 * 180 + 1440 * 160 + 1440 * 140 + remain_block * 120; - } else if (height > 4320) { - var remain_block = height - 4320; - var coin_existence = - 1440 * 200 + 1440 * 180 + 1440 * 160 + remain_block * 140; - } else if (height > 2880) { - var remain_block = height - 2880; - var coin_existence = 1440 * 200 + 1440 * 180 + remain_block * 160; - } else if (height > 1440) { - var remain_block = height - 1440; - var coin_existence = 1440 * 200 + remain_block * 180; - } else { - var coin_existence = height * 200; - } + // if (height > 12960) { + // var remain_block = height - 12960; + // var coin_existence = + // 1440 * 200 + + // 1440 * 180 + + // 1440 * 160 + + // 1440 * 140 + + // 1440 * 120 + + // 1440 * 100 + + // 1440 * 80 + + // 1440 * 60 + + // 1440 * 50 + + // 25 * remain_block; + // } else if (height > 11520) { + // var remain_block = height - 11520; + // var coin_existence = + // 1440 * 200 + + // 1440 * 180 + + // 1440 * 160 + + // 1440 * 140 + + // 1440 * 120 + + // 1440 * 100 + + // 1440 * 80 + + // 1440 * 60 + + // remain_block * 50; + // } else if (height > 10080) { + // var remain_block = height - 10080; + // var coin_existence = + // 1440 * 200 + + // 1440 * 180 + + // 1440 * 160 + + // 1440 * 140 + + // 1440 * 120 + + // 1440 * 100 + + // 1440 * 80 + + // remain_block * 60; + // } else if (height > 8640) { + // var remain_block = height - 8640; + // var coin_existence = + // 1440 * 200 + + // 1440 * 180 + + // 1440 * 160 + + // 1440 * 140 + + // 1440 * 120 + + // 1440 * 100 + + // remain_block * 80; + // } else if (height > 7200) { + // var remain_block = height - 7200; + // var coin_existence = + // 1440 * 200 + + // 1440 * 180 + + // 1440 * 160 + + // 1440 * 140 + + // 1440 * 120 + + // remain_block * 100; + // } else if (height > 5760) { + // var remain_block = height - 5760; + // var coin_existence = + // 1440 * 200 + 1440 * 180 + 1440 * 160 + 1440 * 140 + remain_block * 120; + // } else if (height > 4320) { + // var remain_block = height - 4320; + // var coin_existence = + // 1440 * 200 + 1440 * 180 + 1440 * 160 + remain_block * 140; + // } else if (height > 2880) { + // var remain_block = height - 2880; + // var coin_existence = 1440 * 200 + 1440 * 180 + remain_block * 160; + // } else if (height > 1440) { + // var remain_block = height - 1440; + // var coin_existence = 1440 * 200 + remain_block * 180; + // } else { + // var coin_existence = height * 200; + // } + 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; + /// Compute the total reward generated by each block in a given height. + if (height <= BLOCK_ERA_1) { + coin_existence = height * 16; + } else if (height <= BLOCK_ERA_2) { + remaining_height = height - BLOCK_ERA_1; + coin_existence = (16 * BLOCK_ERA_1) + 8 * remaining_height; + } 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; + } 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; + } 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; + } 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 ; + } letest_block = dateDiff(BlockchainLatestBlockQuery[0].timestamp, true); letest_block_num = letest_block // "72" @@ -200,11 +245,11 @@ export async function universalGetLatestBlockDetails(socket) { BlockchainPreviousBlockQuery[0].total_difficulty_randomx; } - if(BlockchainLatestBlockQuery[0].proof == "RandomX"){ - var Difficulty = targetdifficultyrandomx; - }else if(BlockchainLatestBlockQuery[0].proof == "ProgPow"){ + if (BlockchainLatestBlockQuery[0].proof == "RandomX") { + var Difficulty = targetdifficultyrandomx; + } else if (BlockchainLatestBlockQuery[0].proof == "ProgPow") { var Difficulty = targetdifficultyprogpow; - }else if(BlockchainLatestBlockQuery[0].proof == "Cuckoo" ){ + } else if (BlockchainLatestBlockQuery[0].proof == "Cuckoo") { var Difficulty = targetdifficultycuckatoo; } @@ -214,9 +259,9 @@ export async function universalGetLatestBlockDetails(socket) { var TotalCuckoo = parseInt(BlockchainLatestBlockQuery[0].total_difficulty_cuckatoo) + parseInt(BlockchainLatestBlockQuery[0].total_difficulty_cuckaroo); - let balance = BlockchainLatestBlockQuery[0].hash.substring(2, 62); - let arr = balance.match(/.{1,6}/g); - var hasharray = arr.map(i => '#' + i); + let balance = BlockchainLatestBlockQuery[0].hash.substring(2, 62); + let arr = balance.match(/.{1,6}/g); + var hasharray = arr.map(i => '#' + i); socket.emit("latestblockdetail", { block_height, @@ -230,7 +275,7 @@ export async function universalGetLatestBlockDetails(socket) { targetdifficultyprogpow, targetdifficultyrandomx, TotalCuckoo, - age : dateTimeDurationString, + age: dateTimeDurationString, input_count: BlockchainLatestBlockQuery[0].input_count, kernel_count: BlockchainLatestBlockQuery[0].kernel_count, output_count: BlockchainLatestBlockQuery[0].output_count, @@ -238,8 +283,8 @@ export async function universalGetLatestBlockDetails(socket) { proof: BlockchainLatestBlockQuery[0].proof, hasharray: hasharray, Difficulty: Difficulty, - hashstart:BlockchainLatestBlockQuery[0].hash.slice(0, 2), - hashend:BlockchainLatestBlockQuery[0].hash.slice(62,64), + hashstart: BlockchainLatestBlockQuery[0].hash.slice(0, 2), + hashend: BlockchainLatestBlockQuery[0].hash.slice(62, 64), TotalDifficultyCuckaroo: BlockchainLatestBlockQuery[0].total_difficulty_cuckaroo, TotalDifficultyCuckatoo: diff --git a/src/app/shared/components/header/header.component.html b/src/app/shared/components/header/header.component.html index 26886be..320f938 100755 --- a/src/app/shared/components/header/header.component.html +++ b/src/app/shared/components/header/header.component.html @@ -44,19 +44,20 @@