From 311289a0495980c3d0a980512cb6a2ac38b23948 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 12 Jan 2017 13:52:43 +0100 Subject: [PATCH] rename location storagelocation --- src/solidity/decodeInfo.js | 28 +++++++-------- src/solidity/stateDecoder.js | 2 +- src/solidity/types/Struct.js | 4 +-- test/solidity/storageLocation.js | 58 ++++++++++++++++---------------- 4 files changed, 46 insertions(+), 46 deletions(-) diff --git a/src/solidity/decodeInfo.js b/src/solidity/decodeInfo.js index e2c4239d07..77baf45d4f 100644 --- a/src/solidity/decodeInfo.js +++ b/src/solidity/decodeInfo.js @@ -286,7 +286,7 @@ function parseType (type, stateDefinitions, contractName) { */ function computeOffsets (types, stateDefinitions, contractName) { var ret = [] - var location = { + var storagelocation = { offset: 0, slot: 0 } @@ -297,31 +297,31 @@ function computeOffsets (types, stateDefinitions, contractName) { console.log('unable to retrieve decode info of ' + variable.attributes.type) return null } - if (location.offset + type.storageBytes > 32) { - location.slot++ - location.offset = 0 + if (storagelocation.offset + type.storageBytes > 32) { + storagelocation.slot++ + storagelocation.offset = 0 } ret.push({ name: variable.attributes.name, type: type, - location: { - offset: location.offset, - slot: location.slot + storagelocation: { + offset: storagelocation.offset, + slot: storagelocation.slot } }) - if (type.storageSlots === 1 && location.offset + type.storageBytes <= 32) { - location.offset += type.storageBytes + if (type.storageSlots === 1 && storagelocation.offset + type.storageBytes <= 32) { + storagelocation.offset += type.storageBytes } else { - location.slot += type.storageSlots - location.offset = 0 + storagelocation.slot += type.storageSlots + storagelocation.offset = 0 } } - if (location.offset > 0) { - location.slot++ + if (storagelocation.offset > 0) { + storagelocation.slot++ } return { typesOffsets: ret, - endLocation: location + endLocation: storagelocation } } diff --git a/src/solidity/stateDecoder.js b/src/solidity/stateDecoder.js index be77fe6b60..76a22a182f 100644 --- a/src/solidity/stateDecoder.js +++ b/src/solidity/stateDecoder.js @@ -12,7 +12,7 @@ function decodeState (stateVars, storageContent) { var ret = {} for (var k in stateVars) { var stateVar = stateVars[k] - ret[stateVar.name] = stateVar.type.decodeFromStorage(stateVar.location, storageContent) + ret[stateVar.name] = stateVar.type.decodeFromStorage(stateVar.storagelocation, storageContent) } return ret } diff --git a/src/solidity/types/Struct.js b/src/solidity/types/Struct.js index c0804d6123..a8fc14428d 100644 --- a/src/solidity/types/Struct.js +++ b/src/solidity/types/Struct.js @@ -12,8 +12,8 @@ class Struct extends RefType { var ret = {} this.members.map(function (item, i) { var globalLocation = { - offset: location.offset + item.location.offset, - slot: util.add(location.slot, item.location.slot) + offset: location.offset + item.storagelocation.offset, + slot: util.add(location.slot, item.storagelocation.slot) } ret[item.name] = item.type.decodeFromStorage(globalLocation, storageContent) }) diff --git a/test/solidity/storageLocation.js b/test/solidity/storageLocation.js index 19d0d41695..8385ebe82b 100644 --- a/test/solidity/storageLocation.js +++ b/test/solidity/storageLocation.js @@ -8,43 +8,43 @@ tape('solidity', function (t) { t.test('storage location', function (st) { var output = compiler.compile(contracts, 0) var stateDec = index.solidity.stateDecoder.extractStateVariables('contractUint', output.sources) - checkLocation(st, stateDec[0].location, 0, 0) - checkLocation(st, stateDec[1].location, 1, 0) - checkLocation(st, stateDec[2].location, 2, 0) - checkLocation(st, stateDec[3].location, 3, 0) + checkLocation(st, stateDec[0].storagelocation, 0, 0) + checkLocation(st, stateDec[1].storagelocation, 1, 0) + checkLocation(st, stateDec[2].storagelocation, 2, 0) + checkLocation(st, stateDec[3].storagelocation, 3, 0) stateDec = index.solidity.stateDecoder.extractStateVariables('contractStructAndArray', output.sources) - checkLocation(st, stateDec[0].location, 0, 0) - checkLocation(st, stateDec[1].location, 2, 0) - checkLocation(st, stateDec[2].location, 8, 0) + checkLocation(st, stateDec[0].storagelocation, 0, 0) + checkLocation(st, stateDec[1].storagelocation, 2, 0) + checkLocation(st, stateDec[2].storagelocation, 8, 0) stateDec = index.solidity.stateDecoder.extractStateVariables('contractArray', output.sources) - checkLocation(st, stateDec[0].location, 0, 0) - checkLocation(st, stateDec[1].location, 1, 0) - checkLocation(st, stateDec[2].location, 2, 0) + checkLocation(st, stateDec[0].storagelocation, 0, 0) + checkLocation(st, stateDec[1].storagelocation, 1, 0) + checkLocation(st, stateDec[2].storagelocation, 2, 0) stateDec = index.solidity.stateDecoder.extractStateVariables('contractSmallVariable', output.sources) - checkLocation(st, stateDec[0].location, 0, 0) - checkLocation(st, stateDec[1].location, 0, 1) - checkLocation(st, stateDec[2].location, 0, 2) - checkLocation(st, stateDec[3].location, 0, 4) - checkLocation(st, stateDec[4].location, 1, 0) - checkLocation(st, stateDec[5].location, 2, 0) + checkLocation(st, stateDec[0].storagelocation, 0, 0) + checkLocation(st, stateDec[1].storagelocation, 0, 1) + checkLocation(st, stateDec[2].storagelocation, 0, 2) + checkLocation(st, stateDec[3].storagelocation, 0, 4) + checkLocation(st, stateDec[4].storagelocation, 1, 0) + checkLocation(st, stateDec[5].storagelocation, 2, 0) stateDec = index.solidity.stateDecoder.extractStateVariables('testSimpleStorage', output.sources) - checkLocation(st, stateDec[0].location, 0, 0) - checkLocation(st, stateDec[1].location, 1, 0) - checkLocation(st, stateDec[2].location, 2, 0) - checkLocation(st, stateDec[3].location, 3, 0) - checkLocation(st, stateDec[4].location, 4, 0) - checkLocation(st, stateDec[5].location, 8, 0) - checkLocation(st, stateDec[6].location, 9, 0) - checkLocation(st, stateDec[8].location, 17, 0) - checkLocation(st, stateDec[9].location, 17, 4) - checkLocation(st, stateDec[10].location, 17, 6) - checkLocation(st, stateDec[11].location, 17, 7) - checkLocation(st, stateDec[12].location, 18, 0) - checkLocation(st, stateDec[13].location, 21, 0) + checkLocation(st, stateDec[0].storagelocation, 0, 0) + checkLocation(st, stateDec[1].storagelocation, 1, 0) + checkLocation(st, stateDec[2].storagelocation, 2, 0) + checkLocation(st, stateDec[3].storagelocation, 3, 0) + checkLocation(st, stateDec[4].storagelocation, 4, 0) + checkLocation(st, stateDec[5].storagelocation, 8, 0) + checkLocation(st, stateDec[6].storagelocation, 9, 0) + checkLocation(st, stateDec[8].storagelocation, 17, 0) + checkLocation(st, stateDec[9].storagelocation, 17, 4) + checkLocation(st, stateDec[10].storagelocation, 17, 6) + checkLocation(st, stateDec[11].storagelocation, 17, 7) + checkLocation(st, stateDec[12].storagelocation, 18, 0) + checkLocation(st, stateDec[13].storagelocation, 21, 0) st.end() })