diff --git a/server/controllers/BlockchainBlock.ts b/server/controllers/BlockchainBlock.ts index be74a4c..77c23ce 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) { @@ -758,7 +758,9 @@ export class BlockchainBlockController { /// 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 <= BLOCK_ERA_1) { + 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; @@ -1867,23 +1869,34 @@ let remaining_height = 0; } 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 \ + 'select x.timestamp, x.height, SUM(x.reward) as total_reward_per_day \ from (SELECT hash, height, 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', ) @@ -1891,6 +1904,28 @@ let remaining_height = 0; 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/src/app/view/home/latestblocks/latestblocks.component.html b/src/app/view/home/latestblocks/latestblocks.component.html index a2b3c10..251b1be 100644 --- a/src/app/view/home/latestblocks/latestblocks.component.html +++ b/src/app/view/home/latestblocks/latestblocks.component.html @@ -163,9 +163,11 @@