From 301e230abb5545ab2a726f8a9bd70ced6a6a8c2a Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 27 Jun 2016 17:16:22 +0200 Subject: [PATCH] retrieve step from the trace --- src/trace/traceAnalyser.js | 18 ++++++++++++++---- src/trace/traceCache.js | 5 +++++ src/trace/traceManager.js | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/trace/traceAnalyser.js b/src/trace/traceAnalyser.js index 897bd6b8a4..c256b14bb0 100644 --- a/src/trace/traceAnalyser.js +++ b/src/trace/traceAnalyser.js @@ -11,7 +11,9 @@ TraceAnalyser.prototype.analyse = function (trace, tx, callback) { this.traceCache.pushStoreChanges(0, tx.to) var context = { currentStorageAddress: tx.to, - previousStorageAddress: tx.to + previousStorageAddress: tx.to, + currentCallIndex: 0, + lastCallIndex: 0 } var callStack = [tx.to] this.traceCache.pushCallStack(0, { @@ -22,11 +24,10 @@ TraceAnalyser.prototype.analyse = function (trace, tx, callback) { this.traceCache.pushContractCreation(tx.to, tx.input) } this.buildCalldata(0, this.trace[0], tx, true) - for (var k = 0; k < this.trace.length; k++) { var step = this.trace[k] this.buildMemory(k, step) - this.buildDepth(k, step, tx, callStack) + context = this.buildDepth(k, step, tx, callStack, context) context = this.buildStorage(k, step, context) } callback(null, true) @@ -82,7 +83,7 @@ TraceAnalyser.prototype.buildStorage = function (index, step, context) { return context } -TraceAnalyser.prototype.buildDepth = function (index, step, tx, callStack) { +TraceAnalyser.prototype.buildDepth = function (index, step, tx, callStack, context) { if (traceHelper.isCallInstruction(step) && !traceHelper.isCallToPrecompiledContract(index, this.trace)) { if (traceHelper.isCreateInstruction(step)) { var contractToken = traceHelper.contractCreationToken(index) @@ -102,6 +103,9 @@ TraceAnalyser.prototype.buildDepth = function (index, step, tx, callStack) { callStack: callStack.slice(0) }) this.buildCalldata(index, step, tx, true) + this.traceCache.pushSteps(index, context.currentCallIndex) + context.lastCallIndex = context.currentCallIndex + context.currentCallIndex = 0 } else if (traceHelper.isReturnInstruction(step)) { if (index + 1 < this.trace.length) { callStack.pop() @@ -110,8 +114,14 @@ TraceAnalyser.prototype.buildDepth = function (index, step, tx, callStack) { callStack: callStack.slice(0) }) this.buildCalldata(index, step, tx, false) + this.traceCache.pushSteps(index, context.currentCallIndex) + context.currentCallIndex = context.lastCallIndex + 1 } + } else { + this.traceCache.pushSteps(index, context.currentCallIndex) + context.currentCallIndex++ } + return context } module.exports = TraceAnalyser diff --git a/src/trace/traceCache.js b/src/trace/traceCache.js index 4942baf739..f69d080aa6 100644 --- a/src/trace/traceCache.js +++ b/src/trace/traceCache.js @@ -11,6 +11,7 @@ TraceCache.prototype.init = function () { this.calls = {} this.callsData = {} this.contractCreation = {} + this.steps = {} this.callDataChanges = [] this.memoryChanges = [] @@ -19,6 +20,10 @@ TraceCache.prototype.init = function () { this.callStack = {} // contains all callStack by vmtrace index (we need to rebuild it, callstack is not included in the vmtrace) } +TraceCache.prototype.pushSteps = function (index, currentCallIndex) { + this.steps[index] = currentCallIndex +} + TraceCache.prototype.pushCallDataChanges = function (value, calldata) { this.callDataChanges.push(value) this.callsData[value] = calldata diff --git a/src/trace/traceManager.js b/src/trace/traceManager.js index 463017e0f3..0c1c87680e 100644 --- a/src/trace/traceManager.js +++ b/src/trace/traceManager.js @@ -208,7 +208,7 @@ TraceManager.prototype.getCurrentStep = function (stepIndex, callback) { if (check) { return callback(check, null) } - callback(null, this.trace[stepIndex].steps) + callback(null, this.traceCache.steps[stepIndex]) } TraceManager.prototype.getMemExpand = function (stepIndex, callback) {