move accumulateStorageChanges && address to StorageViewer

pull/7/head
yann300 8 years ago
parent c5b4fc96c5
commit 36fa9cb5ae
  1. 73
      src/storage/storageResolver.js
  2. 29
      src/storage/storageViewer.js
  3. 5
      src/ui/FullStoragesChanges.js
  4. 10
      src/ui/SolidityLocals.js
  5. 7
      src/ui/SolidityState.js
  6. 23
      src/ui/StoragePanel.js
  7. 2
      src/ui/VmDebugger.js

@ -3,8 +3,7 @@ var traceHelper = require('../helpers/traceHelper')
var util = require('../helpers/global') var util = require('../helpers/global')
class StorageResolver { class StorageResolver {
constructor (_traceManager) { constructor () {
this.traceManager = _traceManager
this.storageByAddress = {} this.storageByAddress = {}
this.maxSize = 100 this.maxSize = 100
} }
@ -15,10 +14,12 @@ class StorageResolver {
* *
* @param {Object} - tx - transaction * @param {Object} - tx - transaction
* @param {Int} - stepIndex - Index of the stop in the vm trace * @param {Int} - stepIndex - Index of the stop in the vm trace
* @param {Object} - storageChanges - contains storage changes by hashde key
* @param {String} - address - lookup address
* @param {Function} - callback - contains a map: [hashedKey] = {key, hashedKey, value} * @param {Function} - callback - contains a map: [hashedKey] = {key, hashedKey, value}
*/ */
storageRange (tx, stepIndex, callback) { storageRange (tx, stepIndex, storageChanges, address, callback) {
storageRangeInternal(this, zeroSlot, tx, stepIndex, true, callback) storageRangeInternal(this, zeroSlot, tx, stepIndex, true, storageChanges, address, callback)
} }
/** /**
@ -27,10 +28,12 @@ class StorageResolver {
* @param {String} - slot - slot key * @param {String} - slot - slot key
* @param {Object} - tx - transaction * @param {Object} - tx - transaction
* @param {Int} - stepIndex - Index of the stop in the vm trace * @param {Int} - stepIndex - Index of the stop in the vm trace
* @param {Object} - storageChanges - contains storage changes by hashde key
* @param {String} - address - lookup address
* @param {Function} - callback - {key, hashedKey, value} - * @param {Function} - callback - {key, hashedKey, value} -
*/ */
storageSlot (slot, tx, stepIndex, callback) { storageSlot (slot, tx, stepIndex, storageChanges, address, callback) {
storageRangeInternal(this, slot, tx, stepIndex, false, function (error, storage) { storageRangeInternal(this, slot, tx, stepIndex, false, storageChanges, address, function (error, storage) {
if (error) { if (error) {
callback(error) callback(error)
} else { } else {
@ -56,39 +59,29 @@ class StorageResolver {
* even if the next 1000 items are not in the cache. * even if the next 1000 items are not in the cache.
* - If @arg slot is not cached, the corresponding value will be resolved and the next 1000 slots. * - If @arg slot is not cached, the corresponding value will be resolved and the next 1000 slots.
*/ */
function storageRangeInternal (self, slotKey, tx, stepIndex, fullStorage, callback) { function storageRangeInternal (self, slotKey, tx, stepIndex, fullStorage, storageChanges, address, callback) {
resolveAddress(self, stepIndex, (error, address) => { if (!fullStorage && storageChanges[slotKey]) { // don't need the full storage just returning the value from the storageChanges
return callback(null, storageChanges)
}
var cached = fromCache(self, address)
if (cached && cached.storage[slotKey]) { // we have the current slot in the cache and maybe the next 1000...
return callback(null, Object.assign({}, cached.storage, storageChanges))
}
storageRangeWeb3Call(tx, address, slotKey, self.maxSize, (error, storage, complete) => {
if (error) { if (error) {
return callback(error) return callback(error)
} }
self.traceManager.accumulateStorageChanges(stepIndex, address, {}, (error, storageChanges) => { if (!storage[slotKey]) {
if (error) { storage[slotKey] = {
return callback(error) key: slotKey,
} value: zeroSlot
if (!fullStorage && storageChanges[slotKey]) { // don't need the full storage just returning the value from the storageChanges
return callback(null, storageChanges)
}
var cached = fromCache(self, address)
if (cached && cached.storage[slotKey]) { // we have the current slot in the cache and maybe the next 1000...
return callback(null, Object.assign(cached.storage, storageChanges))
} }
storageRangeWeb3Call(tx, address, slotKey, self.maxSize, (error, storage, complete) => { }
if (error) { toCache(self, address, storage)
return callback(error) if (slotKey === zeroSlot && Object.keys(storage).length < self.maxSize) {
} self.storageByAddress[address].complete = true
if (!storage[slotKey]) { }
storage[slotKey] = { callback(null, Object.assign(storage, storageChanges))
key: slotKey,
value: zeroSlot
}
}
toCache(self, address, storage)
if (slotKey === zeroSlot && Object.keys(storage).length < self.maxSize) {
self.storageByAddress[address].complete = true
}
callback(null, Object.assign(storage, storageChanges))
})
})
}) })
} }
@ -141,14 +134,4 @@ function storageRangeWeb3Call (tx, address, start, maxSize, callback) {
} }
} }
function resolveAddress (self, stepIndex, callback) {
self.traceManager.getCurrentCalledAddressAt(stepIndex, (error, result) => {
if (error) {
callback(error)
} else {
callback(null, result)
}
})
}
module.exports = StorageResolver module.exports = StorageResolver

@ -2,9 +2,16 @@
var helper = require('../helpers/util') var helper = require('../helpers/util')
class StorageViewer { class StorageViewer {
constructor (_context, _storageResolver) { constructor (_context, _storageResolver, _traceManager) {
this.context = _context this.context = _context
this.storageResolver = _storageResolver this.storageResolver = _storageResolver
_traceManager.accumulateStorageChanges(this.context.stepIndex, this.context.address, {}, (error, storageChanges) => {
if (!error) {
this.storageChanges = storageChanges
} else {
console.log(error)
}
})
} }
/** /**
@ -14,27 +21,21 @@ class StorageViewer {
* @param {Function} - callback - contains a map: [hashedKey] = {key, hashedKey, value} * @param {Function} - callback - contains a map: [hashedKey] = {key, hashedKey, value}
*/ */
storageRange (callback) { storageRange (callback) {
this.storageResolver.storageRange(this.context.tx, this.context.stepIndex, callback) this.storageResolver.storageRange(this.context.tx, this.context.stepIndex, this.storageChanges, this.context.address, callback)
} }
/** /**
* return a slot value for the current context (address and vm trace index) * return a slot value for the current context (address and vm trace index)
* * @param {String} - slot - slot key (not hashed key!)
* @param {Function} - callback - {key, hashedKey, value} - * @param {Function} - callback - {key, hashedKey, value} -
*/ */
storageSlot (slot, callback) { storageSlot (slot, callback) {
this.storageResolver.storageSlot(slot, this.context.tx, this.context.stepIndex, (error, result) => { var hashed = helper.sha3_32(slot)
if (error || !result || !result[slot]) { this.storageResolver.storageSlot(hashed, this.context.tx, this.context.stepIndex, this.storageChanges, this.context.address, (error, result) => {
var hashed = helper.sha3_32(slot) if (error) {
this.storageResolver.storageSlot(hashed, this.context.tx, this.context.stepIndex, (error, result) => { callback(error)
if (error) {
callback(error)
} else {
callback(null, result)
}
})
} else { } else {
return callback(null, result) callback(null, result)
} }
}) })
} }

@ -51,8 +51,9 @@ FullStoragesChanges.prototype.init = function () {
var address = self.addresses[k] var address = self.addresses[k]
var storageViewer = new StorageViewer({ var storageViewer = new StorageViewer({
stepIndex: self.parent.currentStepIndex, stepIndex: self.parent.currentStepIndex,
tx: self.parent.tx tx: self.parent.tx,
}, self.storageResolver) address: address
}, self.storageResolver, self.traceManager)
storageViewer.storageRange(function (error, result) { storageViewer.storageRange(function (error, result) {
if (!error) { if (!error) {
storageJSON[address] = result storageJSON[address] = result

@ -39,7 +39,8 @@ class SolidityLocals {
} }
this.traceManager.waterfall([ this.traceManager.waterfall([
this.traceManager.getStackAt, this.traceManager.getStackAt,
this.traceManager.getMemoryAt], this.traceManager.getMemoryAt,
this.traceManager.getCurrentCalledAddressAt],
this.parent.currentStepIndex, this.parent.currentStepIndex,
(error, result) => { (error, result) => {
if (!error) { if (!error) {
@ -48,8 +49,9 @@ class SolidityLocals {
try { try {
var storageViewer = new StorageViewer({ var storageViewer = new StorageViewer({
stepIndex: this.parent.currentStepIndex, stepIndex: this.parent.currentStepIndex,
tx: this.parent.tx tx: this.parent.tx,
}, this.storageResolver) address: result[2].value
}, this.storageResolver, this.traceManager)
localDecoder.solidityLocals(this.parent.currentStepIndex, this.internalTreeCall, stack, memory, storageViewer, sourceLocation).then((locals) => { localDecoder.solidityLocals(this.parent.currentStepIndex, this.internalTreeCall, stack, memory, storageViewer, sourceLocation).then((locals) => {
if (!result.error) { if (!result.error) {
this.basicPanel.update(locals) this.basicPanel.update(locals)
@ -58,6 +60,8 @@ class SolidityLocals {
} catch (e) { } catch (e) {
warningDiv.innerHTML = e.message warningDiv.innerHTML = e.message
} }
} else {
console.log(error)
} }
}) })
}) })

@ -49,7 +49,7 @@ SolidityState.prototype.init = function () {
return return
} }
self.traceManager.getCurrentCalledAddressAt(self.parent.currentStepIndex, (error, result) => { self.traceManager.getCurrentCalledAddressAt(self.parent.currentStepIndex, (error, address) => {
if (error) { if (error) {
self.basicPanel.update({}) self.basicPanel.update({})
console.log(error) console.log(error)
@ -61,8 +61,9 @@ SolidityState.prototype.init = function () {
} else { } else {
var storageViewer = new StorageViewer({ var storageViewer = new StorageViewer({
stepIndex: self.parent.currentStepIndex, stepIndex: self.parent.currentStepIndex,
tx: self.parent.tx tx: self.parent.tx,
}, self.storageResolver) address: address
}, self.storageResolver, self.traceManager)
stateDecoder.decodeState(stateVars, storageViewer).then((result) => { stateDecoder.decodeState(stateVars, storageViewer).then((result) => {
if (!result.error) { if (!result.error) {
self.basicPanel.update(result) self.basicPanel.update(result)

@ -24,18 +24,19 @@ StoragePanel.prototype.init = function () {
if (self.parent.currentStepIndex !== index) return if (self.parent.currentStepIndex !== index) return
if (!self.storageResolver) return if (!self.storageResolver) return
var storageViewer = new StorageViewer({ this.traceManager.getCurrentCalledAddressAt(index, (error, address) => {
stepIndex: self.parent.currentStepIndex, if (!error) {
tx: self.parent.tx var storageViewer = new StorageViewer({
}, self.storageResolver) stepIndex: self.parent.currentStepIndex,
tx: self.parent.tx,
address: address
}, self.storageResolver, self.traceManager)
storageViewer.storageRange((error, storage) => { storageViewer.storageRange((error, storage) => {
if (error) { if (error) {
console.log(error) console.log(error)
self.basicPanel.update({}) self.basicPanel.update({})
} else if (self.parent.currentStepIndex === index) { } else if (self.parent.currentStepIndex === index) {
this.traceManager.getCurrentCalledAddressAt(index, (error, address) => {
if (!error) {
var header = storageViewer.isComplete(address) ? 'completely loaded' : 'partially loaded...' var header = storageViewer.isComplete(address) ? 'completely loaded' : 'partially loaded...'
self.basicPanel.update(storage, header) self.basicPanel.update(storage, header)
} }

@ -44,7 +44,7 @@ function VmDebugger (_parent, _traceManager, _codeManager, _solidityProxy, _call
this.view this.view
var self = this var self = this
_parent.event.register('newTraceLoaded', this, function () { _parent.event.register('newTraceLoaded', this, function () {
var storageResolver = new StorageResolver(_traceManager) var storageResolver = new StorageResolver()
self.storagePanel.storageResolver = storageResolver self.storagePanel.storageResolver = storageResolver
self.solidityState.storageResolver = storageResolver self.solidityState.storageResolver = storageResolver
self.solidityLocals.storageResolver = storageResolver self.solidityLocals.storageResolver = storageResolver

Loading…
Cancel
Save