- display storage changes instead of storage
pull/7/head
yann300 9 years ago
parent 60037e9718
commit efdb337874
  1. 8
      src/Ethdebugger.js
  2. 2
      src/StoragePanel.js
  3. 5
      src/TxBrowser.js
  4. 18
      src/trace/traceManager.js
  5. 10
      src/trace/traceRetriever.js
  6. 6
      test/codeManager.js
  7. 10
      test/traceManager.js

@ -69,12 +69,10 @@ Ethdebugger.prototype.startDebugging = function (blockNumber, txIndex, tx) {
console.log('loading trace...')
this.tx = tx
var self = this
this.traceManager.resolveTrace(tx, function (success) {
console.log('trace loaded ' + success)
if (success) {
this.traceManager.resolveTrace(tx, function (error, result) {
console.log('trace loaded ' + result + ' ' + error)
if (result) {
self.trigger('newTraceLoaded')
} else {
console.log('trace not loaded')
}
})
}

@ -5,7 +5,7 @@ var yo = require('yo-yo')
function StoragePanel (_parent, _traceManager) {
this.parent = _parent
this.traceManager = _traceManager
this.basicPanel = new BasicPanel('Storage')
this.basicPanel = new BasicPanel('Storage Changes')
this.init()
}

@ -19,9 +19,8 @@ function TxBrowser (_web3) {
this.setDefaultValues()
}
// 0xcda2b2835add61af54cf83bd076664d98d7908c6cd98d86423b3b48d8b8e51ff
// creation 0xa9619e1d0a35b2c1d686f5b661b3abd87f998d2844e8e9cc905edb57fc9ce349
// invokation 0x71a6d583d16d142c5c3e8903060e8a4ee5a5016348a9448df6c3e63b68076ec4
// invokation 0x71a6d583d16d142c5c3e8903060e8a4ee5a5016348a9448df6c3e63b68076ec4 0xcda2b2835add61af54cf83bd076664d98d7908c6cd98d86423b3b48d8b8e51ff
// test:
// creation: 0x72908de76f99fca476f9e3a3b5d352f350a98cd77d09cebfc59ffe32a6ecaa0b
// invokation: 0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51
@ -31,7 +30,7 @@ TxBrowser.prototype.setDefaultValues = function () {
this.to = ' - '
this.hash = ' - '
this.blockNumber = null
this.txNumber = '0x71a6d583d16d142c5c3e8903060e8a4ee5a5016348a9448df6c3e63b68076ec4'
this.txNumber = '0xcda2b2835add61af54cf83bd076664d98d7908c6cd98d86423b3b48d8b8e51ff'
}
TxBrowser.prototype.submit = function () {

@ -20,13 +20,14 @@ function TraceManager (_web3) {
TraceManager.prototype.resolveTrace = function (tx, callback) {
this.tx = tx
this.init()
if (!this.web3) callback(false)
if (!this.web3) callback('web3 not loaded', false)
this.isLoading = true
var self = this
this.traceRetriever.getTrace(tx.hash, function (error, result) {
if (error) {
console.log(error)
self.isLoading = false
callback(error, false)
} else {
if (result.structLogs.length > 0) {
self.trace = result.structLogs
@ -34,15 +35,17 @@ TraceManager.prototype.resolveTrace = function (tx, callback) {
if (error) {
self.isLoading = false
console.log(error)
callback(false)
callback(error, false)
} else {
self.isLoading = false
callback(true)
callback(null, true)
}
})
} else {
console.log(tx.hash + ' is not a contract invokation or contract creation.')
var mes = tx.hash + ' is not a contract invokation or contract creation.'
console.log(mes)
self.isLoading = false
callback(mes, false)
}
}
})
@ -77,6 +80,12 @@ TraceManager.prototype.getStorageAt = function (stepIndex, tx, callback) {
}
var stoChange = traceHelper.findLowerBound(stepIndex, this.traceCache.storageChanges)
if (stoChange === undefined) return callback('no storage found', null)
var address = this.traceCache.sstore[stoChange].address
var storage = {}
storage = this.traceCache.rebuildStorage(address, storage, stepIndex)
callback(null, storage)
/*
// TODO: use it if we need the full storage to be loaded
var self = this
if (this.traceRetriever.debugStorageAtAvailable()) {
var address = this.traceCache.sstore[stoChange].address
@ -92,6 +101,7 @@ TraceManager.prototype.getStorageAt = function (stepIndex, tx, callback) {
} else {
callback(null, this.trace[stoChange].storage)
}
*/
}
TraceManager.prototype.getCallDataAt = function (stepIndex, callback) {

@ -8,10 +8,10 @@ function TraceRetriever (_web3) {
TraceRetriever.prototype.getTrace = function (txHash, callback) {
var options = {
disableStorage: this.debugStorageAtAvailable(),
disableStorage: true,
disableMemory: false,
disableStack: false,
fullStorage: false // !this.debugStorageAtAvailable()
fullStorage: false
}
this.web3.debug.traceTransaction(txHash, options, function (error, result) {
callback(error, result)
@ -24,16 +24,20 @@ TraceRetriever.prototype.getStorage = function (tx, address, callback) {
} else if (this.storages[address]) {
callback(null, this.storages[address])
} else {
// we always return an empty storage ... storage changes will be displayed instead of the full contract storage
callback(null, {})
/*
var self = this
this.web3.debug.storageAt(tx.blockNumber.toString(), tx.transactionIndex, address, function (error, result) {
self.storages[address] = result
callback(error, result)
})
*/
}
}
TraceRetriever.prototype.debugStorageAtAvailable = function () {
return this.web3.version.node.toLowerCase().indexOf('geth') === -1 // storageAt not available if using geth
return false // this.web3.version.node.toLowerCase().indexOf('geth') === -1 // storageAt not available if using geth
}
module.exports = TraceRetriever

@ -14,9 +14,9 @@ tape('CodeManager', function (t) {
traceManager.traceRetriever = new TestTraceRetriever()
codeManager = new CodeManager(web3, traceManager)
codeManager.codeResolver.cacheExecutingCode('0x0d3a18d64dfe4f927832ab58d6451cecc4e517c5', contractCode) // so a call to web3 is not necessary
traceManager.resolveTrace(txInvokation, function (success) {
if (!success) {
t.fail(' - traceManager.resolveTrace - failed')
traceManager.resolveTrace(txInvokation, function (error, result) {
if (error) {
t.fail(' - traceManager.resolveTrace - failed ' + result)
} else {
continueTesting(t, codeManager)
}

@ -16,9 +16,9 @@ tape('TraceManager', function (t) {
})
t.test('TraceManager.resolveTrace', function (st) {
traceManager.resolveTrace(txInvokation, function (success) {
if (!success) {
st.fail(' - traceManager.resolveTrace - failed')
traceManager.resolveTrace(txInvokation, function (error, result) {
if (error) {
st.fail(' - traceManager.resolveTrace - failed ' + result)
} else {
st.end()
}
@ -44,11 +44,11 @@ tape('TraceManager', function (t) {
})
t.test('TraceManager.getStorageAt', function (st) {
traceManager.getStorageAt(0, txInvokation, function (error, result) {
traceManager.getStorageAt(110, txInvokation, function (error, result) {
if (error) {
st.fail(error)
} else {
st.ok(result['0x00'] === '0x2d')
st.ok(result['0x00'] === '0x38')
st.end()
}
})

Loading…
Cancel
Save