Skip to content
Snippets Groups Projects
Commit 80b1380d authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[fix] #1073 /tx/history returns wrong JSON

parent 81bc5b48
Branches
Tags
No related merge requests found
......@@ -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,
......
......@@ -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() {
......
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 {
......
......@@ -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(){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment