Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deserialisation #53

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions modules/blockHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}


Expand Down
24 changes: 19 additions & 5 deletions modules/smartContracts/EcmaContract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1634,7 +1643,6 @@ class EcmaContract {
_handleContractDeploy(address, code, state, block, callback) {
let that = this;


/**
* Initiate and run contract
*/
Expand All @@ -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');
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions modules/validators/dlcpoa.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
11 changes: 10 additions & 1 deletion modules/validators/lcpoa.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
10 changes: 9 additions & 1 deletion modules/validators/thrusted.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down