From 5b72f3bb3f4adf17de85e68fa9f171d7973b8250 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 18 Sep 2018 11:55:53 -0400 Subject: [PATCH] refactor to use events --- src/app/debugger/debuggerUI/VmDebugger.js | 3 +- .../debuggerUI/vmDebugger/SolidityLocals.js | 111 +++++++++++------- 2 files changed, 72 insertions(+), 42 deletions(-) diff --git a/src/app/debugger/debuggerUI/VmDebugger.js b/src/app/debugger/debuggerUI/VmDebugger.js index 7dd5f1ca21..cd33f541b3 100644 --- a/src/app/debugger/debuggerUI/VmDebugger.js +++ b/src/app/debugger/debuggerUI/VmDebugger.js @@ -10,9 +10,8 @@ var StepDetail = require('./vmDebugger/StepDetail') var DebuggerSolidityState = require('../solidityState') var SolidityState = require('./vmDebugger/SolidityState') - -// var SolidityLocals = require('../remix-debugger/src/ui/SolidityLocals') var SolidityLocals = require('./vmDebugger/SolidityLocals') + var FullStoragesChangesPanel = require('../remix-debugger/src/ui/FullStoragesChanges') var DropdownPanel = require('./vmDebugger/DropdownPanel') var remixDebug = require('remix-debug') diff --git a/src/app/debugger/debuggerUI/vmDebugger/SolidityLocals.js b/src/app/debugger/debuggerUI/vmDebugger/SolidityLocals.js index a7d4030d65..09754fb860 100644 --- a/src/app/debugger/debuggerUI/vmDebugger/SolidityLocals.js +++ b/src/app/debugger/debuggerUI/vmDebugger/SolidityLocals.js @@ -1,4 +1,6 @@ 'use strict' +var remixLib = require('remix-lib') +var EventManager = remixLib.EventManager var DropdownPanel = require('./DropdownPanel') var remixDebug = require('remix-debug') var localDecoder = remixDebug.SolidityDecoder.localDecoder @@ -6,9 +8,19 @@ var solidityTypeFormatter = require('./utils/SolidityTypeFormatter') var StorageViewer = remixDebug.storage.StorageViewer var yo = require('yo-yo') +// class DebuggerSolidityLocals { +// +// constructor (_parent, _traceManager, _internalTreeCall) { +// +// } +// +// } + class SolidityLocals { constructor (_parent, _traceManager, _internalTreeCall) { + const self = this + this.event = new EventManager() this.parent = _parent this.internalTreeCall = _internalTreeCall this.storageResolver = null @@ -19,66 +31,85 @@ class SolidityLocals { extractData: solidityTypeFormatter.extractData }) this.init() + + this.event.register('solidityLocals', this, function (state) { + self.update(state) + }) + this.event.register('solidityLocalsMessage', this, function (message) { + self.setMessage(message) + }) + this.event.register('solidityLocalsUpdating', this, function () { + self.setUpdating() + }) + this.view } + update (data) { + this.basicPanel.update(data) + } + + setMessage (message) { + this.basicPanel.setMessage(message) + } + + setUpdating () { + this.basicPanel.setUpdating() + } + render () { - this.view = yo`
- ${this.basicPanel.render()} -
` + this.view = yo`
${this.basicPanel.render()}
` return this.view } init () { + const self = this var decodeTimeout = null this.parent.event.register('sourceLocationChanged', this, (sourceLocation) => { if (!this.storageResolver) { - this.basicPanel.setMessage('storage not ready') - return + return self.event.trigger('solidityLocalsMessage', ['storage not ready']) } if (decodeTimeout) { window.clearTimeout(decodeTimeout) } - this.basicPanel.setUpdating() - decodeTimeout = setTimeout(() => { - decode(this, sourceLocation) + self.event.trigger('solidityLocalsUpdating') + decodeTimeout = setTimeout(function () { + self.decode(sourceLocation) }, 500) }) } -} -function decode (self, sourceLocation) { - self.basicPanel.setMessage('') - 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.basicPanel.update(locals) - } - if (!Object.keys(locals).length) { - self.basicPanel.setMessage('no locals') - } - }) - } catch (e) { - self.basicPanel.setMessage(e.message) + 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) } - } else { - console.log(error) - } - }) + }) + } } + module.exports = SolidityLocals