From d1dc081905393d2dae87d08fad65e509127f7b33 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Sun, 5 Jul 2020 11:25:39 -0400 Subject: [PATCH] refactor getLastCallChangeSince --- .../src/solidity-decoder/solidityProxy.js | 9 ++- libs/remix-lib/src/trace/traceManager.js | 72 ++++++++++++++++--- 2 files changed, 70 insertions(+), 11 deletions(-) diff --git a/libs/remix-debug/src/solidity-decoder/solidityProxy.js b/libs/remix-debug/src/solidity-decoder/solidityProxy.js index 9f53253b95..e6640fae7c 100644 --- a/libs/remix-debug/src/solidity-decoder/solidityProxy.js +++ b/libs/remix-debug/src/solidity-decoder/solidityProxy.js @@ -98,9 +98,12 @@ class SolidityProxy { */ extractStateVariablesAt (vmtraceIndex) { return new Promise((resolve, reject) => { - this.contractNameAt(vmtraceIndex).then((contractName) => { - resolve(this.extractStateVariables(contractName)) - }).catch(reject) + this.contractNameAt(vmtraceIndex, (error, contractName) => { + if (error) { + return reject(error) + } + return resolve(this.extractStateVariables(contractName)) + }) }) } diff --git a/libs/remix-lib/src/trace/traceManager.js b/libs/remix-lib/src/trace/traceManager.js index 4080f407fd..e0741f48db 100644 --- a/libs/remix-lib/src/trace/traceManager.js +++ b/libs/remix-lib/src/trace/traceManager.js @@ -140,10 +140,24 @@ TraceManager.prototype.getStackAt = function (stepIndex, callback) { } } +// TraceManager.prototype.getLastCallChangeSince = function (stepIndex, callback) { +// const check = this.checkRequestedStep(stepIndex) +// if (check) { +// return callback(check, null) +// } +// const callChange = util.findCall(stepIndex, this.traceCache.callsTree.call) +// if (callChange === null) { +// callback(null, 0) +// } else { +// callback(null, callChange) +// } +// } + TraceManager.prototype.getLastCallChangeSince = function (stepIndex) { - try { - this.checkRequestedStep(stepIndex) - } catch (check) { + // this.checkRequestedStep(stepIndex) + const check = this.checkRequestedStep(stepIndex) + if (check) { + // return callback(check, null) throw new Error(check) } @@ -154,16 +168,58 @@ TraceManager.prototype.getLastCallChangeSince = function (stepIndex) { return callChange } -TraceManager.prototype.getCurrentCalledAddressAt = function (stepIndex) { +// TraceManager.prototype.getCurrentCalledAddressAt = function (stepIndex, callback) { +// const check = this.checkRequestedStep(stepIndex) +// if (check) { +// return callback(check, null) +// } +// this.getLastCallChangeSince(stepIndex, function (error, resp) { +// if (error) { +// callback(error, null) +// } else { +// if (resp) { +// callback(null, resp.address) +// } else { +// callback('unable to get current called address. ' + stepIndex + ' does not match with a CALL') +// } +// } +// }) +// } + +// TraceManager.prototype.getCurrentCalledAddressAt = function (stepIndex) { +// const check = this.checkRequestedStep(stepIndex) +// if (check) { +// // return callback(check, null) +// throw new Error(check) +// } +// try { +// const resp = this.getLastCallChangeSince(stepIndex) +// if (!resp) { +// throw new Error('unable to get current called address. ' + stepIndex + ' does not match with a CALL') +// } +// return resp.address +// } catch (error) { +// throw new Error(error) +// } +// } + +TraceManager.prototype.getCurrentCalledAddressAt = function (stepIndex, callback) { + const check = this.checkRequestedStep(stepIndex) + if (check) { + return callback(check, null) + } + try { - this.checkRequestedStep(stepIndex) const resp = this.getLastCallChangeSince(stepIndex) if (!resp) { - throw new Error('unable to get current called address. ' + stepIndex + ' does not match with a CALL') + // throw new Error('unable to get current called address. ' + stepIndex + ' does not match with a CALL') + callback('unable to get current called address. ' + stepIndex + ' does not match with a CALL') } - return resp.address + // return resp.address + return callback(null, resp.address) } catch (error) { - throw new Error(error) + // throw new Error(error) + return callback(error) } }