diff --git a/src/solidity/types/ArrayType.js b/src/solidity/types/ArrayType.js index 4ea4878d93..53743f3de5 100644 --- a/src/solidity/types/ArrayType.js +++ b/src/solidity/types/ArrayType.js @@ -67,10 +67,6 @@ class ArrayType extends RefType { this.underlyingType.location = this.location for (var k = 0; k < length; k++) { var contentOffset = offset - if (this.underlyingType.basicType === 'RefType') { - contentOffset = memory.substr(2 * contentOffset, 64) - contentOffset = parseInt(contentOffset, 16) - } ret.push(this.underlyingType.decode(contentOffset, memory)) offset += 32 } diff --git a/src/solidity/types/RefType.js b/src/solidity/types/RefType.js index c3fde503ef..cdcb46c250 100644 --- a/src/solidity/types/RefType.js +++ b/src/solidity/types/RefType.js @@ -11,28 +11,31 @@ class RefType { } decodeFromStack (stackDepth, stack, memory, storage) { - if (!storage) { - storage = {} // TODO this is a fallback, should manage properly locals store in storage - } if (stack.length - 1 < stackDepth) { return { error: '' } } var offset = stack[stack.length - 1 - stackDepth] offset = parseInt(offset, 16) - return this.decode(offset, memory, storage) + return decodeInternal(this, offset, memory, storage) } decode (offset, memory, storage) { - if (!storage) { - storage = {} // TODO this is a fallback, should manage properly locals store in storage - } - if (util.storageStore(this)) { - return this.decodeFromStorage({ offset: 0, slot: offset }, storage) - } else if (util.memoryStore(this)) { - return this.decodeFromMemory(offset, memory) - } else { - return { error: '' } - } + offset = memory.substr(2 * offset, 64) + offset = parseInt(offset, 16) + return decodeInternal(this, offset, memory, storage) + } +} + +function decodeInternal (self, offset, memory, storage) { + if (!storage) { + storage = {} // TODO this is a fallback, should manage properly locals store in storage + } + if (util.storageStore(self)) { + return self.decodeFromStorage({ offset: 0, slot: offset }, storage) + } else if (util.memoryStore(self)) { + return self.decodeFromMemory(offset, memory) + } else { + return { error: '' } } } diff --git a/src/solidity/types/Struct.js b/src/solidity/types/Struct.js index bd6864db1d..c0804d6123 100644 --- a/src/solidity/types/Struct.js +++ b/src/solidity/types/Struct.js @@ -24,10 +24,6 @@ class Struct extends RefType { var ret = {} this.members.map((item, i) => { var contentOffset = offset - if (item.type.basicType === 'RefType') { - contentOffset = memory.substr(2 * contentOffset, 64) - contentOffset = parseInt(contentOffset, 16) - } item.type.location = this.location var member = item.type.decode(contentOffset, memory) ret[item.name] = member