From 4655f765971864d2c7035c32e2f35c0f4c72b809 Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Thu, 10 Aug 2017 16:43:33 +0200
Subject: [PATCH] =?UTF-8?q?[fix]=20Be=20able=20to=20switch=20from=20=C4=9E?=
 =?UTF-8?q?1=20to=20=C4=9E1-Test=20network?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 app/modules/crawler/lib/sync.ts | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/app/modules/crawler/lib/sync.ts b/app/modules/crawler/lib/sync.ts
index 25e889952..8fe575f42 100644
--- a/app/modules/crawler/lib/sync.ts
+++ b/app/modules/crawler/lib/sync.ts
@@ -188,7 +188,7 @@ export class Synchroniser extends stream.Duplex {
       // We use cautious mode if it is asked, or not particulary asked but blockchain has been started
       const cautious = (askedCautious === true || localNumber >= 0);
       const shuffledPeers = noShufflePeers ? peers : _.shuffle(peers);
-      const downloader = new P2PDownloader(localNumber, to, rCurrent.hash, shuffledPeers, this.watcher, this.logger, hashf, this.dal, this.slowOption);
+      const downloader = new P2PDownloader(rCurrent.currency, localNumber, to, rCurrent.hash, shuffledPeers, this.watcher, this.logger, hashf, this.dal, this.slowOption);
 
       downloader.start();
 
@@ -611,6 +611,7 @@ class P2PDownloader {
   private downloadStarter:Promise<any>
 
   constructor(
+    private currency:string,
     private localNumber:number,
     private to:number,
     private toHash:string,
@@ -870,7 +871,7 @@ class P2PDownloader {
       count = this.nbBlocksToDownload % CONST_BLOCKS_CHUNK || CONST_BLOCKS_CHUNK;
     }
     try {
-      const fileName = "blockchain/chunk_" + index + "-" + CONST_BLOCKS_CHUNK + ".json";
+      const fileName = this.currency + "/chunk_" + index + "-" + CONST_BLOCKS_CHUNK + ".json";
       if (this.localNumber <= 0 && (await this.dal.confDAL.coreFS.exists(fileName))) {
         this.handler[index] = {
           host: 'filesystem',
@@ -882,7 +883,7 @@ class P2PDownloader {
         const chunk:any = await this.p2pDownload(from, count, index);
         // Store the file to avoid re-downloading
         if (this.localNumber <= 0 && chunk.length === CONST_BLOCKS_CHUNK) {
-          await this.dal.confDAL.coreFS.makeTree('blockchain');
+          await this.dal.confDAL.coreFS.makeTree(this.currency);
           await this.dal.confDAL.coreFS.writeJSON(fileName, { blocks: chunk });
         }
         return chunk;
-- 
GitLab