Mise à jour effectuée, merci de nous signaler tout dysfonctionnement ! | Upgrade done, please let us know about any dysfunction!

Commit 9dad9f67 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[enh] refactoring: remove unused code

parent 8bdcf146
......@@ -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 = {
......
......@@ -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)
}
......
......@@ -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[]>
......
......@@ -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> {
......
// 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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment