initial support for mapping types#498
Conversation
|
cool!! |
|
@yann300 btw feel free to review and intervene early. Particularly in src/ui/SolidityState.js and the call to storageViewer.storageRange, that will probably get refactored to support getting preimages using debug_preimage (see ethereum/go-ethereum#3543 and ethereum/go-ethereum#3407). |
5a26444 to
ca9a5d2
Compare
| * @return {Array} containing all members of the current struct type | ||
| */ | ||
| function getStructMembers (type, stateDefinitions, contractName) { | ||
| function getStructMembers (type, stateDefinitions, contractName, location) { |
There was a problem hiding this comment.
the location argument is never used in the getStructMembers function because to get the members only the struct definition is used (not the stateVar declaration, which does have a storage slot location).
| value = value.replace('0x', '').replace(/(..)/g, '%$1') | ||
| var ret = { | ||
| // length: decoded.length, // unneeded, only dynamicBytes uses length | ||
| length: decoded.length, |
There was a problem hiding this comment.
I can't remember why i was convinced that the length here is never used, but it doesn't matter.
|
yeah the length here is not really relevant. but removing this breaks tests |
| * @param {String} location - location of the data (storage ref| storage pointer| memory| calldata) | ||
| * @return {Array} containing all members of the current struct type | ||
| */ | ||
| function getStructMembers (type, stateDefinitions, contractName, location) { |
There was a problem hiding this comment.
Please add a test for the following type: struct X { uint a; mapping(uint=>uint) b; uint c; }
If such a struct is used in memory, it should be identical to struct X { uint a; uint c; }.
There was a problem hiding this comment.
| type: this.type | ||
| } | ||
| } | ||
| var mapSlot = util.toBN(location.slot).toString(16) |
| @@ -0,0 +1,58 @@ | |||
| var global = require('../helpers/global') | |||
There was a problem hiding this comment.
Please document all functions here.
| this.context = _context | ||
| this.storageResolver = _storageResolver | ||
| // contains [mappingSlot][mappingkey] = preimage | ||
| // this map is renewed for each execution step |
There was a problem hiding this comment.
Should only do it once at the beginning of the debugging session and use the trace otherwise.
| function pushSha3Preimage (self, sha3Input) { | ||
| var preimage = sha3Input | ||
| var imageHash = ethutil.sha3('0x' + sha3Input).toString('hex') | ||
| self.sha3Preimages[imageHash] = { |
There was a problem hiding this comment.
Using self in that way here looks a bit weird. What about moving the code to the point where this function is called?
| memoryStart = parseInt(memStartDec) * 2 | ||
| var memLengthDec = (new ethutil.BN(memoryLength.replace('0x', ''), 16).toString(10)) | ||
| memoryLength = parseInt(memLengthDec) * 2 | ||
| var memoryHex = memory.join('') |
There was a problem hiding this comment.
Please avoid this (high complexity).
- add we3.debug.preimage - move mapping resolver from soliditystate to storageViewer
| var subMemoryIndex = Math.floor(memoryStart / 32) | ||
| var sha3Input = '' | ||
| while (sha3Input.length < memoryLength) { | ||
| sha3Input += memory[subMemoryIndex] |
There was a problem hiding this comment.
Ah, I think I misunderstood your question earlier. Unfortunately this won't work. Types in memory most of the time have a length of 32 bytes but
- they might be offset by some amount
- this does not apply to sha3
| * | ||
| * @param {Function} callback | ||
| */ | ||
| async mappingsLocation () { |
Work in progress, don't merge.