From 9dad9f679b1e903a81bce47b252087208356f00b Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Sat, 14 Jul 2018 17:06:45 +0200
Subject: [PATCH] [enh] refactoring: remove unused code

---
 app/lib/computation/QuickSync.ts              | 48 -------------
 app/lib/dal/fileDAL.ts                        |  8 ---
 app/lib/dal/indexDAL/abstract/TxsDAO.ts       |  2 -
 app/lib/dal/indexDAL/loki/LokiTransactions.ts |  5 --
 app/lib/db/DBTransaction.ts                   | 72 -------------------
 5 files changed, 135 deletions(-)
 delete mode 100644 app/lib/db/DBTransaction.ts

diff --git a/app/lib/computation/QuickSync.ts b/app/lib/computation/QuickSync.ts
index 0db4bffca..0e9c79ff3 100644
--- a/app/lib/computation/QuickSync.ts
+++ b/app/lib/computation/QuickSync.ts
@@ -13,12 +13,10 @@
 
 import {DuniterBlockchain} from "../blockchain/DuniterBlockchain";
 import {BlockDTO} from "../dto/BlockDTO";
-import {DBTransaction} from "../db/DBTransaction";
 import {AccountsGarbagingDAL, FullSindexEntry, Indexer} from "../indexer";
 import {CurrencyConfDTO} from "../dto/ConfDTO";
 import {FileDAL} from "../dal/fileDAL"
 import {DBBlock} from "../db/DBBlock"
-import {DBTx} from "../db/DBTx"
 import {Underscore} from "../common-libs/underscore"
 import {CommonConstants} from "../common-libs/constants"
 import {cliprogram} from "../common-libs/programOptions"
