From dffb217ffd410ee368f7ca713e6489bf4c738002 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 9 Jan 2017 14:25:35 +0100 Subject: [PATCH] add contract type + don't throw if type not found --- src/solidity/decodeInfo.js | 10 +++++++++- src/solidity/stateDecoder.js | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/solidity/decodeInfo.js b/src/solidity/decodeInfo.js index 3246a1cf36..8303844827 100644 --- a/src/solidity/decodeInfo.js +++ b/src/solidity/decodeInfo.js @@ -203,6 +203,9 @@ function getStructMembers (type, stateDefinitions, contractName) { for (var dec of state.stateDefinitions) { if (dec.name === 'StructDefinition' && type === contractName + '.' + dec.attributes.name) { var offsets = computeOffsets(dec.children, stateDefinitions, contractName) + if (!offsets) { + return null + } return { members: offsets.typesOffsets, storageSlots: offsets.endLocation.slot @@ -244,6 +247,7 @@ function typeClass (fullType) { function parseType (type, stateDefinitions, contractName) { var decodeInfos = { 'address': Address, + 'contract': Address, 'array': Array, 'bool': Bool, 'bytes': DynamicByteArray, @@ -260,7 +264,11 @@ function parseType (type, stateDefinitions, contractName) { console.log('unable to retrieve decode info of ' + type) return null } - return decodeInfos[currentType](type, stateDefinitions, contractName) + if (decodeInfos[currentType]) { + return decodeInfos[currentType](type, stateDefinitions, contractName) + } else { + return null + } } /** diff --git a/src/solidity/stateDecoder.js b/src/solidity/stateDecoder.js index be77fe6b60..cbc5cc006e 100644 --- a/src/solidity/stateDecoder.js +++ b/src/solidity/stateDecoder.js @@ -31,6 +31,9 @@ function extractStateVariables (contractName, sourcesList) { } var types = states[contractName].stateVariables var offsets = decodeInfo.computeOffsets(types, states, contractName) + if (!offsets) { + return [] // TODO should maybe return an error + } return offsets.typesOffsets }