diff --git a/src/code/codeManager.js b/src/code/codeManager.js index cbd45a5a8a..88371ed4a4 100644 --- a/src/code/codeManager.js +++ b/src/code/codeManager.js @@ -17,7 +17,6 @@ function CodeManager (_traceManager) { util.extend(this, new EventManager()) this.isLoading = false this.traceManager = _traceManager - this.currentAddress = '' this.codeResolver = codeResolver } @@ -26,65 +25,54 @@ CodeManager.prototype.resolveStep = function (stepIndex, tx) { this.trigger('resolvingStep') var self = this if (stepIndex === 0) { - self.ensureCodeLoaded(tx.to, stepIndex, tx) + self.getCode(tx.to, stepIndex, tx) } else { this.traceManager.getCurrentCalledAddressAt(stepIndex, function (error, address) { if (error) { console.log(error) } else { - self.ensureCodeLoaded(address, stepIndex, tx) + self.getCode(address, stepIndex, tx) } }) } } -CodeManager.prototype.ensureCodeLoaded = function (address, currentStep, tx) { +CodeManager.prototype.getCode = function (address, currentStep, tx) { var self = this - if (address !== this.currentAddress) { - if (traceHelper.isContractCreation(address)) { + if (traceHelper.isContractCreation(address)) { + var codes = codeResolver.getExecutingCodeFromCache(address) + if (!codes) { this.traceManager.getContractCreationCode(address, function (error, hexCode) { // contract creation if (error) { console.log(error) } else { - var codes = codeResolver.cacheExecutingCode(address, hexCode) - self.trigger('loadingCode', [address]) - self.getInstructionIndex(address, currentStep, function (error, result) { - if (!error) { - self.trigger('codeChanged', [codes.code, address, result]) - self.trigger('indexChanged', [result]) - self.currentAddress = address - } else { - console.log(error) - } - }) + codes = codeResolver.cacheExecutingCode(address, hexCode) + self.retrieveIndexAndTrigger(address, currentStep, codes.code) } }) } else { - codeResolver.resolveCode(address, currentStep, tx, function (address, code) { - // resoling code from stack - self.trigger('loadingCode', [address]) - self.getInstructionIndex(address, currentStep, function (error, result) { - if (!error) { - self.trigger('codeChanged', [code, address, result]) - self.trigger('indexChanged', [result]) - self.currentAddress = address - } else { - console.log(error) - } - }) - }) + self.retrieveIndexAndTrigger(address, currentStep, codes.code) } } else { - // only set selected item - this.getInstructionIndex(this.currentAddress, currentStep, function (error, result) { - if (!error) { - self.trigger('indexChanged', [result]) - } + codeResolver.resolveCode(address, function (address, code) { + // resoling code from stack + self.retrieveIndexAndTrigger(address, currentStep, code) }) } } +CodeManager.prototype.retrieveIndexAndTrigger = function (address, step, code) { + var self = this + this.getInstructionIndex(address, step, function (error, result) { + if (!error) { + self.trigger('changed', [code, address, result]) + } else { + console.log(error) + } + }) +} + CodeManager.prototype.getInstructionIndex = function (address, step, callback) { this.traceManager.getCurrentPC(step, function (error, instIndex) { if (error) { diff --git a/src/code/codeResolver.js b/src/code/codeResolver.js index 0d2a858b85..3f80ba5093 100644 --- a/src/code/codeResolver.js +++ b/src/code/codeResolver.js @@ -6,7 +6,7 @@ module.exports = { codes: {}, // assembly items instructions list by contract addesses instructionsIndexByBytesOffset: {}, // mapping between bytes offset and instructions index. - resolveCode: function (address, vmTraceIndex, transaction, callBack) { + resolveCode: function (address, callBack) { var cache = this.getExecutingCodeFromCache(address) if (cache) { callBack(address, cache.code) diff --git a/src/ui/ASMCode.js b/src/ui/ASMCode.js index 09e5a86cdd..c53fe59453 100644 --- a/src/ui/ASMCode.js +++ b/src/ui/ASMCode.js @@ -26,21 +26,21 @@ ASMCode.prototype.render = function () { } ASMCode.prototype.init = function () { - this.codeManager.register('indexChanged', this, this.indexChanged) - this.codeManager.register('codeChanged', this, this.codeChanged) - this.codeManager.register('loadingCode', this, function (address) {}) + this.codeManager.register('changed', this, this.changed) } ASMCode.prototype.indexChanged = function (index) { document.getElementById('asmitems').value = index } -ASMCode.prototype.codeChanged = function (code, address, index) { - this.code = code - this.address = address - this.renderAssemblyItems() - yo.update(this.view, this.render()) - document.getElementById('asmitems').value = index +ASMCode.prototype.changed = function (code, address, index) { + if (this.address !== address) { + this.code = code + this.address = address + this.renderAssemblyItems() + yo.update(this.view, this.render()) + } + this.indexChanged(index) } ASMCode.prototype.renderAssemblyItems = function () { diff --git a/test/codeManager.js b/test/codeManager.js index 2d9ceb9da3..46e0ff463b 100644 --- a/test/codeManager.js +++ b/test/codeManager.js @@ -40,7 +40,7 @@ function continueTesting (t, codeManager) { t.test('CodeManager.resolveStep', function (st) { st.plan(6) - codeManager.register('indexChanged', this, function (index) { + codeManager.register('changed', this, function (code, address, index) { if (index === undefined || index === null) { st.fail(index) } else { @@ -48,8 +48,7 @@ function continueTesting (t, codeManager) { } }) - codeManager.register('codeChanged', this, function (code, address, index) { - console.log(address + ' ' + index + ' ' + code) + codeManager.register('changed', this, function (code, address, index) { if (!code) { st.fail('no codes') } else {