move & refactor solidity locals logic

pull/1/head
Iuri Matias 6 years ago committed by yann300
parent f8b97d514c
commit 6716d9b593
  1. 67
      src/app/debugger/SolidityLocals.js
  2. 16
      src/app/debugger/debuggerUI/VmDebugger.js
  3. 83
      src/app/debugger/debuggerUI/vmDebugger/SolidityLocals.js

@ -0,0 +1,67 @@
var remixLib = require('remix-lib')
var EventManager = remixLib.EventManager
var remixDebug = require('remix-debug')
var localDecoder = remixDebug.SolidityDecoder.localDecoder
var StorageViewer = remixDebug.storage.StorageViewer
class DebuggerSolidityLocals {
constructor (_parent, _traceManager, _internalTreeCall) {
this.event = new EventManager()
this.parent = _parent
this.internalTreeCall = _internalTreeCall
this.storageResolver = null
this.traceManager = _traceManager
}
init () {
const self = this
var decodeTimeout = null
this.parent.event.register('sourceLocationChanged', this, (sourceLocation) => {
if (!this.storageResolver) {
return self.event.trigger('solidityLocalsMessage', ['storage not ready'])
}
if (decodeTimeout) {
window.clearTimeout(decodeTimeout)
}
self.event.trigger('solidityLocalsUpdating')
decodeTimeout = setTimeout(function () {
self.decode(sourceLocation)
}, 500)
})
}
decode (sourceLocation) {
const self = this
self.event.trigger('solidityLocalsMessage', [''])
self.traceManager.waterfall([
self.traceManager.getStackAt,
self.traceManager.getMemoryAt,
self.traceManager.getCurrentCalledAddressAt],
self.parent.currentStepIndex,
(error, result) => {
if (!error) {
var stack = result[0].value
var memory = result[1].value
try {
var storageViewer = new StorageViewer({ stepIndex: self.parent.currentStepIndex, tx: self.parent.tx, address: result[2].value }, self.storageResolver, self.traceManager)
localDecoder.solidityLocals(self.parent.currentStepIndex, self.internalTreeCall, stack, memory, storageViewer, sourceLocation).then((locals) => {
if (!locals.error) {
self.event.trigger('solidityLocals', [locals])
}
if (!Object.keys(locals).length) {
self.event.trigger('solidityLocalsMessage', ['no locals'])
}
})
} catch (e) {
self.event.trigger('solidityLocalsMessage', [e.message])
}
} else {
console.log(error)
}
})
}
}
module.exports = DebuggerSolidityLocals

