diff --git a/modules/blockHandler.js b/modules/blockHandler.js index 9845f45..5e06ace 100644 --- a/modules/blockHandler.js +++ b/modules/blockHandler.js @@ -247,11 +247,15 @@ class BlockHandler { try { let blockData; - try { - blockData = JSON.parse(block.data); - } catch (e) { - logger.info('Not JSON block ' + block.index); - return callback(); + if (typeof block.data ==="object") { + blockData = block.data; + } else { + try { + blockData = JSON.parse(block.data); + } catch (e) { + that.log('Info: Not JSON block ' + block.index); + return callback(); + } } diff --git a/modules/smartContracts/EcmaContract.js b/modules/smartContracts/EcmaContract.js index 06295c7..738b661 100644 --- a/modules/smartContracts/EcmaContract.js +++ b/modules/smartContracts/EcmaContract.js @@ -1474,7 +1474,16 @@ class EcmaContract { that.blockchain.generateNextBlockAuto(callBlock, function (generatedBlock) { that.events._handleBlockReplay(generatedBlock.index, function () { - that._handleBlock(JSON.parse(generatedBlock.data), generatedBlock, true, (err) => { + //console.log(generatedBlock.data); + let generatedBlockData = generatedBlock.data; + if (typeof generatedBlockData !== "object"){ + try { + generatedBlockData = JSON.parse(generatedBlock.data) + } catch (e) { + assert.assert(false, e.toString()); + } + } + that._handleBlock(generatedBlock.data, generatedBlock, true, (err) => { if(err) { cb(err); return; @@ -1634,7 +1643,6 @@ class EcmaContract { _handleContractDeploy(address, code, state, block, callback) { let that = this; - /** * Initiate and run contract */ @@ -1643,7 +1651,7 @@ class EcmaContract { state.block = block; state.contractAddress = address; let contract = {code: code, state: state}; - + that.contracts.put(address, JSON.stringify(contract), function (err) { if(err) { logger.error('Contract deploy handling error'); @@ -1799,10 +1807,15 @@ class EcmaContract { let verifyBlock = {}; let testWallet = new Wallet(false, that.config); + //exclude circullar links + let blockState={}; + Object.assign(blockState, blockData.state); switch (blockData.type) { case EcmaContractDeployBlock.blockType: + + verifyBlock = new EcmaContractDeployBlock(blockData.ecmaCode, blockData.state); if(verifyBlock.data !== blockData.data) { @@ -1819,10 +1832,11 @@ class EcmaContract { return } - this._handleContractDeploy(block.index, blockData.ecmaCode, blockData.state, block, callback); + this._handleContractDeploy(block.index, blockData.ecmaCode, blockState, block, callback); break; case EcmaContractCallBlock.blockType: + verifyBlock = new EcmaContractCallBlock(blockData.address, blockData.method, blockData.args, blockData.state); if(verifyBlock.data !== blockData.data) { logger.error('Contract invalid data in block ' + block.index); @@ -1838,7 +1852,7 @@ class EcmaContract { return } - this._handleContractCall(blockData.address, blockData.method, blockData.args, blockData.state, block, testOnly, callback); + this._handleContractCall(blockData.address, blockData.method, blockData.args, blockState, block, testOnly, callback); break; default: diff --git a/modules/validators/dlcpoa.js b/modules/validators/dlcpoa.js index 327a9b9..f8077a1 100644 --- a/modules/validators/dlcpoa.js +++ b/modules/validators/dlcpoa.js @@ -132,8 +132,18 @@ function generateNextBlock(blockData, cb, cancelCondition) { /*if(miningNow) { return; }*/ + /* if(typeof blockData === 'object') { blockData = JSON.stringify(blockData); + }*/ + + if (typeof blockData !== 'object') { + try { + blockData = JSON.parse(blockData); + } catch (e) { + console.log('Info: Error in block data.'); + return false; + } } /*if(blockchain.config.program.disableMining){ diff --git a/modules/validators/lcpoa.js b/modules/validators/lcpoa.js index 8b45ec3..e93d895 100644 --- a/modules/validators/lcpoa.js +++ b/modules/validators/lcpoa.js @@ -84,8 +84,17 @@ function generateNextBlock(blockData, cb, cancelCondition) { /*if(miningNow) { return; }*/ - if(typeof blockData === 'object') { + /*if(typeof blockData === 'object') { blockData = JSON.stringify(blockData); + }*/ + + if (typeof blockData !== 'object') { + try { + blockData = JSON.parse(blockData); + } catch (e) { + console.log('Info: Error in block data.'); + return false; + } } /*if(blockchain.config.program.disableMining){ diff --git a/modules/validators/thrusted.js b/modules/validators/thrusted.js index 5036ca4..036a679 100644 --- a/modules/validators/thrusted.js +++ b/modules/validators/thrusted.js @@ -183,8 +183,16 @@ function generateNextBlock(blockData, cb, cancelCondition, timestamp) { return false; } - if(typeof blockData === 'object') { + /*if(typeof blockData === 'object') { blockData = JSON.stringify(blockData); + }*/ + if (typeof blockData !== 'object') { + try { + blockData = JSON.parse(blockData); + } catch (e) { + console.log('Info: Error in block data.'); + return false; + } } blockchain.getLatestBlock(function (previousBlock) {