parent
98c34f1ff0
commit
80ee748875
@ -1,114 +1,56 @@ |
||||
'use strict' |
||||
var React = require('react') |
||||
var style = require('./basicStyles') |
||||
var codeResolver = require('./codeResolver') |
||||
var traceManagerUtil = require('./traceManagerUtil') |
||||
|
||||
module.exports = React.createClass({ |
||||
contextTypes: { |
||||
traceManager: React.PropTypes.object, |
||||
tx: React.PropTypes.object, |
||||
web3: React.PropTypes.object |
||||
codeManager: React.PropTypes.object |
||||
}, |
||||
|
||||
getInitialState: function () { |
||||
return { |
||||
code: [], |
||||
selected: -1, |
||||
address: '' // selected instruction in the asm
|
||||
} |
||||
}, |
||||
|
||||
getDefaultProps: function () { |
||||
return { |
||||
currentStepIndex: -1 |
||||
code: '', |
||||
address: '' |
||||
} |
||||
}, |
||||
|
||||
render: function () { |
||||
return ( |
||||
<select |
||||
size='10' |
||||
ref='itemsList' |
||||
style={style.instructionsList} |
||||
value={this.state.selected}> |
||||
<select size='10' ref='itemsList' style={style.instructionsList}> |
||||
{this.renderAssemblyItems()} |
||||
</select> |
||||
) |
||||
}, |
||||
|
||||
renderAssemblyItems: function () { |
||||
if (this.state.code) { |
||||
return this.state.code.map(function (item, i) { |
||||
return <option key={i} value={i}>{item}</option> |
||||
}) |
||||
} |
||||
componentDidMount: function () { |
||||
this.context.codeManager.registerIndexChangedListener(this, this.indexChanged) |
||||
this.context.codeManager.registerCodeChangedListener(this, this.codeChanged) |
||||
}, |
||||
|
||||
componentWillReceiveProps: function (nextProps) { |
||||
if (nextProps.currentStepIndex < 0) return |
||||
codeResolver.setWeb3(this.context.web3) |
||||
var self = this |
||||
if (nextProps.currentStepIndex === 0) { |
||||
self.ensureCodeLoaded(this.context.tx.to, nextProps.currentStepIndex) |
||||
} else { |
||||
this.context.traceManager.getCurrentCalledAddressAt(nextProps.currentStepIndex, function (error, address) { |
||||
if (error) { |
||||
console.log(error) |
||||
} else { |
||||
self.ensureCodeLoaded(address, nextProps.currentStepIndex) |
||||
} |
||||
}) |
||||
} |
||||
indexChanged: function (index) { |
||||
this.refs.itemsList.value = index |
||||
}, |
||||
|
||||
ensureCodeLoaded: function (address, currentStep) { |
||||
if (address !== this.state.address) { |
||||
this.setState({ |
||||
code: ['loading...'] |
||||
}) |
||||
var self = this |
||||
if (traceManagerUtil.isContractCreation(address)) { |
||||
this.context.traceManager.getContractCreationCode(address, function (error, hexCode) { |
||||
if (error) { |
||||
console.log(error) |
||||
} else { |
||||
var codes = codeResolver.cacheExecutingCode(address, hexCode) |
||||
self.updateCode(codes.code, address, currentStep) |
||||
} |
||||
}) |
||||
} else { |
||||
codeResolver.resolveCode(address, currentStep, this.context.tx, function (address, code) { |
||||
if (window.ethDebuggerSelectedItem !== currentStep) { |
||||
console.log(currentStep + ' discarded. current is ' + window.ethDebuggerSelectedItem) |
||||
return |
||||
} |
||||
self.updateCode(code, address, currentStep) |
||||
}) |
||||
} |
||||
} else { |
||||
this.setInstructionIndex(this.state.address, currentStep) |
||||
} |
||||
}, |
||||
|
||||
updateCode: function (code, address, currentStep) { |
||||
codeChanged: function (code, address, index) { |
||||
this.setState({ |
||||
code: code, |
||||
address: address |
||||
}) |
||||
this.setInstructionIndex(address, currentStep) |
||||
this.refs.itemsList.value = index |
||||
}, |
||||
|
||||
setInstructionIndex: function (address, step) { |
||||
var self = this |
||||
this.context.traceManager.getCurrentPC(step, function (error, instIndex) { |
||||
if (error) { |
||||
console.log(error) |
||||
} else { |
||||
self.setState({ |
||||
selected: codeResolver.getInstructionIndex(address, instIndex) |
||||
}) |
||||
shouldComponentUpdate: function (nextProps, nextState) { |
||||
if (nextState.address === this.state.address) { |
||||
return false |
||||
} |
||||
return true |
||||
}, |
||||
|
||||
renderAssemblyItems: function () { |
||||
if (this.state && this.state.code) { |
||||
return this.state.code.map(function (item, i) { |
||||
return <option key={i} value={i}>{item}</option> |
||||
}) |
||||
} |
||||
} |
||||
}) |
||||
|
@ -0,0 +1,113 @@ |
||||
'use strict' |
||||
var traceManagerUtil = require('./traceManagerUtil') |
||||
var codeResolver = require('./codeResolver') |
||||
function CodeManager (_web3, _traceManager) { |
||||
this.web3 = _web3 |
||||
this.isLoading = false |
||||
this.traceManager = _traceManager |
||||
this.currentAddress = '' |
||||
this.indexChangedlisteners = [] |
||||
this.codeChangedlisteners = [] |
||||
codeResolver.setWeb3(_web3) |
||||
} |
||||
|
||||
CodeManager.prototype.registerIndexChangedListener = function (obj, func) { |
||||
this.indexChangedlisteners.push({ |
||||
obj: obj, |
||||
func: func |
||||
}) |
||||
} |
||||
|
||||
CodeManager.prototype.registerCodeChangedListener = function (obj, func) { |
||||
this.codeChangedlisteners.push({ |
||||
obj: obj, |
||||
func: func |
||||
}) |
||||
} |
||||
|
||||
CodeManager.prototype.resolveCodeFor = function (stepIndex, tx) { |
||||
if (stepIndex < 0) return |
||||
var self = this |
||||
if (stepIndex === 0) { |
||||
self.ensureCodeLoaded(tx.to, stepIndex, tx) |
||||
} else { |
||||
this.traceManager.getCurrentCalledAddressAt(stepIndex, function (error, address) { |
||||
if (error) { |
||||
console.log(error) |
||||
} else { |
||||
self.ensureCodeLoaded(address, stepIndex, tx) |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
|
||||
CodeManager.prototype.ensureCodeLoaded = function (address, currentStep, tx) { |
||||
var self = this |
||||
if (address !== this.currentAddress) { |
||||
if (traceManagerUtil.isContractCreation(address)) { |
||||
this.traceManager.getContractCreationCode(address, function (error, hexCode) { |
||||
// contract creation
|
||||
if (error) { |
||||
console.log(error) |
||||
} else { |
||||
var codes = codeResolver.cacheExecutingCode(address, hexCode) |
||||
self.getInstructionIndex(address, currentStep, function (error, result) { |
||||
if (!error) { |
||||
self.dispatchCodeChanged(codes.code, address, result) |
||||
self.currentAddress = address |
||||
} else { |
||||
console.log(error) |
||||
} |
||||
}) |
||||
} |
||||
}) |
||||
} else { |
||||
codeResolver.resolveCode(address, currentStep, tx, function (address, code) { |
||||
// resoling code from stack
|
||||
self.getInstructionIndex(address, currentStep, function (error, result) { |
||||
if (!error) { |
||||
self.dispatchCodeChanged(code, address, result) |
||||
self.currentAddress = address |
||||
} else { |
||||
console.log(error) |
||||
} |
||||
}) |
||||
}) |
||||
} |
||||
} else { |
||||
// only set selected item
|
||||
this.getInstructionIndex(this.currentAddress, currentStep, function (error, result) { |
||||
if (!error) { |
||||
self.dispatchIndexChanged(result) |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
|
||||
CodeManager.prototype.getInstructionIndex = function (address, step, callback) { |
||||
this.traceManager.getCurrentPC(step, function (error, instIndex) { |
||||
if (error) { |
||||
console.log(error) |
||||
callback('Cannot retrieve current PC for ' + step, null) |
||||
} else { |
||||
var itemIndex = codeResolver.getInstructionIndex(address, instIndex) |
||||
callback(null, itemIndex) |
||||
} |
||||
}) |
||||
} |
||||
|
||||
CodeManager.prototype.dispatchIndexChanged = function (itemIndex) { |
||||
for (var listener in this.indexChangedlisteners) { |
||||
var l = this.indexChangedlisteners[listener] |
||||
l.func.call(l.obj, itemIndex) |
||||
} |
||||
} |
||||
|
||||
CodeManager.prototype.dispatchCodeChanged = function (code, address, itemIndex) { |
||||
for (var listener in this.codeChangedlisteners) { |
||||
var l = this.codeChangedlisteners[listener] |
||||
l.func.call(l.obj, code, address, itemIndex) |
||||
} |
||||
} |
||||
|
||||
module.exports = CodeManager |
Loading…
Reference in new issue