Commit d72551df authored by yann300's avatar yann300

turn property compilationResult into an async callback

parent 8c6da69a
...@@ -29,9 +29,7 @@ const EventManager = remixLib.EventManager ...@@ -29,9 +29,7 @@ const EventManager = remixLib.EventManager
* @param {Map} opts - { function compilationResult } // * @param {Map} opts - { function compilationResult } //
*/ */
function Ethdebugger (opts) { function Ethdebugger (opts) {
this.opts = opts || {} this.compilationResult = opts.compilationResult || function (contractAddress) { return null }
if (!this.opts.compilationResult) this.opts.compilationResult = () => { return null }
this.web3 = opts.web3 this.web3 = opts.web3
this.event = new EventManager() this.event = new EventManager()
...@@ -60,8 +58,8 @@ Ethdebugger.prototype.resolveStep = function (index) { ...@@ -60,8 +58,8 @@ Ethdebugger.prototype.resolveStep = function (index) {
} }
Ethdebugger.prototype.setCompilationResult = function (compilationResult) { Ethdebugger.prototype.setCompilationResult = function (compilationResult) {
if (compilationResult && compilationResult.sources && compilationResult.contracts) { if (compilationResult && compilationResult.data) {
this.solidityProxy.reset(compilationResult) this.solidityProxy.reset(compilationResult.data)
} else { } else {
this.solidityProxy.reset({}) this.solidityProxy.reset({})
} }
...@@ -173,10 +171,10 @@ Ethdebugger.prototype.debug = function (tx) { ...@@ -173,10 +171,10 @@ Ethdebugger.prototype.debug = function (tx) {
if (!tx.to) { if (!tx.to) {
tx.to = traceHelper.contractCreationToken('0') tx.to = traceHelper.contractCreationToken('0')
} }
this.setCompilationResult(this.opts.compilationResult())
this.tx = tx this.tx = tx
this.traceManager.resolveTrace(tx, (error, result) => { this.traceManager.resolveTrace(tx, async (error, result) => {
if (result) { if (result) {
this.setCompilationResult(await this.compilationResult(tx.to))
this.event.trigger('newTraceLoaded', [this.traceManager.trace]) this.event.trigger('newTraceLoaded', [this.traceManager.trace])
if (this.breakpointManager && this.breakpointManager.hasBreakpoint()) { if (this.breakpointManager && this.breakpointManager.hasBreakpoint()) {
this.breakpointManager.jumpNextBreakpoint(false) this.breakpointManager.jumpNextBreakpoint(false)
......
...@@ -28,7 +28,7 @@ class CmdLine { ...@@ -28,7 +28,7 @@ class CmdLine {
loadCompilationResult (compilationResult) { loadCompilationResult (compilationResult) {
this.compilation = {} this.compilation = {}
this.compilation.lastCompilationResult = compilationResult this.compilation.compilationResult = compilationResult
} }
initDebugger (cb) { initDebugger (cb) {
...@@ -36,7 +36,7 @@ class CmdLine { ...@@ -36,7 +36,7 @@ class CmdLine {
this.debugger = new Debugger({ this.debugger = new Debugger({
web3: this.contextManager.getWeb3(), web3: this.contextManager.getWeb3(),
compiler: this.compilation compilationResult: () => { return this.compilation.compilationResult }
}) })
this.contextManager.event.register('providerChanged', () => { this.contextManager.event.register('providerChanged', () => {
...@@ -54,7 +54,7 @@ class CmdLine { ...@@ -54,7 +54,7 @@ class CmdLine {
if (!lineColumnPos || !lineColumnPos.start) return [] if (!lineColumnPos || !lineColumnPos.start) return []
const content = this.compilation.lastCompilationResult.source.sources[this.filename].content.split('\n') const content = this.compilation.compilationResult.source.sources[this.filename].content.split('\n')
const source = [] const source = []
...@@ -85,7 +85,7 @@ class CmdLine { ...@@ -85,7 +85,7 @@ class CmdLine {
const lineColumnPos = this.lineColumnPos const lineColumnPos = this.lineColumnPos
if (!lineColumnPos) return '' if (!lineColumnPos) return ''
const currentLineNumber = lineColumnPos.start.line const currentLineNumber = lineColumnPos.start.line
const content = this.compilation.lastCompilationResult.source.sources[this.filename].content.split('\n') const content = this.compilation.compilationResult.source.sources[this.filename].content.split('\n')
return content[currentLineNumber] return content[currentLineNumber]
} }
......
...@@ -12,21 +12,19 @@ function Debugger (options) { ...@@ -12,21 +12,19 @@ function Debugger (options) {
this.event = new EventManager() this.event = new EventManager()
this.offsetToLineColumnConverter = options.offsetToLineColumnConverter || (new OffsetToColumnConverter()) this.offsetToLineColumnConverter = options.offsetToLineColumnConverter || (new OffsetToColumnConverter())
this.compiler = options.compiler /*
Returns a compilation result for a given address or the last one available if none are found
*/
this.compilationResult = options.compilationResult || function (contractAddress) { return null }
this.debugger = new Ethdebugger({ this.debugger = new Ethdebugger({
web3: options.web3, web3: options.web3,
compilationResult: () => { compilationResult: this.compilationResult
var compilationResult = this.compiler.lastCompilationResult
if (compilationResult) {
return compilationResult.data
}
return null
}
}) })
this.breakPointManager = new remixLib.code.BreakpointManager(this.debugger, (sourceLocation) => { this.breakPointManager = new remixLib.code.BreakpointManager(this.debugger, async (sourceLocation) => {
return this.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, this.compiler.lastCompilationResult.source.sources, this.compiler.lastCompilationResult.data.sources) const compilationResult = await this.compilationResult()
return this.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, compilationResult.source.sources, compilationResult.data.sources)
}, (step) => { }, (step) => {
this.event.trigger('breakpointStep', [step]) this.event.trigger('breakpointStep', [step])
}) })
...@@ -48,12 +46,12 @@ function Debugger (options) { ...@@ -48,12 +46,12 @@ function Debugger (options) {
Debugger.prototype.registerAndHighlightCodeItem = function (index) { Debugger.prototype.registerAndHighlightCodeItem = function (index) {
// register selected code item, highlight the corresponding source location // register selected code item, highlight the corresponding source location
if (!this.compiler.lastCompilationResult) return this.debugger.traceManager.getCurrentCalledAddressAt(index, async (error, address) => {
this.debugger.traceManager.getCurrentCalledAddressAt(index, (error, address) => {
if (error) return console.log(error) if (error) return console.log(error)
this.debugger.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, index, this.compiler.lastCompilationResult.data.contracts, (error, rawLocation) => { const compilationResultForAddress = await this.compilationResult(address)
if (!error && this.compiler.lastCompilationResult && this.compiler.lastCompilationResult.data) { this.debugger.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, index, compilationResultForAddress.data.contracts, (error, rawLocation) => {
var lineColumnPos = this.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, this.compiler.lastCompilationResult.source.sources, this.compiler.lastCompilationResult.data.sources) if (!error && compilationResultForAddress && compilationResultForAddress.data) {
var lineColumnPos = this.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, compilationResultForAddress.source.sources, compilationResultForAddress.data.sources)
this.event.trigger('newSourceLocation', [lineColumnPos, rawLocation]) this.event.trigger('newSourceLocation', [lineColumnPos, rawLocation])
} else { } else {
this.event.trigger('newSourceLocation', [null]) this.event.trigger('newSourceLocation', [null])
...@@ -112,7 +110,7 @@ Debugger.prototype.debugTx = function (tx, loadingCb) { ...@@ -112,7 +110,7 @@ Debugger.prototype.debugTx = function (tx, loadingCb) {
this.vmDebuggerLogic.event.trigger('sourceLocationChanged', [sourceLocation]) this.vmDebuggerLogic.event.trigger('sourceLocationChanged', [sourceLocation])
} }
}) })
}) })
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.vmDebuggerLogic.start()
......
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