Unverified Commit e0332757 authored by yann300's avatar yann300 Committed by GitHub

Merge pull request #1094 from ethereum/cmd_and_library

(initial) lib for rdb
parents 56b1067f 06071125
This source diff could not be displayed because it is too large. You can view the blob instead.
'use strict' 'use strict'
var EthDebugger = require('./src/Ethdebugger') var EthDebugger = require('./src/Ethdebugger')
var TransactionDebugger = require('./src/debugger/debugger') var TransactionDebugger = require('./src/debugger/debugger')
var CmdLine = require('./src/cmdline')
var StorageViewer = require('./src/storage/storageViewer') var StorageViewer = require('./src/storage/storageViewer')
var StorageResolver = require('./src/storage/storageResolver') var StorageResolver = require('./src/storage/storageResolver')
...@@ -32,6 +33,7 @@ module.exports = { ...@@ -32,6 +33,7 @@ module.exports = {
storage: { storage: {
StorageViewer: StorageViewer, StorageViewer: StorageViewer,
StorageResolver: StorageResolver StorageResolver: StorageResolver
} },
CmdLine: CmdLine
} }
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
{ {
"name": "Liana Husikyan", "name": "Liana Husikyan",
"email": "liana@ethdev.com" "email": "liana@ethdev.com"
},
{
"name": "Iuri Matias",
"email": "iuri.matias@gmail.com"
} }
], ],
"main": "./index.js", "main": "./index.js",
......
var CmdLine = require('./src/cmdline/index.js')
// var compilation = require('./compilation.json')
var solc = require('solc')
var fs = require('fs')
var filename = 'test/sol/simple_storage.sol'
var shortFilename = 'simple_storage.sol'
var inputJson = {
language: 'Solidity',
sources: {
},
settings: {
optimizer: {
enabled: true,
runs: 200
},
outputSelection: {
'*': {
'': [ 'legacyAST' ],
'*': [ 'abi', 'metadata', 'devdoc', 'userdoc', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates' ]
}
}
}
}
inputJson.sources[shortFilename] = {content: fs.readFileSync(filename).toString()}
console.dir(inputJson)
console.log('compiling...')
let compilationData = JSON.parse(solc.compileStandardWrapper(JSON.stringify(inputJson)))
console.dir(Object.keys(compilationData))
var compilation = {}
compilation.data = compilationData
compilation.source = { sources: inputJson.sources }
console.dir(compilation)
console.dir(compilation.data.errors)
var cmdLine = new CmdLine()
cmdLine.connect('http', 'http://localhost:8545')
cmdLine.loadCompilationResult(compilation)
cmdLine.initDebugger()
// var deployContract = function (cb) {
// let _web3 = cmdLine.debugger.debugger.web3
//
// let blockNumber = null
// let txNumber = null
// let tx = null
//
// let code = compilation.data.contracts[shortFilename].SimpleStorage.evm.bytecode.object
// console.dir('deploying...')
// console.dir(code)
// _web3.eth.sendTransaction({data: '0x' + code, from: _web3.eth.accounts[0], gas: 800000}, cb)
// }
// let _web3 = cmdLine.debugger.debugger.web3
var tx = '0xf510c4f0b1d9ee262d7b9e9e87b4262f275fe029c2c733feef7dfa1e2b1e32aa'
// deployContract((err, tx) => {
cmdLine.startDebug(tx, shortFilename)
cmdLine.events.on('source', () => {
cmdLine.getSource().forEach(console.dir)
})
// })
// })
const repl = require('repl')
repl.start({
prompt: '> ',
eval: (cmd, context, filename, cb) => {
let command = cmd.trim()
if (command === 'next' || command === 'n') {
cmdLine.stepOverForward(true)
}
if (command === 'previous' || command === 'p' || command === 'prev') {
cmdLine.stepOverBack(true)
}
if (command === 'step' || command === 's') {
cmdLine.stepIntoForward(true)
}
if (command === 'stepback' || command === 'sb') {
cmdLine.stepIntoBack(true)
}
if (command === 'exit' || command === 'quit') {
process.exit(0)
}
if (command === 'var local' || command === 'v l' || command === 'vl') {
cmdLine.displayLocals()
}
if (command === 'var global' || command === 'v g' || command === 'vg') {
cmdLine.displayGlobals()
}
if (command.split(' ')[0] === 'jump') {
let stepIndex = parseInt(command.split(' ')[1], 10)
cmdLine.jumpTo(stepIndex)
}
cb(null, '')
}
})
module.exports = cmdLine
...@@ -183,7 +183,6 @@ Ethdebugger.prototype.debug = function (tx) { ...@@ -183,7 +183,6 @@ Ethdebugger.prototype.debug = function (tx) {
tx.to = traceHelper.contractCreationToken('0') tx.to = traceHelper.contractCreationToken('0')
} }
this.setCompilationResult(this.opts.compilationResult()) this.setCompilationResult(this.opts.compilationResult())
console.log('loading trace...')
this.tx = tx this.tx = tx
var self = this var self = this
this.traceManager.resolveTrace(tx, function (error, result) { this.traceManager.resolveTrace(tx, function (error, result) {
......
var remixLib = require('remix-lib')
var EventManager = remixLib.EventManager
var executionContext = remixLib.execution.executionContext
var Web3Providers = remixLib.vm.Web3Providers
var DummyProvider = remixLib.vm.DummyProvider
var init = remixLib.init
class ContextManager {
constructor () {
this.executionContext = executionContext
this.web3 = this.executionContext.web3()
this.event = new EventManager()
}
initProviders () {
this.web3Providers = new Web3Providers()
this.addProvider('DUMMYWEB3', new DummyProvider())
this.switchProvider('DUMMYWEB3')
this.addProvider('vm', this.executionContext.vm())
this.addProvider('injected', this.executionContext.internalWeb3())
this.addProvider('web3', this.executionContext.internalWeb3())
this.switchProvider(this.executionContext.getProvider())
}
getWeb3 () {
return this.web3
}
addProvider (type, obj) {
this.web3Providers.addProvider(type, obj)
this.event.trigger('providerAdded', [type])
}
switchProvider (type, cb) {
var self = this
this.web3Providers.get(type, function (error, obj) {
if (error) {
// console.log('provider ' + type + ' not defined')
} else {
self.web3 = obj
self.executionContext.detectNetwork((error, network) => {
if (error || !network) {
self.web3 = obj
} else {
var webDebugNode = init.web3DebugNode(network.name)
self.web3 = (!webDebugNode ? obj : webDebugNode)
}
self.event.trigger('providerChanged', [type, self.web3])
if (cb) return cb()
})
self.event.trigger('providerChanged', [type, self.web3])
}
})
}
}
module.exports = ContextManager
var Web3 = require('web3')
var Debugger = require('../debugger/debugger.js')
var ContextManager = require('./contextManager.js')
var EventManager = require('events')
class CmdLine {
constructor () {
this.events = new EventManager()
this.lineColumnPos = null
this.rawLocation = null
}
connect (providerType, url) {
if (providerType !== 'http') throw new Error('unsupported provider type')
this.web3 = new Web3(new Web3.providers.HttpProvider(url))
}
loadCompilationData (inputJson, outputJson) {
let data = {}
data.data = outputJson
data.source = { sources: inputJson.sources }
this.loadCompilationResult(data)
}
loadCompilationResult (compilationResult) {
this.compilation = {}
this.compilation.lastCompilationResult = compilationResult
}
initDebugger (cb) {
const self = this
this.contextManager = new ContextManager()
this.debugger = new Debugger({
web3: this.contextManager.getWeb3(),
compiler: this.compilation
})
this.contextManager.event.register('providerChanged', () => {
self.debugger.updateWeb3(self.contextManager.getWeb3())
})
this.contextManager.initProviders()
this.contextManager.addProvider('debugger_web3', this.web3)
this.contextManager.switchProvider('debugger_web3', cb)
}
getSource () {
const self = this
let lineColumnPos = this.lineColumnPos
if (!lineColumnPos || !lineColumnPos.start) return []
let content = self.compilation.lastCompilationResult.source.sources[this.filename].content.split('\n')
let source = []
let line
line = content[lineColumnPos.start.line - 2]
if (line !== undefined) {
source.push(' ' + (lineColumnPos.start.line - 1) + ': ' + line)
}
line = content[lineColumnPos.start.line - 1]
if (line !== undefined) {
source.push(' ' + lineColumnPos.start.line + ': ' + line)
}
let currentLineNumber = lineColumnPos.start.line
let currentLine = content[currentLineNumber]
source.push('=> ' + (currentLineNumber + 1) + ': ' + currentLine)
let startLine = lineColumnPos.start.line
for (var i = 1; i < 4; i++) {
let line = content[startLine + i]
source.push(' ' + (startLine + i + 1) + ': ' + line)
}
return source
}
getCurrentLine () {
let lineColumnPos = this.lineColumnPos
if (!lineColumnPos) return ''
let currentLineNumber = lineColumnPos.start.line
let content = this.compilation.lastCompilationResult.source.sources[this.filename].content.split('\n')
return content[currentLineNumber]
}
startDebug (txNumber, filename, cb) {
const self = this
this.filename = filename
this.txHash = txNumber
this.debugger.debug(null, txNumber, null, () => {
self.debugger.event.register('newSourceLocation', function (lineColumnPos, rawLocation) {
self.lineColumnPos = lineColumnPos
self.rawLocation = rawLocation
self.events.emit('source', [lineColumnPos, rawLocation])
})
self.debugger.vmDebuggerLogic.event.register('solidityState', (data) => {
self.solidityState = data
self.events.emit('globals', data)
})
// TODO: this doesnt work too well, it should request the data instead...
self.debugger.vmDebuggerLogic.event.register('solidityLocals', (data) => {
if (JSON.stringify(data) === '{}') return
self.solidityLocals = data
self.events.emit('locals', data)
})
if (cb) {
// TODO: this should be an onReady event
setTimeout(cb, 1000)
}
})
}
getVars () {
return {
locals: this.solidityLocals,
contract: this.solidityState
}
}
triggerSourceUpdate () {
this.events.emit('source', [this.lineColumnPos, this.rawLocation])
}
stepJumpNextBreakpoint () {
this.debugger.step_manager.jumpNextBreakpoint()
}
stepJumpPreviousBreakpoint () {
this.debugger.step_manager.jumpPreviousBreakpoint()
}
stepOverForward (solidityMode) {
this.debugger.step_manager.stepOverForward(solidityMode)
}
stepOverBack (solidityMode) {
this.debugger.step_manager.stepOverBack(solidityMode)
}
stepIntoForward (solidityMode) {
this.debugger.step_manager.stepIntoForward(solidityMode)
}
stepIntoBack (solidityMode) {
this.debugger.step_manager.stepIntoBack(solidityMode)
}
jumpTo (step) {
this.debugger.step_manager.jumpTo(step)
}
getTraceLength () {
if (!this.debugger.step_manager) return 0
return this.debugger.step_manager.traceLength
}
getCodeFirstStep () {
if (!this.debugger.step_manager) return 0
return this.debugger.step_manager.calculateFirstStep()
}
getCodeTraceLength () {
if (!this.debugger.step_manager) return 0
return this.debugger.step_manager.calculateCodeLength()
}
nextStep () {
if (!this.debugger.step_manager) return 0
return this.debugger.step_manager.nextStep()
}
previousStep () {
if (!this.debugger.step_manager) return 0
return this.debugger.step_manager.previousStep()
}
currentStep () {
if (!this.debugger.step_manager) return 0
return this.debugger.step_manager.currentStepIndex
}
canGoNext () {
return this.currentStep() < this.getCodeTraceLength()
}
canGoPrevious () {
return this.currentStep() > this.getCodeFirstStep()
}
unload () {
return this.debugger.unload()
}
displayLocals () {
console.dir('= displayLocals')
console.dir(this.solidityLocals)
}
displayGlobals () {
console.dir('= displayGlobals')
console.dir(this.solidityState)
}
}
module.exports = CmdLine
...@@ -64,7 +64,7 @@ class VmDebuggerLogic { ...@@ -64,7 +64,7 @@ class VmDebuggerLogic {
self._traceManager.getCallDataAt(index, function (error, calldata) { self._traceManager.getCallDataAt(index, function (error, calldata) {
if (error) { if (error) {
console.log(error) // console.log(error)
self.event.trigger('traceManagerCallDataUpdate', [{}]) self.event.trigger('traceManagerCallDataUpdate', [{}])
} else if (self.stepManager.currentStepIndex === index) { } else if (self.stepManager.currentStepIndex === index) {
self.event.trigger('traceManagerCallDataUpdate', [calldata]) self.event.trigger('traceManagerCallDataUpdate', [calldata])
...@@ -73,7 +73,7 @@ class VmDebuggerLogic { ...@@ -73,7 +73,7 @@ class VmDebuggerLogic {
self._traceManager.getMemoryAt(index, function (error, memory) { self._traceManager.getMemoryAt(index, function (error, memory) {
if (error) { if (error) {
console.log(error) // console.log(error)
self.event.trigger('traceManagerMemoryUpdate', [{}]) self.event.trigger('traceManagerMemoryUpdate', [{}])
} else if (self.stepManager.currentStepIndex === index) { } else if (self.stepManager.currentStepIndex === index) {
self.event.trigger('traceManagerMemoryUpdate', [ui.formatMemory(memory, 16)]) self.event.trigger('traceManagerMemoryUpdate', [ui.formatMemory(memory, 16)])
...@@ -82,7 +82,7 @@ class VmDebuggerLogic { ...@@ -82,7 +82,7 @@ class VmDebuggerLogic {
self._traceManager.getCallStackAt(index, function (error, callstack) { self._traceManager.getCallStackAt(index, function (error, callstack) {
if (error) { if (error) {
console.log(error) // console.log(error)
self.event.trigger('traceManagerCallStackUpdate', [{}]) self.event.trigger('traceManagerCallStackUpdate', [{}])
} else if (self.stepManager.currentStepIndex === index) { } else if (self.stepManager.currentStepIndex === index) {
self.event.trigger('traceManagerCallStackUpdate', [callstack]) self.event.trigger('traceManagerCallStackUpdate', [callstack])
...@@ -91,7 +91,7 @@ class VmDebuggerLogic { ...@@ -91,7 +91,7 @@ class VmDebuggerLogic {
self._traceManager.getStackAt(index, function (error, callstack) { self._traceManager.getStackAt(index, function (error, callstack) {
if (error) { if (error) {
console.log(error) // console.log(error)
self.event.trigger('traceManagerStackUpdate', [{}]) self.event.trigger('traceManagerStackUpdate', [{}])
} else if (self.stepManager.currentStepIndex === index) { } else if (self.stepManager.currentStepIndex === index) {
self.event.trigger('traceManagerStackUpdate', [callstack]) self.event.trigger('traceManagerStackUpdate', [callstack])
...@@ -106,7 +106,7 @@ class VmDebuggerLogic { ...@@ -106,7 +106,7 @@ class VmDebuggerLogic {
storageViewer.storageRange((error, storage) => { storageViewer.storageRange((error, storage) => {
if (error) { if (error) {
console.log(error) // console.log(error)
self.event.trigger('traceManagerStorageUpdate', [{}]) self.event.trigger('traceManagerStorageUpdate', [{}])
} else if (self.stepManager.currentStepIndex === index) { } else if (self.stepManager.currentStepIndex === index) {
var header = storageViewer.isComplete(address) ? 'completely loaded' : 'partially loaded...' var header = storageViewer.isComplete(address) ? 'completely loaded' : 'partially loaded...'
......
...@@ -3,6 +3,7 @@ var Ethdebugger = require('../Ethdebugger') ...@@ -3,6 +3,7 @@ var Ethdebugger = require('../Ethdebugger')
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
var EventManager = remixLib.EventManager var EventManager = remixLib.EventManager
var traceHelper = remixLib.helpers.trace var traceHelper = remixLib.helpers.trace
var OffsetToColumnConverter = remixLib.OffsetToColumnConverter
var StepManager = require('./stepManager') var StepManager = require('./stepManager')
var VmDebuggerLogic = require('./VmDebugger') var VmDebuggerLogic = require('./VmDebugger')
...@@ -11,7 +12,7 @@ function Debugger (options) { ...@@ -11,7 +12,7 @@ function Debugger (options) {
var self = this var self = this
this.event = new EventManager() this.event = new EventManager()
this.offsetToLineColumnConverter = options.offsetToLineColumnConverter this.offsetToLineColumnConverter = options.offsetToLineColumnConverter || (new OffsetToColumnConverter())
this.compiler = options.compiler this.compiler = options.compiler
this.debugger = new Ethdebugger({ this.debugger = new Ethdebugger({
...@@ -111,8 +112,13 @@ Debugger.prototype.debugTx = function (tx, loadingCb) { ...@@ -111,8 +112,13 @@ Debugger.prototype.debugTx = function (tx, loadingCb) {
}) })
this.vmDebuggerLogic = new VmDebuggerLogic(this.debugger, tx, this.step_manager, this.debugger.traceManager, this.debugger.codeManager, this.debugger.solidityProxy, this.debugger.callTree) this.vmDebuggerLogic = new VmDebuggerLogic(this.debugger, tx, this.step_manager, this.debugger.traceManager, this.debugger.codeManager, this.debugger.solidityProxy, this.debugger.callTree)
this.vmDebuggerLogic.start()
this.step_manager.event.register('stepChanged', this, function (stepIndex) { this.step_manager.event.register('stepChanged', this, function (stepIndex) {
if (!stepIndex) {
return self.event.trigger('endDebug')
}
self.debugger.codeManager.resolveStep(stepIndex, tx) self.debugger.codeManager.resolveStep(stepIndex, tx)
self.step_manager.event.trigger('indexChanged', [stepIndex]) self.step_manager.event.trigger('indexChanged', [stepIndex])
self.vmDebuggerLogic.event.trigger('indexChanged', [stepIndex]) self.vmDebuggerLogic.event.trigger('indexChanged', [stepIndex])
......
...@@ -40,7 +40,7 @@ class DebuggerSolidityLocals { ...@@ -40,7 +40,7 @@ class DebuggerSolidityLocals {
self.stepManager.currentStepIndex, self.stepManager.currentStepIndex,
(error, result) => { (error, result) => {
if (error) { if (error) {
return console.log(error) return error
} }
var stack = result[0].value var stack = result[0].value
var memory = result[1].value var memory = result[1].value
......
...@@ -36,7 +36,13 @@ class DebuggerSolidityState { ...@@ -36,7 +36,13 @@ class DebuggerSolidityState {
} }
self.event.trigger('solidityStateUpdating') self.event.trigger('solidityStateUpdating')
decodeTimeout = setTimeout(function () { decodeTimeout = setTimeout(function () {
self.decode(index) // necessary due to some states that can crash the debugger
try {
self.decode(index)
} catch (err) {
console.dir('====> error')
console.dir(err)
}
}, 500) }, 500)
} }
......
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
var EventManager = remixLib.EventManager var EventManager = remixLib.EventManager
var util = remixLib.util
class DebuggerStepManager { class DebuggerStepManager {
...@@ -9,6 +10,7 @@ class DebuggerStepManager { ...@@ -9,6 +10,7 @@ class DebuggerStepManager {
this.traceManager = traceManager this.traceManager = traceManager
this.currentStepIndex = 0 this.currentStepIndex = 0
this.traceLength = 0 this.traceLength = 0
this.codeTraceLength = 0
this.revertionPoint = null this.revertionPoint = null
this.listenToEvents() this.listenToEvents()
...@@ -25,6 +27,7 @@ class DebuggerStepManager { ...@@ -25,6 +27,7 @@ class DebuggerStepManager {
if (self.traceLength !== newLength) { if (self.traceLength !== newLength) {
self.event.trigger('traceLengthChanged', [newLength]) self.event.trigger('traceLengthChanged', [newLength])
self.traceLength = newLength self.traceLength = newLength
self.codeTraceLength = self.calculateCodeLength()
} }
self.jumpTo(0) self.jumpTo(0)
}) })
...@@ -81,43 +84,58 @@ class DebuggerStepManager { ...@@ -81,43 +84,58 @@ class DebuggerStepManager {
}) })
} }
stepIntoBack () { stepIntoBack (solidityMode) {
if (!this.traceManager.isLoaded()) return if (!this.traceManager.isLoaded()) return
var step = this.currentStepIndex - 1 var step = this.currentStepIndex - 1
this.currentStepIndex = step this.currentStepIndex = step
if (solidityMode) {
step = this.resolveToReducedTrace(step, -1)
}
if (!this.traceManager.inRange(step)) { if (!this.traceManager.inRange(step)) {
return return
} }
this.event.trigger('stepChanged', [step]) this.event.trigger('stepChanged', [step])
} }
stepIntoForward () { stepIntoForward (solidityMode) {
if (!this.traceManager.isLoaded()) return if (!this.traceManager.isLoaded()) return
var step = this.currentStepIndex + 1 var step = this.currentStepIndex + 1
this.currentStepIndex = step this.currentStepIndex = step
if (solidityMode) {
step = this.resolveToReducedTrace(step, 1)
}
if (!this.traceManager.inRange(step)) { if (!this.traceManager.inRange(step)) {
return return
} }
this.event.trigger('stepChanged', [step]) this.event.trigger('stepChanged', [step])
} }
stepOverBack () { stepOverBack (solidityMode) {
if (!this.traceManager.isLoaded()) return if (!this.traceManager.isLoaded()) return
var step = this.traceManager.findStepOverBack(this.currentStepIndex) var step = this.traceManager.findStepOverBack(this.currentStepIndex)
if (solidityMode) {
step = this.resolveToReducedTrace(step, -1)
}
this.currentStepIndex = step this.currentStepIndex = step
this.event.trigger('stepChanged', [step]) this.event.trigger('stepChanged', [step])
} }
stepOverForward () { stepOverForward (solidityMode) {
if (!this.traceManager.isLoaded()) return if (!this.traceManager.isLoaded()) return
var step = this.traceManager.findStepOverForward(this.currentStepIndex) var step = this.traceManager.findStepOverForward(this.currentStepIndex)
if (solidityMode) {
step = this.resolveToReducedTrace(step, 1)
}
this.currentStepIndex = step this.currentStepIndex = step
this.event.trigger('stepChanged', [step]) this.event.trigger('stepChanged', [step])
} }
jumpOut () { jumpOut (solidityMode) {
if (!this.traceManager.isLoaded()) return if (!this.traceManager.isLoaded()) return
var step = this.traceManager.findStepOut(this.currentStepIndex) var step = this.traceManager.findStepOut(this.currentStepIndex)
if (solidityMode) {
step = this.resolveToReducedTrace(step, 0)
}
this.currentStepIndex = step this.currentStepIndex = step
this.event.trigger('stepChanged', [step]) this.event.trigger('stepChanged', [step])
} }
...@@ -140,6 +158,51 @@ class DebuggerStepManager { ...@@ -140,6 +158,51 @@ class DebuggerStepManager {
this.debugger.breakpointManager.jumpPreviousBreakpoint(this.currentStepIndex, true) this.debugger.breakpointManager.jumpPreviousBreakpoint(this.currentStepIndex, true)
} }
calculateFirstStep () {
let step = this.resolveToReducedTrace(0, 1)
return this.resolveToReducedTrace(step, 1)
}
calculateCodeStepList () {
let step = 0
let steps = []
while (step < this.traceLength) {
let _step = this.resolveToReducedTrace(step, 1)
if (!_step) break
steps.push(_step)
step += 1
}
steps = steps.filter((item, pos, self) => { return steps.indexOf(item) === pos })
return steps
}
calculateCodeLength () {
this.calculateCodeStepList().reverse()
return this.calculateCodeStepList().reverse()[1] || this.traceLength
}
nextStep () {
return this.resolveToReducedTrace(this.currentStepIndex, 1)
}
previousStep () {
return this.resolveToReducedTrace(this.currentStepIndex, -1)
}
resolveToReducedTrace (value, incr) {
if (this.debugger.callTree.reducedTrace.length) {
var nextSource = util.findClosestIndex(value, this.debugger.callTree.reducedTrace)
nextSource = nextSource + incr
if (nextSource <= 0) {
nextSource = 0
} else if (nextSource > this.debugger.callTree.reducedTrace.length) {
nextSource = this.debugger.callTree.reducedTrace.length - 1
}
return this.debugger.callTree.reducedTrace[nextSource]
}
return value
}
} }
module.exports = DebuggerStepManager module.exports = DebuggerStepManager
...@@ -38,7 +38,6 @@ class InternalCallTree { ...@@ -38,7 +38,6 @@ class InternalCallTree {
if (result.error) { if (result.error) {
this.event.trigger('callTreeBuildFailed', [result.error]) this.event.trigger('callTreeBuildFailed', [result.error])
} else { } else {
console.log('ready')
createReducedTrace(this, traceManager.trace.length - 1) createReducedTrace(this, traceManager.trace.length - 1)
this.event.trigger('callTreeReady', [this.scopes, this.scopeStarts]) this.event.trigger('callTreeReady', [this.scopes, this.scopeStarts])
} }
...@@ -230,7 +229,7 @@ function resolveVariableDeclaration (tree, step, sourceLocation) { ...@@ -230,7 +229,7 @@ function resolveVariableDeclaration (tree, step, sourceLocation) {
if (ast) { if (ast) {
tree.variableDeclarationByFile[sourceLocation.file] = extractVariableDeclarations(ast, tree.astWalker) tree.variableDeclarationByFile[sourceLocation.file] = extractVariableDeclarations(ast, tree.astWalker)
} else { } else {
console.log('Ast not found for step ' + step + '. file ' + sourceLocation.file) // console.log('Ast not found for step ' + step + '. file ' + sourceLocation.file)
return null return null
} }
} }
...@@ -243,7 +242,7 @@ function resolveFunctionDefinition (tree, step, sourceLocation) { ...@@ -243,7 +242,7 @@ function resolveFunctionDefinition (tree, step, sourceLocation) {
if (ast) { if (ast) {
tree.functionDefinitionByFile[sourceLocation.file] = extractFunctionDefinitions(ast, tree.astWalker) tree.functionDefinitionByFile[sourceLocation.file] = extractFunctionDefinitions(ast, tree.astWalker)
} else { } else {
console.log('Ast not found for step ' + step + '. file ' + sourceLocation.file) // console.log('Ast not found for step ' + step + '. file ' + sourceLocation.file)
return null return null
} }
} }
......
...@@ -117,7 +117,7 @@ class SolidityProxy { ...@@ -117,7 +117,7 @@ class SolidityProxy {
if (this.sources[file]) { if (this.sources[file]) {
return this.sources[file].legacyAST return this.sources[file].legacyAST
} else { } else {
console.log('AST not found for file id ' + sourceLocation.file) // console.log('AST not found for file id ' + sourceLocation.file)
return null return null
} }
} }
......
pragma solidity ^0.4.0;
contract Ballot {
struct Voter {
uint weight;
bool voted;
uint8 vote;
address delegate;
}
struct Proposal {
uint voteCount;
}
address chairperson;
mapping(address => Voter) voters;
Proposal[] proposals;
/// Create a new ballot with $(_numProposals) different proposals.
function Ballot(uint8 _numProposals) public {
chairperson = msg.sender;
voters[chairperson].weight = 1;
proposals.length = _numProposals;
}
/// Give $(toVoter) the right to vote on this ballot.
/// May only be called by $(chairperson).
function giveRightToVote(address toVoter) public {
if (msg.sender != chairperson || voters[toVoter].voted) return;
voters[toVoter].weight = 1;
}
/// Delegate your vote to the voter $(to).
function delegate(address to) public {
Voter storage sender = voters[msg.sender]; // assigns reference
if (sender.voted) return;
while (voters[to].delegate != address(0) && voters[to].delegate != msg.sender)
to = voters[to].delegate;
if (to == msg.sender) return;
sender.voted = true;
sender.delegate = to;
Voter storage delegateTo = voters[to];
if (delegateTo.voted)
proposals[delegateTo.vote].voteCount += sender.weight;
else
delegateTo.weight += sender.weight;
}
/// Give a single vote to proposal $(toProposal).
function vote(uint8 toProposal) public {
Voter storage sender = voters[msg.sender];
if (sender.voted || toProposal >= proposals.length) return;
sender.voted = true;
sender.vote = toProposal;
proposals[toProposal].voteCount += sender.weight;
}
function winningProposal() public constant returns (uint8 _winningProposal) {
uint256 winningVoteCount = 0;
for (uint8 prop = 0; prop < proposals.length; prop++)
if (proposals[prop].voteCount > winningVoteCount) {
winningVoteCount = proposals[prop].voteCount;
_winningProposal = prop;
}
}
}
pragma solidity ^0.4.25;
contract SimpleStorage {
uint public storedData;
address owner;
constructor(uint initialValue) public {
storedData = initialValue;
owner = msg.sender;
}
function set(uint x) public {
storedData = x;
require(msg.sender != owner);
storedData = x + 2;
}
function get() public view returns (uint retVal) {
return storedData;
}
}
...@@ -5,6 +5,7 @@ var uiHelper = require('./src/helpers/uiHelper') ...@@ -5,6 +5,7 @@ var uiHelper = require('./src/helpers/uiHelper')
var compilerHelper = require('./src/helpers/compilerHelper') var compilerHelper = require('./src/helpers/compilerHelper')
var SourceMappingDecoder = require('./src/sourceMappingDecoder') var SourceMappingDecoder = require('./src/sourceMappingDecoder')
var SourceLocationTracker = require('./src/sourceLocationTracker') var SourceLocationTracker = require('./src/sourceLocationTracker')
var OffsetToColumnConverter = require('./src/offsetToLineColumnConverter')
var init = require('./src/init') var init = require('./src/init')
var util = require('./src/util') var util = require('./src/util')
var Web3Providers = require('./src/web3Provider/web3Providers') var Web3Providers = require('./src/web3Provider/web3Providers')
...@@ -56,6 +57,7 @@ function modules () { ...@@ -56,6 +57,7 @@ function modules () {
}, },
SourceMappingDecoder: SourceMappingDecoder, SourceMappingDecoder: SourceMappingDecoder,
SourceLocationTracker: SourceLocationTracker, SourceLocationTracker: SourceLocationTracker,
OffsetToColumnConverter: OffsetToColumnConverter,
Storage: Storage, Storage: Storage,
init: init, init: init,
util: util, util: util,
......
...@@ -29,7 +29,6 @@ CodeResolver.prototype.resolveCode = function (address, callBack) { ...@@ -29,7 +29,6 @@ CodeResolver.prototype.resolveCode = function (address, callBack) {
} }
CodeResolver.prototype.loadCode = function (address, callback) { CodeResolver.prototype.loadCode = function (address, callback) {
console.log('loading new code from web3 ' + address)
this.web3.eth.getCode(address, function (error, result) { this.web3.eth.getCode(address, function (error, result) {
if (error) { if (error) {
console.log(error) console.log(error)
......
'use strict'
var SourceMappingDecoder = require('./sourceMappingDecoder')
function offsetToColumnConverter (compilerEvent) {
this.lineBreakPositionsByContent = {}
this.sourceMappingDecoder = new SourceMappingDecoder()
var self = this
if (compilerEvent) {
compilerEvent.register('compilationFinished', function (success, data, source) {
self.clear()
})
}
}
offsetToColumnConverter.prototype.offsetToLineColumn = function (rawLocation, file, sources, asts) {
if (!this.lineBreakPositionsByContent[file]) {
for (var filename in asts) {
var source = asts[filename]
if (source.id === file) {
this.lineBreakPositionsByContent[file] = this.sourceMappingDecoder.getLinebreakPositions(sources[filename].content)
break
}
}
}
return this.sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, this.lineBreakPositionsByContent[file])
}
offsetToColumnConverter.prototype.clear = function () {
this.lineBreakPositionsByContent = {}
}
module.exports = offsetToColumnConverter
...@@ -120,7 +120,7 @@ TraceManager.prototype.getStackAt = function (stepIndex, callback) { ...@@ -120,7 +120,7 @@ TraceManager.prototype.getStackAt = function (stepIndex, callback) {
return callback(check, null) return callback(check, null)
} }
var stack var stack
if (this.trace[stepIndex].stack) { // there's always a stack if (this.trace[stepIndex] && this.trace[stepIndex].stack) { // there's always a stack
stack = this.trace[stepIndex].stack.slice(0) stack = this.trace[stepIndex].stack.slice(0)
stack.reverse() stack.reverse()
callback(null, stack) callback(null, stack)
......
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