Skip to content
Snippets Groups Projects
Commit 2124e42e authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[fix] monetaryMass field had `0` value

parent f88de909
No related branches found
No related tags found
No related merge requests found
...@@ -227,7 +227,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain { ...@@ -227,7 +227,7 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
} }
const dbb = DBBlock.fromBlockDTO(block) const dbb = DBBlock.fromBlockDTO(block)
await this.updateBlocksComputedVars(current, dbb); this.updateBlocksComputedVars(current, dbb)
// Saves the block (DAL) // Saves the block (DAL)
await dal.saveBlock(dbb); await dal.saveBlock(dbb);
...@@ -461,13 +461,17 @@ export class DuniterBlockchain extends MiscIndexedBlockchain { ...@@ -461,13 +461,17 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
} }
} }
updateBlocksComputedVars(current:DBBlock, block:DBBlock): Promise<void> { updateBlocksComputedVars(
current:{ unitbase:number, monetaryMass:number }|null,
block:{ number:number, unitbase:number, dividend:number|null, membersCount:number, monetaryMass:number }): void {
// Unit Base // Unit Base
block.unitbase = (block.dividend && block.unitbase) || (current && current.unitbase) || 0; block.unitbase = (block.dividend && block.unitbase) || (current && current.unitbase) || 0;
// Monetary Mass update // Monetary Mass update
if (current) { if (current) {
block.monetaryMass = (current.monetaryMass || 0) block.monetaryMass = (current.monetaryMass || 0)
+ (block.dividend || 0) * Math.pow(10, block.unitbase || 0) * block.membersCount; + (block.dividend || 0) * Math.pow(10, block.unitbase || 0) * block.membersCount;
} else {
block.monetaryMass = 0
} }
// UD Time update // UD Time update
if (block.number == 0) { if (block.number == 0) {
...@@ -476,7 +480,6 @@ export class DuniterBlockchain extends MiscIndexedBlockchain { ...@@ -476,7 +480,6 @@ export class DuniterBlockchain extends MiscIndexedBlockchain {
else if (!block.dividend) { else if (!block.dividend) {
block.dividend = null; block.dividend = null;
} }
return Promise.resolve()
} }
static pushStatsForBlocks(blocks:BlockDTO[], dal:any) { static pushStatsForBlocks(blocks:BlockDTO[], dal:any) {
......
...@@ -61,6 +61,8 @@ export class QuickSynchronizer { ...@@ -61,6 +61,8 @@ export class QuickSynchronizer {
} }
for (const block of blocks) { for (const block of blocks) {
block.fork = false; block.fork = false;
const current:BlockDTO|null = await getBlock(block.number - 1)
this.blockchain.updateBlocksComputedVars(current, block)
} }
// Transactions recording // Transactions recording
await this.updateTransactionsForBlocks(blocks, getBlockByNumberAndHash); await this.updateTransactionsForBlocks(blocks, getBlockByNumberAndHash);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment