From 6e1ed8ffd897684fef3d3d12d0aa6c3e0d3cf749 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 11 Sep 2018 11:09:15 -0400 Subject: [PATCH] create file for solidity state logic --- src/app/debugger/debuggerUI/VmDebugger.js | 20 +++- .../debuggerUI/vmDebugger/SolidityState.js | 108 +----------------- src/app/debugger/solidityState.js | 81 +++++++++++++ 3 files changed, 98 insertions(+), 111 deletions(-) create mode 100644 src/app/debugger/solidityState.js diff --git a/src/app/debugger/debuggerUI/VmDebugger.js b/src/app/debugger/debuggerUI/VmDebugger.js index 0eb82b5a5d..a24b0f0e3b 100644 --- a/src/app/debugger/debuggerUI/VmDebugger.js +++ b/src/app/debugger/debuggerUI/VmDebugger.js @@ -7,7 +7,10 @@ var CallstackPanel = require('./vmDebugger/CallstackPanel') var StackPanel = require('./vmDebugger/StackPanel') var StoragePanel = require('./vmDebugger/StoragePanel') var StepDetail = require('./vmDebugger/StepDetail') + +var DebuggerSolidityState = require('../solidityState') var SolidityState = require('./vmDebugger/SolidityState') + var SolidityLocals = require('../remix-debugger/src/ui/SolidityLocals') var FullStoragesChangesPanel = require('../remix-debugger/src/ui/FullStoragesChanges') var DropdownPanel = require('../remix-debugger/src/ui/DropdownPanel') @@ -161,10 +164,19 @@ function VmDebugger (_parentUI, _traceManager, _codeManager, _solidityProxy, _ca }) }) - console.dir('solidity proxy is') - console.dir(_solidityProxy) + this.debuggerSolidityState = new DebuggerSolidityState(_parentUI, _traceManager, _codeManager, _solidityProxy) + this.solidityState = new SolidityState() + this.debuggerSolidityState.init() + this.debuggerSolidityState.event.register('solidityState', this, function (state) { + self.solidityState.update(state) + }) + this.debuggerSolidityState.event.register('solidityStateMessage', this, function (message) { + self.solidityState.setMessage(message) + }) + this.debuggerSolidityState.event.register('solidityStateUpdating', this, function () { + self.solidityState.setUpdating() + }) - this.solidityState = new SolidityState(_parentUI, _traceManager, _codeManager, _solidityProxy) this.solidityLocals = new SolidityLocals(_parentUI, _traceManager, _callTree) /* Return values - */ @@ -189,7 +201,7 @@ function VmDebugger (_parentUI, _traceManager, _codeManager, _solidityProxy, _ca if (!self.view) return self.storageResolver = new StorageResolver({web3: _parent.web3}) // self.solidityState.storageResolver = self.storageResolver - self.solidityState.debuggerSolidityState.storageResolver = self.storageResolver + self.debuggerSolidityState.storageResolver = self.storageResolver self.solidityLocals.storageResolver = self.storageResolver self.fullStoragesChangesPanel.storageResolver = self.storageResolver self.asmCode.basicPanel.show() diff --git a/src/app/debugger/debuggerUI/vmDebugger/SolidityState.js b/src/app/debugger/debuggerUI/vmDebugger/SolidityState.js index dcaf36ef48..7fb8455571 100644 --- a/src/app/debugger/debuggerUI/vmDebugger/SolidityState.js +++ b/src/app/debugger/debuggerUI/vmDebugger/SolidityState.js @@ -1,120 +1,14 @@ var DropdownPanel = require('./DropdownPanel') -var remixDebug = require('remix-debug') -var stateDecoder = remixDebug.SolidityDecoder.stateDecoder var solidityTypeFormatter = require('./utils/SolidityTypeFormatter') -var StorageViewer = remixDebug.storage.StorageViewer var yo = require('yo-yo') -var remixLib = require('remix-lib') -var EventManager = remixLib.EventManager -class DebuggerSolidityState { - - constructor (_parent, _traceManager, _codeManager, _solidityProxy) { - this.event = new EventManager() - this.storageResolver = null - this.parent = _parent - this.traceManager = _traceManager - this.codeManager = _codeManager - this.solidityProxy = _solidityProxy - this.stateVariablesByAddresses = {} - _parent.event.register('traceUnloaded', () => { this.stateVariablesByAddresses = {} }) - _parent.event.register('newTraceLoaded', () => { this.stateVariablesByAddresses = {} }) - } - - init () { - var self = this - var decodeTimeout = null - this.parent.event.register('indexChanged', this, function (index) { - if (index < 0) { - self.setMessage('invalid step index') - return - } - - if (self.parent.currentStepIndex !== index) return - if (!self.solidityProxy.loaded()) { - // return self.setMessage('no source has been specified') - return self.event.trigger('solidityStateMessage', ['invalid step index']) - } - - if (!self.storageResolver) { - return - } - if (decodeTimeout) { - window.clearTimeout(decodeTimeout) - } - // self.setUpdating() - self.event.trigger('solidityStateUpdating') - decodeTimeout = setTimeout(function () { - //self.decode.apply(self, index) - self.decode(index) - }, 500) - }) - } - - decode (index) { - const self = this - self.traceManager.getCurrentCalledAddressAt(self.parent.currentStepIndex, function (error, address) { - if (error) { - // return self.update({}) - return self.event.trigger('solidityState', [{}]) - } - if (self.stateVariablesByAddresses[address]) { - return self.extractStateVariables(self.stateVariablesByAddresses[address], address) - } - self.solidityProxy.extractStateVariablesAt(index, function (error, stateVars) { - if (error) { - // return self.update({}) - return self.event.trigger('solidityState', [{}]) - } - self.stateVariablesByAddresses[address] = stateVars - self.extractStateVariables(stateVars, address) - }) - }) - } - - extractStateVariables (stateVars, address) { - const self = this - var storageViewer = new StorageViewer({ stepIndex: self.parent.currentStepIndex, tx: self.parent.tx, address: address }, self.storageResolver, self.traceManager) - stateDecoder.decodeState(stateVars, storageViewer).then((result) => { - // self.setMessage('') - self.event.trigger('solidityStateMessage', ['']) - if (result.error) { - // return self.setMessage(result.error) - return self.event.trigger('solidityStateMessage', [result.error]) - } - // self.update(result) - self.event.trigger('solidityState', [result]) - }) - } - -} - -function SolidityState (_parent, _traceManager, _codeManager, _solidityProxy) { - const self = this +function SolidityState () { this.basicPanel = new DropdownPanel('Solidity State', { json: true, // TODO: used by TreeView ui formatSelf: solidityTypeFormatter.formatSelf, extractData: solidityTypeFormatter.extractData }) - - this.debuggerSolidityState = new DebuggerSolidityState(_parent, _traceManager, _codeManager, _solidityProxy) - this.debuggerSolidityState.init() - this.debuggerSolidityState.event.register('solidityState', this, function (state) { - self.update(state) - }) - this.debuggerSolidityState.event.register('solidityStateMessage', this, function (message) { - self.setMessage(message) - }) - this.debuggerSolidityState.event.register('solidityStateUpdating', this, function () { - self.setUpdating() - }) - this.storageResolver = this.debuggerSolidityState.storageResolver - this.parent = this.debuggerSolidityState.parent - this.traceManager = this.debuggerSolidityState.traceManager - this.codeManager = this.debuggerSolidityState.codeManager - this.solidityProxy = this.debuggerSolidityState.solidityProxy - this.view } diff --git a/src/app/debugger/solidityState.js b/src/app/debugger/solidityState.js new file mode 100644 index 0000000000..921fd277be --- /dev/null +++ b/src/app/debugger/solidityState.js @@ -0,0 +1,81 @@ +var remixLib = require('remix-lib') +var EventManager = remixLib.EventManager +var remixDebug = require('remix-debug') +var stateDecoder = remixDebug.SolidityDecoder.stateDecoder +var StorageViewer = remixDebug.storage.StorageViewer + +class DebuggerSolidityState { + + constructor (_parent, _traceManager, _codeManager, _solidityProxy) { + this.event = new EventManager() + this.storageResolver = null + this.parent = _parent + this.traceManager = _traceManager + this.codeManager = _codeManager + this.solidityProxy = _solidityProxy + this.stateVariablesByAddresses = {} + _parent.event.register('traceUnloaded', () => { this.stateVariablesByAddresses = {} }) + _parent.event.register('newTraceLoaded', () => { this.stateVariablesByAddresses = {} }) + } + + init () { + var self = this + var decodeTimeout = null + this.parent.event.register('indexChanged', this, function (index) { + if (index < 0) { + self.setMessage('invalid step index') + return + } + + if (self.parent.currentStepIndex !== index) return + if (!self.solidityProxy.loaded()) { + return self.event.trigger('solidityStateMessage', ['invalid step index']) + } + + if (!self.storageResolver) { + return + } + if (decodeTimeout) { + window.clearTimeout(decodeTimeout) + } + self.event.trigger('solidityStateUpdating') + decodeTimeout = setTimeout(function () { + self.decode(index) + }, 500) + }) + } + + decode (index) { + const self = this + self.traceManager.getCurrentCalledAddressAt(self.parent.currentStepIndex, function (error, address) { + if (error) { + return self.event.trigger('solidityState', [{}]) + } + if (self.stateVariablesByAddresses[address]) { + return self.extractStateVariables(self.stateVariablesByAddresses[address], address) + } + self.solidityProxy.extractStateVariablesAt(index, function (error, stateVars) { + if (error) { + return self.event.trigger('solidityState', [{}]) + } + self.stateVariablesByAddresses[address] = stateVars + self.extractStateVariables(stateVars, address) + }) + }) + } + + extractStateVariables (stateVars, address) { + const self = this + var storageViewer = new StorageViewer({ stepIndex: self.parent.currentStepIndex, tx: self.parent.tx, address: address }, self.storageResolver, self.traceManager) + stateDecoder.decodeState(stateVars, storageViewer).then((result) => { + self.event.trigger('solidityStateMessage', ['']) + if (result.error) { + return self.event.trigger('solidityStateMessage', [result.error]) + } + self.event.trigger('solidityState', [result]) + }) + } + +} + +module.exports = DebuggerSolidityState