From abc5a47925104f47ef260b9c2d9c84567fff7581 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 12 Jan 2017 15:37:10 +0100 Subject: [PATCH] rename decode -> decodeFromMemory --- src/solidity/types/ArrayType.js | 4 +-- src/solidity/types/DynamicByteArray.js | 2 +- src/solidity/types/RefType.js | 42 ++++++++++++-------------- src/solidity/types/StringType.js | 4 +-- src/solidity/types/Struct.js | 4 +-- src/solidity/types/ValueType.js | 11 ------- 6 files changed, 26 insertions(+), 41 deletions(-) diff --git a/src/solidity/types/ArrayType.js b/src/solidity/types/ArrayType.js index 1222b403df..40dbbdfa1c 100644 --- a/src/solidity/types/ArrayType.js +++ b/src/solidity/types/ArrayType.js @@ -56,7 +56,7 @@ class ArrayType extends RefType { } } - decodeFromMemory (offset, memory) { + decodeFromMemoryInternal (offset, memory) { var ret = [] var length = this.arraySize if (this.arraySize === 'dynamic') { @@ -66,7 +66,7 @@ class ArrayType extends RefType { } for (var k = 0; k < length; k++) { var contentOffset = offset - ret.push(this.underlyingType.decode(contentOffset, memory)) + ret.push(this.underlyingType.decodeFromMemory(contentOffset, memory)) offset += 32 } return ret diff --git a/src/solidity/types/DynamicByteArray.js b/src/solidity/types/DynamicByteArray.js index 42fb5c41c0..7c2999db41 100644 --- a/src/solidity/types/DynamicByteArray.js +++ b/src/solidity/types/DynamicByteArray.js @@ -35,7 +35,7 @@ class DynamicByteArray extends RefType { } } - decodeFromMemory (offset, memory) { + decodeFromMemoryInternal (offset, memory) { offset = 2 * offset var length = memory.substr(offset, 64) length = 2 * parseInt(length, 16) diff --git a/src/solidity/types/RefType.js b/src/solidity/types/RefType.js index 22439e8867..72d0120d73 100644 --- a/src/solidity/types/RefType.js +++ b/src/solidity/types/RefType.js @@ -14,29 +14,39 @@ class RefType { * * @param {Int} stackDepth - position of the type in the stack * @param {Array} stack - stack - * @return {String} - memory - * @return {Object} - storage + * @param {String} - memory + * @param {Object} - storage + * @return {Object} decoded value */ decodeFromStack (stackDepth, stack, memory, storage) { if (stack.length - 1 < stackDepth) { return { error: '' } } + if (!storage) { + storage = {} // TODO this is a fallback, should manage properly locals store in storage + } var offset = stack[stack.length - 1 - stackDepth] offset = parseInt(offset, 16) - return decodeInternal(this, offset, memory, storage) + if (this.storageStore()) { + return this.decodeFromStorage({ offset: 0, slot: offset }, storage) + } else if (this.memoryStore()) { + return this.decodeFromMemoryInternal(offset, memory) + } else { + return { error: '' } + } } /** - * decode the type with the @arg offset location from the memory or storage + * decode the type from the memory * - * @param {Int} offset - position of the type in the memory - * @return {String} - memory - * @return {Object} - storage + * @param {Int} offset - position of the ref of the type in memory + * @param {String} memory - memory + * @return {Object} decoded value */ - decode (offset, memory, storage) { + decodeFromMemory (offset, memory) { offset = memory.substr(2 * offset, 64) offset = parseInt(offset, 16) - return decodeInternal(this, offset, memory, storage) + return this.decodeFromMemoryInternal(offset, memory) } /** @@ -56,20 +66,6 @@ class RefType { memoryStore () { return this.location.indexOf('memory') === 0 } - -} - -function decodeInternal (self, offset, memory, storage) { - if (!storage) { - storage = {} // TODO this is a fallback, should manage properly locals store in storage - } - if (self.storageStore()) { - return self.decodeFromStorage({ offset: 0, slot: offset }, storage) - } else if (self.memoryStore()) { - return self.decodeFromMemory(offset, memory) - } else { - return { error: '' } - } } module.exports = RefType diff --git a/src/solidity/types/StringType.js b/src/solidity/types/StringType.js index e8a101cb77..8d3801a23c 100644 --- a/src/solidity/types/StringType.js +++ b/src/solidity/types/StringType.js @@ -16,8 +16,8 @@ class StringType extends DynamicBytes { return super.decodeFromStack(stackDepth, stack, memory) } - decodeFromMemory (offset, memory) { - var decoded = super.decodeFromMemory(offset, memory) + decodeFromMemoryInternal (offset, memory) { + var decoded = super.decodeFromMemoryInternal(offset, memory) return format(decoded) } } diff --git a/src/solidity/types/Struct.js b/src/solidity/types/Struct.js index 97ff485ac4..38781aba67 100644 --- a/src/solidity/types/Struct.js +++ b/src/solidity/types/Struct.js @@ -20,11 +20,11 @@ class Struct extends RefType { return ret } - decodeFromMemory (offset, memory) { + decodeFromMemoryInternal (offset, memory) { var ret = {} this.members.map((item, i) => { var contentOffset = offset - var member = item.type.decode(contentOffset, memory) + var member = item.type.decodeFromMemory(contentOffset, memory) ret[item.name] = member offset += 32 }) diff --git a/src/solidity/types/ValueType.js b/src/solidity/types/ValueType.js index 4e5ba47069..5d7d17683a 100644 --- a/src/solidity/types/ValueType.js +++ b/src/solidity/types/ValueType.js @@ -48,17 +48,6 @@ class ValueType { var value = memory.substr(2 * offset, 64) return this.decodeValue(util.extractHexByteSlice(value, this.storageBytes, 0)) } - - /** - * decode the type with the @arg offset location from the memory - * - * @param {Int} offset - position of the type in the memory - * @return {String} - memory - * @return {Object} - storage - */ - decode (offset, memory) { - return this.decodeFromMemory(offset, memory) - } } module.exports = ValueType