Merge pull request #21 from yann300/slider

Slider
pull/7/head
chriseth 9 years ago
commit b4d7d8c4ad
  1. 2
      package.json
  2. 123
      src/assemblyItemsBrowser.js
  3. 2
      src/debugger.js
  4. 36
      src/slider.js
  5. 17
      src/sliderStyles.js
  6. 1
      src/txBrowser.js
  7. 9
      src/vmTraceBrowser.js
  8. 30
      src/vmTraceButtonNavigator.js

@ -20,7 +20,7 @@
}, },
"devDependencies": { "devDependencies": {
"babel-preset-react": "^6.5.0", "babel-preset-react": "^6.5.0",
"babelify": "^7.2.0", "babelify": "^7.2.0"
}, },
"scripts": { "scripts": {
"install": "npm install --save react react-dom; npm install -g browserify; npm install --save babelify babel-preset-react; npm install web3", "install": "npm install --save react react-dom; npm install -g browserify; npm install --save babelify babel-preset-react; npm install web3",

@ -1,16 +1,18 @@
var React = require('react'); var React = require('react');
var BasicPanel = require('./basicPanel') var BasicPanel = require('./basicPanel')
var Sticker = require('./sticker') var Sticker = require('./sticker')
var ButtonNavigator = require('./vmTraceButtonNavigator')
var codeUtils = require('./codeUtils') var codeUtils = require('./codeUtils')
var style = require('./basicStyles') var style = require('./basicStyles')
var Slider = require('./slider');
module.exports = React.createClass({ module.exports = React.createClass({
getInitialState: function() getInitialState: function()
{ {
return { return {
currentSelected: 0, // current selected item in the vmTrace currentSelected: -1, // current selected item in the vmTrace
selectedInst: 0, // current selected item in the contract assembly code selectedInst: -1, // current selected item in the contract assembly code
currentAddress: null, currentAddress: null,
currentStack: null, currentStack: null,
currentLevels: null, currentLevels: null,
@ -36,14 +38,12 @@ module.exports = React.createClass({
return ( return (
<div style={this.props.vmTrace === null ? style.hidden : style.display} > <div style={this.props.vmTrace === null ? style.hidden : style.display} >
<div style={style.container}><span style={style.address}>Current code: {this.state.currentAddress}</span></div> <div style={style.container}><span style={style.address}>Current code: {this.state.currentAddress}</span></div>
<div style={style.container}> <div style={style.container}>
<button onClick={this.stepIntoBack} disabled={ this.checkButtonState(-1) } >Step Into Back</button> <Slider ref="slider" onChange={this.selectState} min="0" max={this.props.vmTrace ? this.props.vmTrace.length : 0}/>
<button onClick={this.stepOverBack} disabled={ this.checkButtonState(-1) } >Step Over Back</button> <ButtonNavigator
<button onClick={this.stepOverForward} disabled={ this.checkButtonState(1) } >Step Over Forward</button> vmTraceLength={this.props.vmTrace ? this.props.vmTrace.length : 0} step={this.state.currentSelected} stepIntoBack={this.stepIntoBack}
<button onClick={this.stepIntoForward} disabled={ this.checkButtonState(1) } >Step Into Forward</button> stepIntoForward={this.stepIntoForward} stepOverBack={this.stepOverBack} stepOverForward={this.stepOverForward} />
</div> </div>
<div style={style.container}> <div style={style.container}>
<table> <table>
<tbody> <tbody>
@ -119,16 +119,6 @@ module.exports = React.createClass({
} }
}, },
checkButtonState: function(incr)
{
if (!this.props.vmTrace)
return "disabled"
if (incr === -1)
return this.state.currentSelected === 0 ? "disabled" : ""
else if (incr === 1)
return this.state.currentSelected >= this.props.vmTrace.length - 1 ? "disabled" : ""
},
renderAssemblyItems: function() renderAssemblyItems: function()
{ {
if (this.props.vmTrace) if (this.props.vmTrace)
@ -145,6 +135,7 @@ module.exports = React.createClass({
if (!nextProps.vmTrace) if (!nextProps.vmTrace)
return return
this.buildCallStack(nextProps.vmTrace) this.buildCallStack(nextProps.vmTrace)
this.setState({"currentSelected": -1})
this.updateState(nextProps, 0) this.updateState(nextProps, 0)
}, },
@ -154,7 +145,7 @@ module.exports = React.createClass({
return return
var callStack = [] var callStack = []
var depth = -1 var depth = -1
for (var k = 1; k < vmTrace.length; k++) for (var k = 0; k < vmTrace.length; k++)
{ {
var trace = vmTrace[k] var trace = vmTrace[k]
if (trace.depth === undefined || trace.depth === depth) if (trace.depth === undefined || trace.depth === depth)
@ -170,50 +161,42 @@ module.exports = React.createClass({
updateState: function(props, vmTraceIndex) updateState: function(props, vmTraceIndex)
{ {
if (!props.vmTrace) if (!props.vmTrace || !props.vmTrace[vmTraceIndex])
return return
var previousState = this.state.currentSelected var previousIndex = this.state.currentSelected
var stateChanges = {} var stateChanges = {}
var currentAddress = this.state.currentAddress if (props.vmTrace[vmTraceIndex].stack) // there's always a stack
if (!currentAddress)
currentAddress = props.vmTrace[vmTraceIndex].address
if (props.vmTrace[vmTraceIndex].address && props.vmTrace[vmTraceIndex].address !== this.state.currentAddress)
{
this.resolveAddress(props.vmTrace[vmTraceIndex].address)
stateChanges["currentAddress"] = props.vmTrace[vmTraceIndex].address
}
if (props.vmTrace[vmTraceIndex].stack)
{ {
var stack = props.vmTrace[vmTraceIndex].stack var stack = props.vmTrace[vmTraceIndex].stack
stack.reverse() stack.reverse()
stateChanges["currentStack"] = stack stateChanges["currentStack"] = stack
} }
var callStackIndex = vmTraceIndex var currentAddress = this.state.currentAddress
if (vmTraceIndex < previousState) var addressIndex = this.shouldUpdateStateProperty("address", vmTraceIndex, previousIndex, props.vmTrace)
callStackIndex = this.retrieveLastSeenProperty(vmTraceIndex, "depth", props.vmTrace) if (addressIndex > -1)
if (this.state.callStack[callStackIndex] || callStackIndex === 0) {
stateChanges["currentCallStack"] = this.state.callStack[callStackIndex] currentAddress = props.vmTrace[addressIndex].address
this.resolveAddress(currentAddress)
var storageIndex = vmTraceIndex Object.assign(stateChanges, { "currentAddress": currentAddress })
if (vmTraceIndex < previousState) }
storageIndex = this.retrieveLastSeenProperty(vmTraceIndex, "storage", props.vmTrace)
if (props.vmTrace[storageIndex].storage || storageIndex === 0) var depthIndex = this.shouldUpdateStateProperty("depth", vmTraceIndex, previousIndex, props.vmTrace)
stateChanges["currentStorage"] = props.vmTrace[storageIndex].storage if (depthIndex > -1)
Object.assign(stateChanges, { "currentCallStack": this.state.callStack[depthIndex] })
var memoryIndex = vmTraceIndex
if (vmTraceIndex < previousState) var storageIndex = this.shouldUpdateStateProperty("storage", vmTraceIndex, previousIndex, props.vmTrace)
memoryIndex = this.retrieveLastSeenProperty(vmTraceIndex, "memory", props.vmTrace) if (storageIndex > -1)
if (props.vmTrace[memoryIndex].memory || memoryIndex === 0) Object.assign(stateChanges, { "currentStorage": props.vmTrace[storageIndex].storage })
stateChanges["currentMemory"] = this.formatMemory(props.vmTrace[memoryIndex].memory, 16)
var memoryIndex = this.shouldUpdateStateProperty("memory", vmTraceIndex, previousIndex, props.vmTrace)
var callDataIndex = vmTraceIndex if (memoryIndex > -1)
if (vmTraceIndex < previousState) Object.assign(stateChanges, { "currentMemory": this.formatMemory(props.vmTrace[memoryIndex].memory, 16) })
callDataIndex = this.retrieveLastSeenProperty(vmTraceIndex, "calldata", props.vmTrace)
if (props.vmTrace[vmTraceIndex].calldata || callDataIndex === 0) var callDataIndex = this.shouldUpdateStateProperty("calldata", vmTraceIndex, previousIndex, props.vmTrace)
stateChanges["currentCallData"] = [props.vmTrace[callDataIndex].calldata] if (callDataIndex > -1)
Object.assign(stateChanges, { "currentCallData": [props.vmTrace[callDataIndex].calldata] })
stateChanges["selectedInst"] = this.state.instructionsIndexByBytesOffset[currentAddress][props.vmTrace[vmTraceIndex].pc] stateChanges["selectedInst"] = this.state.instructionsIndexByBytesOffset[currentAddress][props.vmTrace[vmTraceIndex].pc]
stateChanges["currentSelected"] = vmTraceIndex stateChanges["currentSelected"] = vmTraceIndex
@ -224,10 +207,24 @@ module.exports = React.createClass({
"Step Cost: " + props.vmTrace[vmTraceIndex].gascost, "Step Cost: " + props.vmTrace[vmTraceIndex].gascost,
"Remaining Gas: " + props.vmTrace[vmTraceIndex].gas "Remaining Gas: " + props.vmTrace[vmTraceIndex].gas
] ]
this.refs.slider.setValue(vmTraceIndex)
this.setState(stateChanges) this.setState(stateChanges)
}, },
shouldUpdateStateProperty: function(vmTraceName, nextIndex, previousIndex, vmTrace)
{
var propIndex = -1
if (previousIndex + 1 === nextIndex)
propIndex = nextIndex
else
propIndex = this.retrieveLastSeenProperty(nextIndex, vmTraceName, vmTrace)
if (propIndex > -1 && vmTrace[propIndex][vmTraceName] !== undefined)
return propIndex
else
return -1
},
retrieveLastSeenProperty: function(currentIndex, propertyName, vmTrace) retrieveLastSeenProperty: function(currentIndex, propertyName, vmTrace)
{ {
var index = currentIndex var index = currentIndex
@ -245,22 +242,6 @@ module.exports = React.createClass({
this.moveSelection(-1) this.moveSelection(-1)
}, },
stepOverBack: function()
{
if (this.isReturnInstruction(this.state.currentSelected - 1))
this.stepOutBack();
else
this.moveSelection(-1);
},
stepOverForward: function()
{
if (this.isCallInstruction(this.state.currentSelected))
this.stepOutForward();
else
this.moveSelection(1);
},
stepIntoForward: function() stepIntoForward: function()
{ {
this.moveSelection(1) this.moveSelection(1)

@ -6,7 +6,7 @@ var style = require('./basicStyles')
module.exports = React.createClass({ module.exports = React.createClass({
getInitialState: function() { getInitialState: function() {
return {vmTrace: null, state: ""} return {vmTrace: null, state: "", currentStep: -1}
}, },
render: function() { render: function() {

@ -0,0 +1,36 @@
var React = require('react');
var style = require('./sliderStyles')
module.exports = React.createClass({
propTypes: {
onChange: React.PropTypes.func.isRequired,
},
getDefaultProps: function () {
return {
min: 0,
max: 500
};
},
render: function () {
return (
<div>
<input ref="rule" style={style.rule} type="range" min={this.props.min} max={this.props.max} onMouseUp={this.onMouseUp} />
</div>
);
},
onMouseUp: function (event) {
this.props.onChange(parseInt(this.refs.rule.value))
},
setValue: function (value) {
var diff = value - this.refs.rule.value
if (diff > 0)
this.refs.rule.stepUp(diff)
else
this.refs.rule.stepDown(Math.abs(diff))
}
})

@ -0,0 +1,17 @@
module.exports = {
rule:
{
'width': '600px',
},
runner:
{
'position': 'absolute',
'width': '16px',
'height': '16px',
'margin': '0',
'padding': '0',
'overflow': 'hidden',
'border': '1px solid #a4bed4',
'background-color': '#f1f7ff'
}
}

@ -13,6 +13,7 @@ module.exports = React.createClass({
submit: function() submit: function()
{ {
var tx = web3.eth.getTransactionFromBlock(this.state.blockNumber, this.state.txNumber) var tx = web3.eth.getTransactionFromBlock(this.state.blockNumber, this.state.txNumber)
if (tx)
this.setState({from: tx.from, to: tx.to, hash: tx.hash}) this.setState({from: tx.from, to: tx.to, hash: tx.hash})
this.props.onNewTxRequested(this.state.blockNumber, parseInt(this.state.txNumber)) this.props.onNewTxRequested(this.state.blockNumber, parseInt(this.state.txNumber))
}, },

@ -2,7 +2,12 @@ var React = require('react');
var AssemblyItemsBrowser = require('./assemblyItemsBrowser'); var AssemblyItemsBrowser = require('./assemblyItemsBrowser');
module.exports = React.createClass({ module.exports = React.createClass({
render: function() { render: function() {
return ( <AssemblyItemsBrowser vmTrace={this.props.vmTrace} /> ) return (
} <div>
<AssemblyItemsBrowser vmTrace={this.props.vmTrace} />
</div>
)
},
}); });

@ -0,0 +1,30 @@
var React = require('react');
module.exports = React.createClass({
propTypes: {
stepIntoBack: React.PropTypes.func.isRequired,
stepIntoForward: React.PropTypes.func.isRequired,
stepOverBack: React.PropTypes.func.isRequired,
stepOverForward: React.PropTypes.func.isRequired,
},
render: function() {
return (
<div>
<button onClick={this.props.stepIntoBack} disabled={this.checkButtonState(-1)} >Step Into Back</button>
<button onClick={this.props.stepOverBack} disabled={this.checkButtonState(-1)} >Step Over Back</button>
<button onClick={this.props.stepOverForward} disabled={this.checkButtonState(1)} >Step Over Forward</button>
<button onClick={this.props.stepIntoForward} disabled={this.checkButtonState(1)} >Step Into Forward</button>
</div>
);
},
checkButtonState: function(incr)
{
if (incr === -1)
return this.props.step === 0 ? "disabled" : ""
else if (incr === 1)
return this.props.step >= this.props.vmTraceLength - 1 ? "disabled" : ""
},
})
Loading…
Cancel
Save