always use bytes offset as param

pull/7/head
yann300 8 years ago
parent f06cc737da
commit 249dbdf64a
  1. 20
      src/solidity/types/ArrayType.js
  2. 5
      src/solidity/types/Struct.js
  3. 1
      src/solidity/types/ValueType.js

@ -57,33 +57,25 @@ class ArrayType extends RefType {
} }
decodeFromMemory (offset, memory) { decodeFromMemory (offset, memory) {
offset = 2 * offset
var ret = [] var ret = []
var length = extractLength(this, offset, memory) var length = this.arraySize
if (this.arraySize === 'dynamic') { if (this.arraySize === 'dynamic') {
offset = offset + 64 length = memory.substr(2 * offset, 64)
length = parseInt(length, 16)
offset = offset + 32
} }
this.underlyingType.location = this.location this.underlyingType.location = this.location
for (var k = 0; k < length; k++) { for (var k = 0; k < length; k++) {
var contentOffset = offset var contentOffset = offset
if (this.underlyingType.basicType === 'RefType') { if (this.underlyingType.basicType === 'RefType') {
contentOffset = memory.substr(offset, 64) contentOffset = memory.substr(2 * contentOffset, 64)
contentOffset = parseInt(contentOffset, 16) contentOffset = parseInt(contentOffset, 16)
} }
ret.push(this.underlyingType.decode(contentOffset, memory)) ret.push(this.underlyingType.decode(contentOffset, memory))
offset += 64 offset += 32
} }
return ret return ret
} }
} }
function extractLength (type, offset, memory) {
var length = type.arraySize
if (length === 'dynamic') {
length = memory.substr(offset, 64)
length = parseInt(length, 16)
}
return length
}
module.exports = ArrayType module.exports = ArrayType

@ -21,18 +21,17 @@ class Struct extends RefType {
} }
decodeFromMemory (offset, memory) { decodeFromMemory (offset, memory) {
offset = 2 * offset
var ret = {} var ret = {}
this.members.map((item, i) => { this.members.map((item, i) => {
var contentOffset = offset var contentOffset = offset
if (item.type.basicType === 'RefType') { if (item.type.basicType === 'RefType') {
contentOffset = memory.substr(contentOffset, 64) contentOffset = memory.substr(2 * contentOffset, 64)
contentOffset = parseInt(contentOffset, 16) contentOffset = parseInt(contentOffset, 16)
} }
item.type.location = this.location item.type.location = this.location
var member = item.type.decode(contentOffset, memory) var member = item.type.decode(contentOffset, memory)
ret[item.name] = member ret[item.name] = member
offset += 64 offset += 32
}) })
return ret return ret
} }

@ -28,7 +28,6 @@ class ValueType {
} }
decode (offset, memory) { decode (offset, memory) {
offset = offset / 2
return this.decodeFromMemory(offset, memory) return this.decodeFromMemory(offset, memory)
} }
} }

Loading…
Cancel
Save