Update TraceManager to use the new callstree

pull/7/head
yann300 8 years ago
parent 858f17d264
commit 3df99cd319
  1. 32
      src/trace/traceManager.js
  2. 17
      src/trace/traceStepManager.js

@ -101,14 +101,7 @@ TraceManager.prototype.getStorageAt = function (stepIndex, tx, callback, address
} }
TraceManager.prototype.getAddresses = function (callback) { TraceManager.prototype.getAddresses = function (callback) {
var addresses = [ this.tx.to ] callback(null, this.traceCache.addresses)
for (var k in this.traceCache.calls) {
var address = this.traceCache.calls[k].address
if (address && addresses.join('').indexOf(address) === -1) {
addresses.push(address)
}
}
callback(null, addresses)
} }
TraceManager.prototype.getCallDataAt = function (stepIndex, callback) { TraceManager.prototype.getCallDataAt = function (stepIndex, callback) {
@ -126,9 +119,9 @@ TraceManager.prototype.getCallStackAt = function (stepIndex, callback) {
if (check) { if (check) {
return callback(check, null) return callback(check, null)
} }
var callStackChange = util.findLowerBoundValue(stepIndex, this.traceCache.callChanges) var call = util.findCall(stepIndex, this.traceCache.callsTree.call)
if (callStackChange === null) return callback('no callstack found', null) if (call === null) return callback('no callstack found', null)
callback(null, this.traceCache.calls[callStackChange].callStack) callback(null, call.callStack)
} }
TraceManager.prototype.getStackAt = function (stepIndex, callback) { TraceManager.prototype.getStackAt = function (stepIndex, callback) {
@ -151,7 +144,7 @@ TraceManager.prototype.getLastCallChangeSince = function (stepIndex, callback) {
if (check) { if (check) {
return callback(check, null) return callback(check, null)
} }
var callChange = util.findLowerBoundValue(stepIndex, this.traceCache.callChanges) var callChange = util.findCall(stepIndex, this.traceCache.callsTree.call)
if (callChange === null) { if (callChange === null) {
callback(null, 0) callback(null, 0)
} else { } else {
@ -164,21 +157,14 @@ TraceManager.prototype.getCurrentCalledAddressAt = function (stepIndex, callback
if (check) { if (check) {
return callback(check, null) return callback(check, null)
} }
var self = this this.getLastCallChangeSince(stepIndex, function (error, resp) {
this.getLastCallChangeSince(stepIndex, function (error, addressIndex) {
if (error) { if (error) {
callback(error, null) callback(error, null)
} else { } else {
if (addressIndex === 0) { if (resp) {
callback(null, self.tx.to) callback(null, resp.address)
} else { } else {
var callStack = self.traceCache.calls[addressIndex].callStack callback('unable to get current called address. ' + stepIndex + ' does not match with a CALL')
var calledAddress = callStack[callStack.length - 1]
if (calledAddress) {
callback(null, calledAddress)
} else {
callback('unable to get current called address. ' + stepIndex + ' does not match with a CALL', null)
}
} }
} }
}) })

@ -33,25 +33,18 @@ TraceStepManager.prototype.findStepOverForward = function (currentStep) {
} }
TraceStepManager.prototype.findNextCall = function (currentStep) { TraceStepManager.prototype.findNextCall = function (currentStep) {
var callChanges = this.traceAnalyser.traceCache.callChanges var call = util.findCall(currentStep, this.traceAnalyser.traceCache.callsTree.call)
var stepIndex = util.findLowerBound(currentStep, callChanges) var subCalls = Object.keys(call.calls)
var callchange = callChanges[stepIndex + 1] if (subCalls.length) {
if (callchange && this.isCallInstruction(callchange - 1)) { return call.calls[subCalls[0]].start - 1
return callchange - 1
} else { } else {
return currentStep return currentStep
} }
} }
TraceStepManager.prototype.findStepOut = function (currentStep) { TraceStepManager.prototype.findStepOut = function (currentStep) {
var callChanges = this.traceAnalyser.traceCache.callChanges var call = util.findCall(currentStep, this.traceAnalyser.traceCache.callsTree.call)
var stepIndex = util.findLowerBound(currentStep, callChanges)
var call = this.traceAnalyser.traceCache.calls[callChanges[stepIndex]]
if (call && call.return) {
return call.return return call.return
} else {
return currentStep
}
} }
module.exports = TraceStepManager module.exports = TraceStepManager

Loading…
Cancel
Save