fix struct type

pull/7/head
yann300 8 years ago
parent 5a833953ff
commit 54060ecde0
  1. 27
      src/solidity/decodeInfo.js
  2. 2
      src/solidity/types/Struct.js

@ -165,26 +165,41 @@ function getEnum (type, stateDefinitions) {
*/
function getStructMembers (typeName, stateDefinitions) {
var members = []
var storageBytes = 0
for (var k in stateDefinitions) {
var dec = stateDefinitions[k]
if (dec.name === 'StructDefinition' && typeName === dec.attributes.name) {
var location = {
offset: 0,
slot: 0
}
for (var i in dec.children) {
var member = dec.children[i]
var decoded = parseType(member.attributes.type, stateDefinitions)
if (!decoded) {
var type = parseType(member.attributes.type, stateDefinitions)
if (location.offset + type.storageBytes > 32) {
location.slot++
location.offset = 0
}
if (!type) {
console.log('unable to retrieve decode info of ' + member.attributes.type)
return null
}
members.push(decoded)
storageBytes += decoded.storageBytes
members.push(type)
if (type.storageSlots === 1 && location.offset + type.storageBytes <= 32) {
location.offset += type.storageBytes
} else {
location.slot += type.storageSlots
location.offset = 0
}
}
if (location.offset > 0) {
location.slot++
}
break
}
}
return {
members: members,
storageBytes: storageBytes
storageBytes: location.slot
}
}

@ -1,7 +1,7 @@
'use strict'
function Struct (memberDetails) {
this.storageSlots = Math.ceil(memberDetails.storageBytes / 32)
this.storageSlots = memberDetails.storageBytes
this.storageBytes = 32
this.members = memberDetails.members
this.typeName = 'struct'

Loading…
Cancel
Save