diff --git a/src/solidity/types/Struct.js b/src/solidity/types/Struct.js index 666c45a02e..26899e378a 100644 --- a/src/solidity/types/Struct.js +++ b/src/solidity/types/Struct.js @@ -45,4 +45,29 @@ Struct.prototype.decodeFromMemory = function (offset, memory) { return ret } +Struct.prototype.decodeLocals = function (stackHeight, stack, memory) { + if (stack.length - 1 < stackHeight) { + return {} + } else { // TODO manage decoding locals from storage + var offset = stack[stack.length - 1 - stackHeight] + offset = 2 * parseInt(offset, 16) + return this.decodeFromMemory(offset, memory) + } +} + +Struct.prototype.decodeFromMemory = function (offset, memory) { + var ret = {} + this.members.map(function (item, i) { + var contentOffset = offset + if (item.type.typeName === 'bytes' || item.type.typeName === 'string' || item.type.typeName === 'array' || item.type.typeName === 'struct') { + contentOffset = memory.substr(offset, 64) + contentOffset = 2 * parseInt(contentOffset, 16) + } + var member = item.type.decodeFromMemory(contentOffset, memory) + ret[item.name] = member + offset += 64 + }) + return ret +} + module.exports = Struct