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
No related branches found
No related tags found
No related merge requests found
...@@ -94,6 +94,9 @@ module.exports = { ...@@ -94,6 +94,9 @@ module.exports = {
FIRST_UNIT_BASE: 0, FIRST_UNIT_BASE: 0,
PEER: CommonConstants.PEER, PEER: CommonConstants.PEER,
CURRENT_DB_VERSION: 26,
NETWORK: { NETWORK: {
MAX_MEMBERS_TO_FORWARD_TO_FOR_SELF_DOCUMENTS: 10, MAX_MEMBERS_TO_FORWARD_TO_FOR_SELF_DOCUMENTS: 10,
MAX_NON_MEMBERS_TO_FORWARD_TO_FOR_SELF_DOCUMENTS: 6, MAX_NON_MEMBERS_TO_FORWARD_TO_FOR_SELF_DOCUMENTS: 6,
......
...@@ -13,6 +13,7 @@ import {DBBlock} from "../../db/DBBlock" ...@@ -13,6 +13,7 @@ import {DBBlock} from "../../db/DBBlock"
import {IdentityDTO} from "../../dto/IdentityDTO" import {IdentityDTO} from "../../dto/IdentityDTO"
import {rawer} from "../../common-libs/index" import {rawer} from "../../common-libs/index"
import {CommonConstants} from "../../common-libs/constants" import {CommonConstants} from "../../common-libs/constants"
import {TxsDAL} from "./TxsDAL"
const _ = require('underscore') const _ = require('underscore')
const logger = require('../../logger').NewLogger('metaDAL'); const logger = require('../../logger').NewLogger('metaDAL');
...@@ -364,6 +365,36 @@ export class MetaDAL extends AbstractSQLite<DBMeta> { ...@@ -364,6 +365,36 @@ export class MetaDAL extends AbstractSQLite<DBMeta> {
await mindexDAL.exec(updateQuery) 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() { async init() {
......
import {hashf} from "../common" import {hashf} from "../common"
import {Cloneable} from "./Cloneable"; import {Cloneable} from "./Cloneable"
export interface BaseDTO { export interface BaseDTO {
base: number base: number
...@@ -250,6 +250,10 @@ export class TransactionDTO implements Cloneable { ...@@ -250,6 +250,10 @@ export class TransactionDTO implements Cloneable {
return [o.amount, o.base, o.conditions].join(':') 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) { static outputStr2Obj(outputStr:string) {
const sp = outputStr.split(':'); const sp = outputStr.split(':');
return { return {
......
...@@ -103,7 +103,7 @@ describe("DAL", function(){ ...@@ -103,7 +103,7 @@ describe("DAL", function(){
it('should have DB version 21', () => co(function *() { it('should have DB version 21', () => co(function *() {
let version = yield fileDAL.getDBVersion(); let version = yield fileDAL.getDBVersion();
should.exist(version); should.exist(version);
version.should.equal(25); version.should.equal(constants.CURRENT_DB_VERSION);
})); }));
it('should have no peer in a first time', function(){ 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