rename decode -> decodeFromMemory

pull/7/head
yann300 8 years ago
parent 4c09db3707
commit abc5a47925
  1. 4
      src/solidity/types/ArrayType.js
  2. 2
      src/solidity/types/DynamicByteArray.js
  3. 42
      src/solidity/types/RefType.js
  4. 4
      src/solidity/types/StringType.js
  5. 4
      src/solidity/types/Struct.js
  6. 11
      src/solidity/types/ValueType.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

@ -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)

@ -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: '<decoding failed - stack underflow ' + stackDepth + '>' }
}
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: '<decoding failed - no decoder for ' + this.location + '>' }
}
}
/**
* 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: '<decoding failed - no decoder for ' + self.location + '>' }
}
}
module.exports = RefType

@ -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)
}
}

@ -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
})

@ -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

Loading…
Cancel
Save