@@ -54,52 +52,6 @@ export class QuickSynchronizer {
   constructor(private conf: any, private dal:FileDAL, private logger: any) {
   }
 
-  async saveBlocksInMainBranch(blocks: BlockDTO[]): Promise<void> {
-    // Helper to retrieve a block with local cache
-    const getBlock = async (number: number): Promise<BlockDTO> => {
-      const firstLocalNumber = blocks[0].number;
-      if (number >= firstLocalNumber) {
-        let offset = number - firstLocalNumber;
-        return Promise.resolve(blocks[offset])
-      }
-      return BlockDTO.fromJSONObject(await this.dal.getBlockWeHaveItForSure(number))
-    };
-    const getBlockByNumberAndHash = async (number: number, hash: string): Promise<BlockDTO> => {
-      const block = await getBlock(number);
-      if (!block || block.hash != hash) {
-        throw 'Block #' + [number, hash].join('-') + ' not found neither in DB nor in applying blocks';
-      }
-      return block;
-    }
-    for (const block of blocks) {
-      block.fork = false;
-      const current:BlockDTO|null = block.number > 0 ? await getBlock(block.number - 1) : null
-      DuniterBlockchain.updateBlocksComputedVars(current, block)
-    }
-    // Transactions recording
-    await this.updateTransactionsForBlocks(blocks, getBlockByNumberAndHash);
-    await this.dal.blockDAL.saveBunch(blocks.map(b => DBBlock.fromBlockDTO(b)));
-    await DuniterBlockchain.pushStatsForBlocks(blocks, this.dal);
-  }
-
-  private async updateTransactionsForBlocks(blocks: BlockDTO[], getBlockByNumberAndHash: (number: number, hash: string) => Promise<BlockDTO>): Promise<any> {
-    let txs: DBTransaction[] = [];
-    for (const block of blocks) {
-      const newOnes: DBTransaction[] = [];
-      for (const tx of block.transactions) {
-        const [number, hash] = tx.blockstamp.split('-')
-        const refBlock: BlockDTO = (await getBlockByNumberAndHash(parseInt(number), hash))
-        // We force the usage of the reference block's currency
-        tx.currency = refBlock.currency
-        tx.hash = tx.getHash()
-        const dbTx: DBTransaction = DBTransaction.fromTransactionDTO(tx, refBlock.medianTime, true, false, refBlock.number, refBlock.medianTime)
-        newOnes.push(dbTx)
-      }
-      txs = txs.concat(newOnes);
-    }
-    return this.dal.updateTransactions(txs.map(t => DBTx.fromTransactionDTO(t)))
-  }
-
   async quickApplyBlocks(blocks:BlockDTO[], to: number): Promise<void> {
 
     sync_memoryDAL.sindexDAL = {
diff --git a/app/lib/dal/fileDAL.ts b/app/lib/dal/fileDAL.ts
index 8109af996..f5e556edb 100644
--- a/app/lib/dal/fileDAL.ts
+++ b/app/lib/dal/fileDAL.ts
@@ -1121,14 +1121,6 @@ export class FileDAL {
     return merkle;
   }
 
-  removeAllSourcesOfBlock(blockstamp:string) {
-    return this.sindexDAL.removeBlock(blockstamp)
-  }
-
-  updateTransactions(txs:DBTx[]) {
-    return this.txsDAL.insertBatchOfTxs(txs)
-  }
-
   savePendingIdentity(idty:DBIdentity) {
     return this.idtyDAL.saveIdentity(idty)
   }
diff --git a/app/lib/dal/indexDAL/abstract/TxsDAO.ts b/app/lib/dal/indexDAL/abstract/TxsDAO.ts
index 0f8961605..84c53b008 100644
--- a/app/lib/dal/indexDAL/abstract/TxsDAO.ts
+++ b/app/lib/dal/indexDAL/abstract/TxsDAO.ts
@@ -5,8 +5,6 @@ import {DBTx} from "../../../db/DBTx"
 
 export interface TxsDAO extends GenericDAO<DBTx> {
 
-  insertBatchOfTxs(txs:DBTx[]): Promise<void>
-
   trimExpiredNonWrittenTxs(limitTime:number): Promise<void>
 
   getAllPending(versionMin:number): Promise<DBTx[]>
diff --git a/app/lib/dal/indexDAL/loki/LokiTransactions.ts b/app/lib/dal/indexDAL/loki/LokiTransactions.ts
index 7db59faf4..78ebf7fe5 100644
--- a/app/lib/dal/indexDAL/loki/LokiTransactions.ts
+++ b/app/lib/dal/indexDAL/loki/LokiTransactions.ts
@@ -12,7 +12,6 @@
 // GNU Affero General Public License for more details.
 
 import * as moment from "moment"
-import {LokiIndex} from "./LokiIndex"
 import {TxsDAO} from "../abstract/TxsDAO"
 import {SandBox} from "../../sqliteDAL/SandBox"
 import {TransactionDTO} from "../../../dto/TransactionDTO"
@@ -50,10 +49,6 @@ export class LokiTransactions extends LokiProtocolIndex<DBTx> implements TxsDAO
       })
   }
 
-  async insertBatchOfTxs(txs: DBTx[]) {
-    return this.insertBatch(txs)
-  }
-
   sandbox: SandBox<{ issuers: string[]; output_base: number; output_amount: number }>
 
   async addLinked(tx: TransactionDTO, block_number: number, time: number): Promise<DBTx> {
diff --git a/app/lib/db/DBTransaction.ts b/app/lib/db/DBTransaction.ts
deleted file mode 100644
index 4e5bb3ab3..000000000
--- a/app/lib/db/DBTransaction.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-// Source file from duniter: Crypto-currency software to manage libre currency such as Äž1
-// Copyright (C) 2018  Cedric Moreau <cem.moreau@gmail.com>
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU Affero General Public License for more details.
-
-import {TransactionDTO} from "../dto/TransactionDTO"
-
-export class DBTransaction extends TransactionDTO {
-
-  constructor(
-    public version: number,
-    public currency: string,
-    public locktime: number,
-    public hash: string,
-    public blockstamp: string,
-    public issuers: string[],
-    public inputs: string[],
-    public outputs: string[],
-    public unlocks: string[],
-    public signatures: string[],
-    public comment: string,
-    public blockstampTime: number,
-    public written: boolean,
-    public removed: boolean,
-    public block_number: number,
-    public time: number,
-  ) {
-    super(
-      version,
-      currency,
-      locktime,
-      hash,
-      blockstamp,
-      blockstampTime,
-      issuers,
-      inputs,
-      outputs,
-      unlocks,
-      signatures,
-      comment
-    )
-  }
-
-  static fromTransactionDTO(dto:TransactionDTO, blockstampTime:number, written: boolean, removed: boolean, block_number:number, block_medianTime:number) {
-    return new DBTransaction(
-      dto.version,
-      dto.currency,
-      dto.locktime,
-      dto.hash,
-      dto.blockstamp,
-      dto.issuers,
-      dto.inputs,
-      dto.outputs,
-      dto.unlocks,
-      dto.signatures,
-      dto.comment || "",
-      blockstampTime,
-      written,
-      removed,
-      block_number,
-      block_medianTime
-    )
-  }
-}
\ No newline at end of file
-- 
GitLab