Merge branch 'master' into yann300-patch-3

pull/7/head
yann300 9 years ago committed by GitHub
commit 52fc1540b8
  1. 8
      src/Ethdebugger.js
  2. 2
      src/StoragePanel.js
  3. 32
      src/TxBrowser.js
  4. 4
      src/helpers/init.js
  5. 18
      src/trace/traceManager.js
  6. 10
      src/trace/traceRetriever.js
  7. 6
      test/codeManager.js
  8. 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()
}

@ -4,6 +4,7 @@ var EventManager = require('./lib/eventManager')
var traceHelper = require('./helpers/traceHelper')
var yo = require('yo-yo')
var ui = require('./helpers/ui')
var init = require('./helpers/init')
function TxBrowser (_web3) {
util.extend(this, new EventManager())
@ -19,9 +20,8 @@ function TxBrowser (_web3) {
this.setDefaultValues()
}
// 0xcda2b2835add61af54cf83bd076664d98d7908c6cd98d86423b3b48d8b8e51ff
// creation 0xa9619e1d0a35b2c1d686f5b661b3abd87f998d2844e8e9cc905edb57fc9ce349
// invokation 0x71a6d583d16d142c5c3e8903060e8a4ee5a5016348a9448df6c3e63b68076ec4
// invokation 0x71a6d583d16d142c5c3e8903060e8a4ee5a5016348a9448df6c3e63b68076ec4 0xcda2b2835add61af54cf83bd076664d98d7908c6cd98d86423b3b48d8b8e51ff
// test:
// creation: 0x72908de76f99fca476f9e3a3b5d352f350a98cd77d09cebfc59ffe32a6ecaa0b
// invokation: 0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51
@ -31,7 +31,9 @@ TxBrowser.prototype.setDefaultValues = function () {
this.to = ' - '
this.hash = ' - '
this.blockNumber = null
this.txNumber = '0x71a6d583d16d142c5c3e8903060e8a4ee5a5016348a9448df6c3e63b68076ec4'
this.txNumber = '0xcda2b2835add61af54cf83bd076664d98d7908c6cd98d86423b3b48d8b8e51ff'
this.connectInfo = ''
this.checkWeb3()
}
TxBrowser.prototype.submit = function () {
@ -67,6 +69,22 @@ TxBrowser.prototype.submit = function () {
yo.update(this.view, this.render())
}
TxBrowser.prototype.updateWeb3Url = function (ev) {
init.setProvider(this.web3, ev.target.value)
this.checkWeb3()
yo.update(this.view, this.render())
}
TxBrowser.prototype.checkWeb3 = function () {
try {
console.log('block ' + this.web3.eth.blockNumber)
this.connectInfo = 'Connected to ' + this.web3.currentProvider.host
} catch (e) {
console.log(e)
this.connectInfo = e.message
}
}
TxBrowser.prototype.updateBlockN = function (ev) {
this.blockNumber = ev.target.value
}
@ -83,8 +101,12 @@ TxBrowser.prototype.init = function (ev) {
TxBrowser.prototype.render = function () {
var self = this
var view = yo`<div style=${ui.formatCss(style.container)}>
<input onchange=${function () { self.updateBlockN(arguments[0]) }} type='text' placeholder=${'Block number (default 1000110)' + this.blockNumber}></input>
<input onchange=${function () { self.updateTxN(arguments[0]) }} type='text' value=${this.txNumber} placeholder=${'Transaction Number or hash (default 2) ' + this.txNumber}></input>
<span>Node URL: </span><input onkeyup=${function () { self.updateWeb3Url(arguments[0]) }} value=${this.web3.currentProvider ? this.web3.currentProvider.host : ' - none - '} type='text' />
<span>${this.connectInfo}</span>
<br />
<br />
<input onkeyup=${function () { self.updateBlockN(arguments[0]) }} type='text' placeholder=${'Block number (default 1000110)' + this.blockNumber} />
<input onkeyup=${function () { self.updateTxN(arguments[0]) }} type='text' value=${this.txNumber} placeholder=${'Transaction Number or hash (default 2) ' + this.txNumber} />
<button onclick=${function () { self.submit() }}>
Get
</button>

@ -8,5 +8,9 @@ module.exports = {
web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545'))
Web3Admin.extend(web3)
return web3
},
setProvider: function (web3, url) {
web3.setProvider(new web3.providers.HttpProvider(url))
}
}

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