@ -9,6 +9,7 @@ var StoragePanel = require('./vmDebugger/StoragePanel')
var StepDetail = require('./vmDebugger/StepDetail')
var DebuggerSolidityState = require('../solidityState')
var DebuggerSolidityLocals = require('../solidityLocals')
var SolidityState = require('./vmDebugger/SolidityState')
var SolidityLocals = require('./vmDebugger/SolidityLocals')
@ -177,7 +178,18 @@ function VmDebugger (_parentUI, _traceManager, _codeManager, _solidityProxy, _ca
self.solidityState.setUpdating()
})
this.solidityLocals = new SolidityLocals(_parentUI, _traceManager, _callTree)
this.debuggerSolidityLocals = new DebuggerSolidityLocals(_parentUI, _traceManager, _callTree)
this.solidityLocals = new SolidityLocals()
this.debuggerSolidityLocals.event.register('solidityLocals', this, function (state) {
self.solidityLocals.update(state)
})
this.debuggerSolidityLocals.event.register('solidityLocalsMessage', this, function (message) {
self.solidityLocals.setMessage(message)
})
this.debuggerSolidityLocals.event.register('solidityLocalsUpdating', this, function () {
self.solidityLocals.setUpdating()
})
this.debuggerSolidityLocals.init()
/* Return values - */
this.returnValuesPanel = new DropdownPanel('Return Value', {json: true})
@ -202,7 +214,7 @@ function VmDebugger (_parentUI, _traceManager, _codeManager, _solidityProxy, _ca
self.storageResolver = new StorageResolver({web3: _parent.web3})
// self.solidityState.storageResolver = self.storageResolver
self.debuggerSolidityState.storageResolver = self.storageResolver
self.solidityLocals.debuggerSolidityLocals.storageResolver = self.storageResolver
self.debuggerSolidityLocals.storageResolver = self.storageResolver
self.fullStoragesChangesPanel.storageResolver = self.storageResolver
self.asmCode.basicPanel.show()
self.stackPanel.basicPanel.show()

@ -2,100 +2,18 @@
var remixLib = require('remix-lib')
var EventManager = remixLib.EventManager
var DropdownPanel = require('./DropdownPanel')
var remixDebug = require('remix-debug')
var localDecoder = remixDebug.SolidityDecoder.localDecoder
var solidityTypeFormatter = require('./utils/SolidityTypeFormatter')
var StorageViewer = remixDebug.storage.StorageViewer
var yo = require('yo-yo')
class DebuggerSolidityLocals {
constructor (_parent, _traceManager, _internalTreeCall) {
this.event = new EventManager()
this.parent = _parent
this.internalTreeCall = _internalTreeCall
this.storageResolver = null
this.traceManager = _traceManager
}
init () {
const self = this
var decodeTimeout = null
this.parent.event.register('sourceLocationChanged', this, (sourceLocation) => {
if (!this.storageResolver) {
return self.event.trigger('solidityLocalsMessage', ['storage not ready'])
}
if (decodeTimeout) {
window.clearTimeout(decodeTimeout)
}
self.event.trigger('solidityLocalsUpdating')
decodeTimeout = setTimeout(function () {
self.decode(sourceLocation)
}, 500)
})
}
decode (sourceLocation) {
const self = this
self.event.trigger('solidityLocalsMessage', [''])
self.traceManager.waterfall([
self.traceManager.getStackAt,
self.traceManager.getMemoryAt,
self.traceManager.getCurrentCalledAddressAt],
self.parent.currentStepIndex,
(error, result) => {
if (!error) {
var stack = result[0].value
var memory = result[1].value
try {
var storageViewer = new StorageViewer({ stepIndex: self.parent.currentStepIndex, tx: self.parent.tx, address: result[2].value }, self.storageResolver, self.traceManager)
localDecoder.solidityLocals(self.parent.currentStepIndex, self.internalTreeCall, stack, memory, storageViewer, sourceLocation).then((locals) => {
if (!locals.error) {
self.event.trigger('solidityLocals', [locals])
}
if (!Object.keys(locals).length) {
self.event.trigger('solidityLocalsMessage', ['no locals'])
}
})
} catch (e) {
self.event.trigger('solidityLocalsMessage', [e.message])
}
} else {
console.log(error)
}
})
}
}
class SolidityLocals {
constructor (_parent, _traceManager, _internalTreeCall) {
const self = this
this.event = new EventManager()
this.basicPanel = new DropdownPanel('Solidity Locals', {
json: true,
formatSelf: solidityTypeFormatter.formatSelf,
extractData: solidityTypeFormatter.extractData
})
this.debuggerSolidityLocals = new DebuggerSolidityLocals(_parent, _traceManager, _internalTreeCall)
this.parent = this.debuggerSolidityLocals.parent
this.internalTreeCall = this.debuggerSolidityLocals.internalTreeCall
this.storageResolver = this.debuggerSolidityLocals.storageResolver
this.traceManager = this.debuggerSolidityLocals.traceManager
this.debuggerSolidityLocals.event.register('solidityLocals', this, function (state) {
self.update(state)
})
this.debuggerSolidityLocals.event.register('solidityLocalsMessage', this, function (message) {
self.setMessage(message)
})
this.debuggerSolidityLocals.event.register('solidityLocalsUpdating', this, function () {
self.setUpdating()
})
this.debuggerSolidityLocals.init()
this.view
}
@ -118,4 +36,3 @@ class SolidityLocals {
}
module.exports = SolidityLocals

Loading…
Cancel
Save