Merge branch 'master' into yann300-patch-3

pull/7/head
yann300 8 years ago committed by GitHub
commit 5c34c7c318
  1. 18
      src/trace/traceAnalyser.js
  2. 5
      src/trace/traceCache.js
  3. 2
      src/trace/traceManager.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

@ -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

@ -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) {

Loading…
Cancel
Save