From f574ee65de9b45295e3aec7e6afe10ee9bed3a93 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 12 Dec 2016 16:39:26 +0100 Subject: [PATCH] decode enum --- src/solidity/types/Enum.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/solidity/types/Enum.js b/src/solidity/types/Enum.js index e8aca6a9cd..f8950209b5 100644 --- a/src/solidity/types/Enum.js +++ b/src/solidity/types/Enum.js @@ -16,8 +16,23 @@ function Enum (enumDef) { Enum.prototype.decodeFromStorage = function (location, storageContent) { var value = util.extractHexValue(location, storageContent, this.storageBytes) value = parseInt(value, 16) - if (this.enumDef.children.length > value) { - return this.enumDef.children[value].attributes.name + return output(value, this.enumDef) +} + +Enum.prototype.decodeLocals = function (stackHeight, stack, memory) { + var defaultValue = 0 + if (stack.length - 1 < stackHeight) { + defaultValue = 0 + } else { + defaultValue = util.extractHexByteSlice(stack[stack.length - 1 - stackHeight], this.storageBytes, 0) + defaultValue = parseInt(defaultValue, 16) + } + return output(defaultValue, this.enumDef) +} + +function output (value, enumDef) { + if (enumDef.children.length > value) { + return enumDef.children[value].attributes.name } else { return 'INVALID_ENUM<' + value + '>' }