diff --git a/remix-debug/src/debugger/VmDebugger.js b/remix-debug/src/debugger/VmDebugger.js index a21e5c5f61..896efdceea 100644 --- a/remix-debug/src/debugger/VmDebugger.js +++ b/remix-debug/src/debugger/VmDebugger.js @@ -196,7 +196,7 @@ class VmDebuggerLogic { self.event.trigger('newTrace', []) }) - self.debugger.event.register('callTreeReady', function () { + self.debugger.callTree.event.register('callTreeReady', function () { if (self.debugger.callTree.reducedTrace.length) { return self.event.trigger('newCallTree', []) } diff --git a/remix-debug/src/debugger/debugger.js b/remix-debug/src/debugger/debugger.js index 0d9ede06de..56b911b844 100644 --- a/remix-debug/src/debugger/debugger.js +++ b/remix-debug/src/debugger/debugger.js @@ -69,34 +69,41 @@ Debugger.prototype.updateWeb3 = function (web3) { } Debugger.prototype.debug = function (blockNumber, txNumber, tx, loadingCb) { - const self = this let web3 = this.debugger.web3 - if (this.debugger.traceManager.isLoading) { - return - } + return new Promise((resolve, reject) => { + if (this.debugger.traceManager.isLoading) { + return resolve() + } - if (tx) { - if (!tx.to) { - tx.to = traceHelper.contractCreationToken('0') + if (tx) { + if (!tx.to) { + tx.to = traceHelper.contractCreationToken('0') + } + this.debugTx(tx, loadingCb) + return resolve() } - return self.debugTx(tx, loadingCb) - } - - try { - if (txNumber.indexOf('0x') !== -1) { - return web3.eth.getTransaction(txNumber, function (_error, result) { - let tx = result - self.debugTx(tx, loadingCb) + + try { + if (txNumber.indexOf('0x') !== -1) { + return web3.eth.getTransaction(txNumber, (_error, tx) => { + if (_error) return reject(_error) + if (!tx) return reject('cannot find transaction ' + txNumber) + this.debugTx(tx, loadingCb) + return resolve() + }) + } + web3.eth.getTransactionFromBlock(blockNumber, txNumber, (_error, tx) => { + if (_error) return reject(_error) + if (!tx) return reject('cannot find transaction ' + blockNumber + ' ' + txNumber) + this.debugTx(tx, loadingCb) + return resolve() }) + } catch (e) { + console.error(e.message) + return reject(e.message) } - web3.eth.getTransactionFromBlock(blockNumber, txNumber, function (_error, result) { - let tx = result - self.debugTx(tx, loadingCb) - }) - } catch (e) { - console.error(e.message) - } + }) } Debugger.prototype.debugTx = function (tx, loadingCb) { @@ -115,7 +122,7 @@ Debugger.prototype.debugTx = function (tx, loadingCb) { this.vmDebuggerLogic.start() this.step_manager.event.register('stepChanged', this, function (stepIndex) { - if (!stepIndex) { + if (typeof stepIndex !== 'number' || stepIndex >= self.step_manager.traceLength) { return self.event.trigger('endDebug') }