Commit 78b93513 authored by Iuri Matias's avatar Iuri Matias

refactor resolveTrace into a promise

parent c7018a7d
...@@ -112,11 +112,7 @@ Ethdebugger.prototype.decodeStateAt = async function (step, stateVars, callback) ...@@ -112,11 +112,7 @@ Ethdebugger.prototype.decodeStateAt = async function (step, stateVars, callback)
} }
Ethdebugger.prototype.storageViewAt = function (step, address) { Ethdebugger.prototype.storageViewAt = function (step, address) {
return new StorageViewer({ return new StorageViewer({stepIndex: step, tx: this.tx, address: address}, this.storageResolver, this.traceManager)
stepIndex: step,
tx: this.tx,
address: address
}, this.storageResolver, this.traceManager)
} }
Ethdebugger.prototype.updateWeb3 = function (web3) { Ethdebugger.prototype.updateWeb3 = function (web3) {
...@@ -134,21 +130,18 @@ Ethdebugger.prototype.debug = function (tx) { ...@@ -134,21 +130,18 @@ Ethdebugger.prototype.debug = function (tx) {
if (this.traceManager.isLoading) { if (this.traceManager.isLoading) {
return return
} }
if (!tx.to) { tx.to = tx.to || traceHelper.contractCreationToken('0')
tx.to = traceHelper.contractCreationToken('0')
}
this.tx = tx this.tx = tx
this.traceManager.resolveTrace(tx, async (error, result) => {
if (result) { this.traceManager.resolveTrace(tx).then(async (result) => {
this.setCompilationResult(await this.compilationResult(tx.to)) this.setCompilationResult(await this.compilationResult(tx.to))
this.event.trigger('newTraceLoaded', [this.traceManager.trace]) this.event.trigger('newTraceLoaded', [this.traceManager.trace])
if (this.breakpointManager && this.breakpointManager.hasBreakpoint()) { if (this.breakpointManager && this.breakpointManager.hasBreakpoint()) {
this.breakpointManager.jumpNextBreakpoint(false) this.breakpointManager.jumpNextBreakpoint(false)
} }
this.storageResolver = new StorageResolver({web3: this.traceManager.web3}) this.storageResolver = new StorageResolver({web3: this.traceManager.web3})
} else { }).catch((error) => {
this.statusMessage = error ? error.message : 'Trace not loaded' this.statusMessage = error ? error.message : 'Trace not loaded'
}
}) })
} }
......
...@@ -119,12 +119,10 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu ...@@ -119,12 +119,10 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
cb() cb()
}) })
}) })
traceManager.resolveTrace(tx, (error, result) => { traceManager.resolveTrace(tx).then(() => {
if (error) {
st.fail(error)
} else {
debuggerEvent.trigger('newTraceLoaded', [traceManager.trace]) debuggerEvent.trigger('newTraceLoaded', [traceManager.trace])
} }).catch((error) => {
st.fail(error)
}) })
} }
}) })
......
...@@ -65,12 +65,10 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu ...@@ -65,12 +65,10 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
cb() cb()
}) })
}) })
traceManager.resolveTrace(tx, (error, result) => { traceManager.resolveTrace(tx).then(() => {
if (error) {
st.fail(error)
} else {
debuggerEvent.trigger('newTraceLoaded', [traceManager.trace]) debuggerEvent.trigger('newTraceLoaded', [traceManager.trace])
} }).catch((error) => {
st.fail(error)
}) })
} }
}) })
......
...@@ -51,12 +51,10 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu ...@@ -51,12 +51,10 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
cb() cb()
}) })
}) })
traceManager.resolveTrace(tx, (error, result) => { traceManager.resolveTrace(tx).then(() => {
if (error) {
st.fail(error)
} else {
debuggerEvent.trigger('newTraceLoaded', [traceManager.trace]) debuggerEvent.trigger('newTraceLoaded', [traceManager.trace])
} }).catch((error) => {
st.fail(error)
}) })
} }
}) })
......
...@@ -109,12 +109,10 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu ...@@ -109,12 +109,10 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
cb() cb()
}) })
}) })
traceManager.resolveTrace(tx, (error, result) => { traceManager.resolveTrace(tx).then(() => {
if (error) {
st.fail(error)
} else {
debuggerEvent.trigger('newTraceLoaded', [traceManager.trace]) debuggerEvent.trigger('newTraceLoaded', [traceManager.trace])
} }).catch((error) => {
st.fail(error)
}) })
} }
}) })
......
...@@ -46,7 +46,8 @@ function testMapping (st, vm, privateKey, contractAddress, output, cb) { ...@@ -46,7 +46,8 @@ function testMapping (st, vm, privateKey, contractAddress, output, cb) {
st.end(error) st.end(error)
} else { } else {
var traceManager = new TraceManager({web3: vm.web3}) var traceManager = new TraceManager({web3: vm.web3})
traceManager.resolveTrace(tx, () => {
traceManager.resolveTrace(tx).then(() => {
var storageViewer = new StorageViewer({ var storageViewer = new StorageViewer({
stepIndex: 268, stepIndex: 268,
tx: tx, tx: tx,
......
...@@ -17,10 +17,11 @@ function TraceManager (options) { ...@@ -17,10 +17,11 @@ function TraceManager (options) {
} }
// init section // init section
TraceManager.prototype.resolveTrace = async function (tx, callback) { TraceManager.prototype.resolveTrace = async function (tx) {
return new Promise(async (resolve, reject) => {
this.tx = tx this.tx = tx
this.init() this.init()
if (!this.web3) callback('web3 not loaded', false) if (!this.web3) reject('web3 not loaded')
this.isLoading = true this.isLoading = true
try { try {
const result = await this.getTrace(tx.hash) const result = await this.getTrace(tx.hash)
...@@ -30,17 +31,18 @@ TraceManager.prototype.resolveTrace = async function (tx, callback) { ...@@ -30,17 +31,18 @@ TraceManager.prototype.resolveTrace = async function (tx, callback) {
this.traceAnalyser.analyse(result.structLogs, tx) this.traceAnalyser.analyse(result.structLogs, tx)
this.isLoading = false this.isLoading = false
return callback(null, true) return resolve(true)
} }
var mes = tx.hash + ' is not a contract invocation or contract creation.' var mes = tx.hash + ' is not a contract invocation or contract creation.'
console.log(mes) console.log(mes)
this.isLoading = false this.isLoading = false
callback(mes, false) reject(mes)
} catch (error) { } catch (error) {
console.log(error) console.log(error)
this.isLoading = false this.isLoading = false
callback(error, false) reject(error)
} }
})
} }
TraceManager.prototype.getTrace = function (txHash) { TraceManager.prototype.getTrace = function (txHash) {
......
...@@ -23,12 +23,10 @@ tape('CodeManager', function (t) { ...@@ -23,12 +23,10 @@ tape('CodeManager', function (t) {
const contractCode = web3.eth.getCode('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5') const contractCode = web3.eth.getCode('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5')
codeManager.codeResolver.cacheExecutingCode('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', contractCode) // so a call to web3 is not necessary codeManager.codeResolver.cacheExecutingCode('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', contractCode) // so a call to web3 is not necessary
const tx = web3.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51') const tx = web3.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51')
traceManager.resolveTrace(tx, function (error, result) { traceManager.resolveTrace(tx).then(() => {
if (error) {
t.fail(' - traceManager.resolveTrace - failed ' + result)
} else {
continueTesting(t, codeManager) continueTesting(t, codeManager)
} }).catch(() => {
t.fail(' - traceManager.resolveTrace - failed ')
}) })
} }
}) })
......
...@@ -27,12 +27,10 @@ tape('TraceManager', function (t) { ...@@ -27,12 +27,10 @@ tape('TraceManager', function (t) {
t.test('TraceManager.resolveTrace', function (st) { t.test('TraceManager.resolveTrace', function (st) {
const tx = web3.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51') const tx = web3.eth.getTransaction('0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51')
traceManager.resolveTrace(tx, function (error, result) { traceManager.resolveTrace(tx).then(() => {
if (error) {
st.fail(' - traceManager.resolveTrace - failed ' + result)
} else {
st.end() st.end()
} }).catch(() => {
st.fail(' - traceManager.resolveTrace - failed ')
}) })
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment