diff --git a/app/lib/constants.ts b/app/lib/constants.ts index b9354483b7dfb1a4168826a04ba295623aaafe13..15a743224ba820841ac36c83bac7adf7b17e559a 100644 --- a/app/lib/constants.ts +++ b/app/lib/constants.ts @@ -94,6 +94,9 @@ module.exports = { FIRST_UNIT_BASE: 0, PEER: CommonConstants.PEER, + + CURRENT_DB_VERSION: 26, + NETWORK: { MAX_MEMBERS_TO_FORWARD_TO_FOR_SELF_DOCUMENTS: 10, MAX_NON_MEMBERS_TO_FORWARD_TO_FOR_SELF_DOCUMENTS: 6, diff --git a/app/lib/dal/sqliteDAL/MetaDAL.ts b/app/lib/dal/sqliteDAL/MetaDAL.ts index eceba0a290aa0e3c5c299d1bf3368b772ca2a61a..158d39f4ddf10a1890ac3af8a93483272bce39aa 100644 --- a/app/lib/dal/sqliteDAL/MetaDAL.ts +++ b/app/lib/dal/sqliteDAL/MetaDAL.ts @@ -13,6 +13,7 @@ import {DBBlock} from "../../db/DBBlock" import {IdentityDTO} from "../../dto/IdentityDTO" import {rawer} from "../../common-libs/index" import {CommonConstants} from "../../common-libs/constants" +import {TxsDAL} from "./TxsDAL" const _ = require('underscore') const logger = require('../../logger').NewLogger('metaDAL'); @@ -364,6 +365,36 @@ export class MetaDAL extends AbstractSQLite<DBMeta> { await mindexDAL.exec(updateQuery) } }, + + /** + * Wrong transaction storage + */ + 25: async () => { + const txsDAL = new TxsDAL(this.driverCopy) + const wrongTXS = await txsDAL.query('SELECT * FROM txs WHERE outputs LIKE ? OR inputs LIKE ?', ['%amount%', '%amount%']) + let i = 1 + for (const tx of wrongTXS) { + logger.info('Updating incorrect transaction %s/%s.', i, wrongTXS.length) + i++ + const dto = TransactionDTO.fromJSONObject(tx) + dto.outputs = dto.outputs.map(o => { + if (typeof o === 'object') { + return TransactionDTO.outputObj2Str(o) + } + return o + }) + dto.inputs = dto.inputs.map(o => { + if (typeof o === 'object') { + return TransactionDTO.inputObj2Str(o) + } + return o + }) + await txsDAL.exec('UPDATE txs SET ' + + 'outputs = \'' + JSON.stringify(dto.outputs) + '\', ' + + 'inputs = \'' + JSON.stringify(dto.inputs) + '\' ' + + 'WHERE hash = \'' + tx.hash + '\'') + } + }, }; async init() { diff --git a/app/lib/dto/TransactionDTO.ts b/app/lib/dto/TransactionDTO.ts index 97c43cde7a590b7bc27bff8fba54d07c275664af..15e65a4a2359298395d53b1c7822df5df93493a9 100644 --- a/app/lib/dto/TransactionDTO.ts +++ b/app/lib/dto/TransactionDTO.ts @@ -1,5 +1,5 @@ import {hashf} from "../common" -import {Cloneable} from "./Cloneable"; +import {Cloneable} from "./Cloneable" export interface BaseDTO { base: number @@ -250,6 +250,10 @@ export class TransactionDTO implements Cloneable { return [o.amount, o.base, o.conditions].join(':') } + static inputObj2Str(i:InputDTO) { + return [i.amount, i.base, i.type, i.identifier, i.pos].join(':') + } + static outputStr2Obj(outputStr:string) { const sp = outputStr.split(':'); return { diff --git a/test/dal/dal.js b/test/dal/dal.js index 44b1a63d33fa7ee35fc5a84e4127616cbd712616..a4014a2441a4a66b37fbd5d35bdc8da7feac5c44 100644 --- a/test/dal/dal.js +++ b/test/dal/dal.js @@ -103,7 +103,7 @@ describe("DAL", function(){ it('should have DB version 21', () => co(function *() { let version = yield fileDAL.getDBVersion(); should.exist(version); - version.should.equal(25); + version.should.equal(constants.CURRENT_DB_VERSION); })); it('should have no peer in a first time', function(){