From d1e772511ade34a034e1e3859b53de9f2c7e87dc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Moreau?= <cem.moreau@gmail.com>
Date: Sat, 14 Apr 2018 10:30:25 +0200
Subject: [PATCH] [fix] Refactoring: `sync` was broken

---
 app/lib/computation/QuickSync.ts | 2 +-
 app/lib/indexer.ts               | 7 ++-----
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/app/lib/computation/QuickSync.ts b/app/lib/computation/QuickSync.ts
index fcc3f1600..556f2f0c1 100644
--- a/app/lib/computation/QuickSync.ts
+++ b/app/lib/computation/QuickSync.ts
@@ -77,7 +77,7 @@ export class QuickSynchronizer {
     }
     for (const block of blocks) {
       block.fork = false;
-      const current:BlockDTO|null = await getBlock(block.number - 1)
+      const current:BlockDTO|null = block.number > 0 ? await getBlock(block.number - 1) : null
       this.blockchain.updateBlocksComputedVars(current, block)
     }
     // Transactions recording
diff --git a/app/lib/indexer.ts b/app/lib/indexer.ts
index 90a626bf1..793f2d96a 100644
--- a/app/lib/indexer.ts
+++ b/app/lib/indexer.ts
@@ -26,6 +26,7 @@ import {UnlockMetadata} from "./common-libs/txunlock"
 import {FileDAL} from "./dal/fileDAL"
 import {DBWallet} from "./dal/sqliteDAL/WalletDAL"
 import {DataErrors} from "./common-libs/errors"
+import {DBBlock} from "./db/DBBlock"
 
 const _               = require('underscore');
 
@@ -1805,11 +1806,7 @@ export class Indexer {
       if (HEAD.number == 0) {
         basedBlock = HEAD;
       } else {
-        if (HEAD.currency === 'gtest') {
-          basedBlock = await dal.getBlockWeHaveItForSure(CERT.created_on);
-        } else {
-          basedBlock = await dal.getBlockWeHaveItForSure(CERT.created_on);
-        }
+        basedBlock = (await dal.getBlock(CERT.created_on)) as DBBlock;
       }
       CERT.expires_on += basedBlock.medianTime;
     }
-- 
GitLab