Skip to content

Commit

Permalink
[EEX-751] Fix large contract verify error (#149)
Browse files Browse the repository at this point in the history
  • Loading branch information
kosAndrey22 authored and doomdabidon committed Jan 9, 2020
1 parent 6c75da1 commit 9522409
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"description": "Explorer for Echo platform",
"homepage": "https://github.com/echoprotocol/explorer",
"version": "1.5.1",
"version": "1.5.2",
"license": "MIT",
"main": "server.js",
"scripts": {
Expand Down
26 changes: 21 additions & 5 deletions src/actions/ContractActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import { getContractInfo, getTotalHistory } from '../services/queries/contract';

import { loadScript } from '../api/ContractApi';
import browserHistory from '../history';
import { COMPILER_CONSTS } from '../constants/ContractConstants';

class ContractActions extends BaseActionsClass {

Expand Down Expand Up @@ -298,7 +299,7 @@ class ContractActions extends BaseActionsClass {
};
}

contractCodeCompile(code, filename = 'test.sol') {
contractCodeCompile(code, filename = 'test.sol', attempt = 1) {
return async (dispatch, getState) => {
if (!code) {
code = getState().form.getIn([FORM_CONTRACT_VERIFY, 'code']);
Expand Down Expand Up @@ -333,6 +334,10 @@ class ContractActions extends BaseActionsClass {

const solc = wrapper(window.Module);
const output = JSON.parse(solc.compile(JSON.stringify(input)));
const errors = this.getErrors(output);
if (errors.length) {
throw new Error(errors);
}
let contracts = new Map({});
contracts = contracts.withMutations((contractsMap) => {
Object.entries(output.contracts[filename]).forEach(([name, contract]) => {
Expand All @@ -347,13 +352,24 @@ class ContractActions extends BaseActionsClass {
dispatch(FormActions.setValue(FORM_CONTRACT_VERIFY, 'contractName', contracts.keySeq().first()));
dispatch(FormActions.setFormError(FORM_CONTRACT_VERIFY, 'currentCompiler', null));
} catch (err) {
dispatch(FormActions.setFormError(FORM_CONTRACT_VERIFY, 'currentCompiler', 'Invalid contract code'));
dispatch(this.setValue('contracts', new Map({})));
dispatch(FormActions.setValue(FORM_CONTRACT_VERIFY, 'contractName', ''));
if (err.message.indexOf(COMPILER_CONSTS.SOLC_NOT_ENOUGH_STACK_ERROR) !== -1
&& attempt < COMPILER_CONSTS.MAX_TRIES_TO_COMPILE) {
dispatch(this.contractCodeCompile(code, filename, attempt + 1));
} else {
dispatch(FormActions.setFormError(FORM_CONTRACT_VERIFY, 'currentCompiler', 'Invalid contract code'));
dispatch(this.setValue('contracts', new Map({})));
dispatch(FormActions.setValue(FORM_CONTRACT_VERIFY, 'contractName', ''));
}
}
};
}

getErrors(output) {
const { errors } = output;
if (!errors) {
return [];
}
return errors.map((err) => err.formattedMessage);
}
manageContract(contractId, name, icon, description, clickSaveCounter) {
return async (dispatch, getState) => {

Expand Down
5 changes: 4 additions & 1 deletion src/constants/ContractConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ export const CONTRACT_TABS = {
};

export const CHANGE_TEXT_TIME = 2000;

export const COMPILER_CONSTS = {
SOLC_NOT_ENOUGH_STACK_ERROR: 'Maximum call stack size exceeded',
MAX_TRIES_TO_COMPILE: 2,
};

0 comments on commit 9522409

Please sign in to comment.