Commit 311289a0 authored by yann300's avatar yann300

rename location storagelocation

parent 70a880a8
...@@ -286,7 +286,7 @@ function parseType (type, stateDefinitions, contractName) { ...@@ -286,7 +286,7 @@ function parseType (type, stateDefinitions, contractName) {
*/ */
function computeOffsets (types, stateDefinitions, contractName) { function computeOffsets (types, stateDefinitions, contractName) {
var ret = [] var ret = []
var location = { var storagelocation = {
offset: 0, offset: 0,
slot: 0 slot: 0
} }
...@@ -297,31 +297,31 @@ function computeOffsets (types, stateDefinitions, contractName) { ...@@ -297,31 +297,31 @@ function computeOffsets (types, stateDefinitions, contractName) {
console.log('unable to retrieve decode info of ' + variable.attributes.type) console.log('unable to retrieve decode info of ' + variable.attributes.type)
return null return null
} }
if (location.offset + type.storageBytes > 32) { if (storagelocation.offset + type.storageBytes > 32) {
location.slot++ storagelocation.slot++
location.offset = 0 storagelocation.offset = 0
} }
ret.push({ ret.push({
name: variable.attributes.name, name: variable.attributes.name,
type: type, type: type,
location: { storagelocation: {
offset: location.offset, offset: storagelocation.offset,
slot: location.slot slot: storagelocation.slot
} }
}) })
if (type.storageSlots === 1 && location.offset + type.storageBytes <= 32) { if (type.storageSlots === 1 && storagelocation.offset + type.storageBytes <= 32) {
location.offset += type.storageBytes storagelocation.offset += type.storageBytes
} else { } else {
location.slot += type.storageSlots storagelocation.slot += type.storageSlots
location.offset = 0 storagelocation.offset = 0
} }
} }
if (location.offset > 0) { if (storagelocation.offset > 0) {
location.slot++ storagelocation.slot++
} }
return { return {
typesOffsets: ret, typesOffsets: ret,
endLocation: location endLocation: storagelocation
} }
} }
......
...@@ -12,7 +12,7 @@ function decodeState (stateVars, storageContent) { ...@@ -12,7 +12,7 @@ function decodeState (stateVars, storageContent) {
var ret = {} var ret = {}
for (var k in stateVars) { for (var k in stateVars) {
var stateVar = stateVars[k] var stateVar = stateVars[k]
ret[stateVar.name] = stateVar.type.decodeFromStorage(stateVar.location, storageContent) ret[stateVar.name] = stateVar.type.decodeFromStorage(stateVar.storagelocation, storageContent)
} }
return ret return ret
} }
......
...@@ -12,8 +12,8 @@ class Struct extends RefType { ...@@ -12,8 +12,8 @@ class Struct extends RefType {
var ret = {} var ret = {}
this.members.map(function (item, i) { this.members.map(function (item, i) {
var globalLocation = { var globalLocation = {
offset: location.offset + item.location.offset, offset: location.offset + item.storagelocation.offset,
slot: util.add(location.slot, item.location.slot) slot: util.add(location.slot, item.storagelocation.slot)
} }
ret[item.name] = item.type.decodeFromStorage(globalLocation, storageContent) ret[item.name] = item.type.decodeFromStorage(globalLocation, storageContent)
}) })
......
...@@ -8,43 +8,43 @@ tape('solidity', function (t) { ...@@ -8,43 +8,43 @@ tape('solidity', function (t) {
t.test('storage location', function (st) { t.test('storage location', function (st) {
var output = compiler.compile(contracts, 0) var output = compiler.compile(contracts, 0)
var stateDec = index.solidity.stateDecoder.extractStateVariables('contractUint', output.sources) var stateDec = index.solidity.stateDecoder.extractStateVariables('contractUint', output.sources)
checkLocation(st, stateDec[0].location, 0, 0) checkLocation(st, stateDec[0].storagelocation, 0, 0)
checkLocation(st, stateDec[1].location, 1, 0) checkLocation(st, stateDec[1].storagelocation, 1, 0)
checkLocation(st, stateDec[2].location, 2, 0) checkLocation(st, stateDec[2].storagelocation, 2, 0)
checkLocation(st, stateDec[3].location, 3, 0) checkLocation(st, stateDec[3].storagelocation, 3, 0)
stateDec = index.solidity.stateDecoder.extractStateVariables('contractStructAndArray', output.sources) stateDec = index.solidity.stateDecoder.extractStateVariables('contractStructAndArray', output.sources)
checkLocation(st, stateDec[0].location, 0, 0) checkLocation(st, stateDec[0].storagelocation, 0, 0)
checkLocation(st, stateDec[1].location, 2, 0) checkLocation(st, stateDec[1].storagelocation, 2, 0)
checkLocation(st, stateDec[2].location, 8, 0) checkLocation(st, stateDec[2].storagelocation, 8, 0)
stateDec = index.solidity.stateDecoder.extractStateVariables('contractArray', output.sources) stateDec = index.solidity.stateDecoder.extractStateVariables('contractArray', output.sources)
checkLocation(st, stateDec[0].location, 0, 0) checkLocation(st, stateDec[0].storagelocation, 0, 0)
checkLocation(st, stateDec[1].location, 1, 0) checkLocation(st, stateDec[1].storagelocation, 1, 0)
checkLocation(st, stateDec[2].location, 2, 0) checkLocation(st, stateDec[2].storagelocation, 2, 0)
stateDec = index.solidity.stateDecoder.extractStateVariables('contractSmallVariable', output.sources) stateDec = index.solidity.stateDecoder.extractStateVariables('contractSmallVariable', output.sources)
checkLocation(st, stateDec[0].location, 0, 0) checkLocation(st, stateDec[0].storagelocation, 0, 0)
checkLocation(st, stateDec[1].location, 0, 1) checkLocation(st, stateDec[1].storagelocation, 0, 1)
checkLocation(st, stateDec[2].location, 0, 2) checkLocation(st, stateDec[2].storagelocation, 0, 2)
checkLocation(st, stateDec[3].location, 0, 4) checkLocation(st, stateDec[3].storagelocation, 0, 4)
checkLocation(st, stateDec[4].location, 1, 0) checkLocation(st, stateDec[4].storagelocation, 1, 0)
checkLocation(st, stateDec[5].location, 2, 0) checkLocation(st, stateDec[5].storagelocation, 2, 0)
stateDec = index.solidity.stateDecoder.extractStateVariables('testSimpleStorage', output.sources) stateDec = index.solidity.stateDecoder.extractStateVariables('testSimpleStorage', output.sources)
checkLocation(st, stateDec[0].location, 0, 0) checkLocation(st, stateDec[0].storagelocation, 0, 0)
checkLocation(st, stateDec[1].location, 1, 0) checkLocation(st, stateDec[1].storagelocation, 1, 0)
checkLocation(st, stateDec[2].location, 2, 0) checkLocation(st, stateDec[2].storagelocation, 2, 0)
checkLocation(st, stateDec[3].location, 3, 0) checkLocation(st, stateDec[3].storagelocation, 3, 0)
checkLocation(st, stateDec[4].location, 4, 0) checkLocation(st, stateDec[4].storagelocation, 4, 0)
checkLocation(st, stateDec[5].location, 8, 0) checkLocation(st, stateDec[5].storagelocation, 8, 0)
checkLocation(st, stateDec[6].location, 9, 0) checkLocation(st, stateDec[6].storagelocation, 9, 0)
checkLocation(st, stateDec[8].location, 17, 0) checkLocation(st, stateDec[8].storagelocation, 17, 0)
checkLocation(st, stateDec[9].location, 17, 4) checkLocation(st, stateDec[9].storagelocation, 17, 4)
checkLocation(st, stateDec[10].location, 17, 6) checkLocation(st, stateDec[10].storagelocation, 17, 6)
checkLocation(st, stateDec[11].location, 17, 7) checkLocation(st, stateDec[11].storagelocation, 17, 7)
checkLocation(st, stateDec[12].location, 18, 0) checkLocation(st, stateDec[12].storagelocation, 18, 0)
checkLocation(st, stateDec[13].location, 21, 0) checkLocation(st, stateDec[13].storagelocation, 21, 0)
st.end() st.end()
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment