Commit 7ff2e3fa authored by yann300's avatar yann300

group API

parent 39704974
...@@ -494,39 +494,10 @@ var run = function () { ...@@ -494,39 +494,10 @@ var run = function () {
var executionContext = new ExecutionContext() var executionContext = new ExecutionContext()
var compiler = new Compiler(handleImportCall) var compiler = new Compiler(handleImportCall)
var formalVerification = new FormalVerification($('#verificationView'), compiler.event) var formalVerification = new FormalVerification($('#verificationView'), compiler.event)
var offsetToLineColumnConverter = new OffsetToLineColumnConverter(compiler.event) var offsetToLineColumnConverter = new OffsetToLineColumnConverter(compiler.event)
var contentToolAPI = { // ----------------- Debugger -----------------
offsetToLineColumn: (location, file) => { var debugAPI = {
return offsetToLineColumnConverter.offsetToLineColumn(location, file, compiler.lastCompilationResult)
}
}
var transactionContextAPI = {
getAddress: (cb) => {
cb(null, $('#txorigin').val())
},
getValue: (cb) => {
try {
var comp = $('#value').val().split(' ')
cb(null, executionContext.web3().toWei(comp[0], comp.slice(1).join(' ')))
} catch (e) {
cb(e)
}
},
getGasLimit: (cb) => {
cb(null, $('#gasLimit').val())
}
}
var compilerAPI = {
lastCompilationResult: () => {
return compiler.lastCompilationResult
}
}
var editorAPIDebug = {
statementMarker: null, statementMarker: null,
fullLineMarker: null, fullLineMarker: null,
currentSourceLocation: (lineColumnPos, location) => { currentSourceLocation: (lineColumnPos, location) => {
...@@ -554,37 +525,49 @@ var run = function () { ...@@ -554,37 +525,49 @@ var run = function () {
}, 'highlightcode_fullLine') }, 'highlightcode_fullLine')
} }
} }
},
lastCompilationResult: () => {
return compiler.lastCompilationResult
},
offsetToLineColumn: (location, file) => {
return offsetToLineColumnConverter.offsetToLineColumn(location, file, compiler.lastCompilationResult)
} }
} }
var transactionDebugger = new Debugger('#debugger', debugAPI, executionContext.event, editor.event)
var transactionDebugger = new Debugger('#debugger', executionContext.event, editor.event, editorAPIDebug, compilerAPI, contentToolAPI)
transactionDebugger.addProvider('vm', executionContext.vm()) transactionDebugger.addProvider('vm', executionContext.vm())
transactionDebugger.addProvider('injected', executionContext.web3()) transactionDebugger.addProvider('injected', executionContext.web3())
transactionDebugger.addProvider('web3', executionContext.web3()) transactionDebugger.addProvider('web3', executionContext.web3())
transactionDebugger.switchProvider(executionContext.getProvider()) transactionDebugger.switchProvider(executionContext.getProvider())
// ----------------- UniversalDApp -----------------
var udapp = new UniversalDApp(executionContext, { var udapp = new UniversalDApp(executionContext, {
removable: false, removable: false,
removable_instances: true removable_instances: true
}, transactionDebugger) })
var udappAPI = { udapp.event.register('debugRequested', this, function (txResult) {
reset: (udappContracts, renderOutputModifier) => { startdebugging(txResult.transactionHash)
udapp.reset(udappContracts, transactionContextAPI, renderOutputModifier) })
// ----------------- Renderer -----------------
var transactionContextAPI = {
getAddress: (cb) => {
cb(null, $('#txorigin').val())
}, },
render: () => { getValue: (cb) => {
return udapp.render() try {
var comp = $('#value').val().split(' ')
cb(null, executionContext.web3().toWei(comp[0], comp.slice(1).join(' ')))
} catch (e) {
cb(e)
}
}, },
getAccounts: (callback) => { getGasLimit: (cb) => {
udapp.getAccounts(callback) cb(null, $('#gasLimit').val())
} }
} }
udapp.event.register('debugRequested', this, function (txResult) { var rendererAPI = {
startdebugging(txResult.transactionHash)
})
var editorAPIRenderer = {
error: (file, error) => { error: (file, error) => {
if (file === editor.getCacheFile()) { if (file === editor.getCacheFile()) {
editor.addAnnotation(error) editor.addAnnotation(error)
...@@ -601,18 +584,32 @@ var run = function () { ...@@ -601,18 +584,32 @@ var run = function () {
return compiler.lastCompilationResult.source.sources[compiler.lastCompilationResult.source.target] return compiler.lastCompilationResult.source.sources[compiler.lastCompilationResult.source.target]
} }
return '' return ''
},
resetDapp: (udappContracts, renderOutputModifier) => {
udapp.reset(udappContracts, transactionContextAPI, renderOutputModifier)
},
renderDapp: () => {
return udapp.render()
},
getAccounts: (callback) => {
udapp.getAccounts(callback)
} }
} }
var renderer = new Renderer(editorAPIRenderer, udappAPI, formalVerification.event, compiler.event) // eslint-disable-line var renderer = new Renderer(rendererAPI, formalVerification.event, compiler.event)
var rendererAPI = {
renderItem: (label, warningContainer, type) => { // ----------------- StaticAnalysis -----------------
var staticAnalysisAPI = {
renderWarning: (label, warningContainer, type) => {
return renderer.error(label, warningContainer, type) return renderer.error(label, warningContainer, type)
},
offsetToLineColumn: (location, file) => {
return offsetToLineColumnConverter.offsetToLineColumn(location, file, compiler.lastCompilationResult)
} }
} }
var staticanalysis = new StaticAnalysis(staticAnalysisAPI, compiler.event)
var staticanalysis = new StaticAnalysis(compiler.event, rendererAPI, contentToolAPI)
$('#staticanalysisView').append(staticanalysis.render()) $('#staticanalysisView').append(staticanalysis.render())
// ----------------- autoCompile -----------------
var autoCompile = document.querySelector('#autoCompile').checked var autoCompile = document.querySelector('#autoCompile').checked
if (config.exists('autoCompile')) { if (config.exists('autoCompile')) {
autoCompile = config.get('autoCompile') autoCompile = config.get('autoCompile')
......
...@@ -5,14 +5,12 @@ var remix = require('ethereum-remix') ...@@ -5,14 +5,12 @@ var remix = require('ethereum-remix')
/** /**
* Manage remix and source highlighting * Manage remix and source highlighting
*/ */
function Debugger (id, executionContextEvent, editorEvent, editorAPI, compilerAPI, contentToolAPI) { function Debugger (id, appAPI, executionContextEvent, editorEvent) {
this.el = document.querySelector(id) this.el = document.querySelector(id)
this.contentToolAPI = contentToolAPI
this.debugger = new remix.ui.Debugger() this.debugger = new remix.ui.Debugger()
this.sourceMappingDecoder = new remix.util.SourceMappingDecoder() this.sourceMappingDecoder = new remix.util.SourceMappingDecoder()
this.el.appendChild(this.debugger.render()) this.el.appendChild(this.debugger.render())
this.compilerAPI = compilerAPI this.appAPI = appAPI
this.editorAPI = editorAPI
var self = this var self = this
executionContextEvent.register('contextChanged', this, function (context) { executionContextEvent.register('contextChanged', this, function (context) {
...@@ -20,7 +18,7 @@ function Debugger (id, executionContextEvent, editorEvent, editorAPI, compilerAP ...@@ -20,7 +18,7 @@ function Debugger (id, executionContextEvent, editorEvent, editorAPI, compilerAP
}) })
this.debugger.event.register('traceUnloaded', this, function () { this.debugger.event.register('traceUnloaded', this, function () {
self.editorAPI.currentSourceLocation(null) self.appAPI.currentSourceLocation(null)
}) })
// unload if a file has changed (but not if tabs were switched) // unload if a file has changed (but not if tabs were switched)
...@@ -30,13 +28,13 @@ function Debugger (id, executionContextEvent, editorEvent, editorAPI, compilerAP ...@@ -30,13 +28,13 @@ function Debugger (id, executionContextEvent, editorEvent, editorAPI, compilerAP
// register selected code item, highlight the corresponding source location // register selected code item, highlight the corresponding source location
this.debugger.codeManager.event.register('changed', this, function (code, address, index) { this.debugger.codeManager.event.register('changed', this, function (code, address, index) {
if (self.compilerAPI.lastCompilationResult()) { if (self.appAPI.lastCompilationResult()) {
this.debugger.callTree.sourceLocationTracker.getSourceLocationFromInstructionIndex(address, index, self.compilerAPI.lastCompilationResult().data.contracts, function (error, rawLocation) { this.debugger.callTree.sourceLocationTracker.getSourceLocationFromInstructionIndex(address, index, self.appAPI.lastCompilationResult().data.contracts, function (error, rawLocation) {
if (!error) { if (!error) {
var lineColumnPos = self.contentToolAPI.offsetToLineColumn(rawLocation, rawLocation.file) var lineColumnPos = self.appAPI.offsetToLineColumn(rawLocation, rawLocation.file)
self.editorAPI.currentSourceLocation(lineColumnPos, rawLocation) self.appAPI.currentSourceLocation(lineColumnPos, rawLocation)
} else { } else {
self.editorAPI.currentSourceLocation(null) self.appAPI.currentSourceLocation(null)
} }
}) })
} }
...@@ -52,7 +50,7 @@ Debugger.prototype.debug = function (txHash) { ...@@ -52,7 +50,7 @@ Debugger.prototype.debug = function (txHash) {
var self = this var self = this
this.debugger.web3().eth.getTransaction(txHash, function (error, tx) { this.debugger.web3().eth.getTransaction(txHash, function (error, tx) {
if (!error) { if (!error) {
self.debugger.setCompilationResult(self.compilerAPI.lastCompilationResult().data) self.debugger.setCompilationResult(self.appAPI.lastCompilationResult().data)
self.debugger.debug(tx) self.debugger.debug(tx)
} }
}) })
......
...@@ -4,9 +4,8 @@ var $ = require('jquery') ...@@ -4,9 +4,8 @@ var $ = require('jquery')
var utils = require('./utils') var utils = require('./utils')
function Renderer (editorAPI, udappAPI, formalVerificationEvent, compilerEvent) { function Renderer (appAPI, formalVerificationEvent, compilerEvent) {
this.editorAPI = editorAPI this.appAPI = appAPI
this.udappAPI = udappAPI
var self = this var self = this
formalVerificationEvent.register('compilationFinished', this, function (success, message, container, options) { formalVerificationEvent.register('compilationFinished', this, function (success, message, container, options) {
if (!success) { if (!success) {
...@@ -54,7 +53,7 @@ Renderer.prototype.error = function (message, container, options) { ...@@ -54,7 +53,7 @@ Renderer.prototype.error = function (message, container, options) {
var errLine = parseInt(err[2], 10) - 1 var errLine = parseInt(err[2], 10) - 1
var errCol = err[4] ? parseInt(err[4], 10) : 0 var errCol = err[4] ? parseInt(err[4], 10) : 0
if (!opt.noAnnotations) { if (!opt.noAnnotations) {
self.editorAPI.error(errFile, { self.appAPI.error(errFile, {
row: errLine, row: errLine,
column: errCol, column: errCol,
text: message, text: message,
...@@ -62,7 +61,7 @@ Renderer.prototype.error = function (message, container, options) { ...@@ -62,7 +61,7 @@ Renderer.prototype.error = function (message, container, options) {
}) })
} }
$error.click(function (ev) { $error.click(function (ev) {
self.editorAPI.errorClick(errFile, errLine, errCol) self.appAPI.errorClick(errFile, errLine, errCol)
}) })
} }
$error.find('.close').click(function (ev) { $error.find('.close').click(function (ev) {
...@@ -275,20 +274,20 @@ Renderer.prototype.contracts = function (data, source) { ...@@ -275,20 +274,20 @@ Renderer.prototype.contracts = function (data, source) {
} }
} }
var ctrSource = self.editorAPI.currentCompiledSourceCode() var ctrSource = self.appAPI.currentCompiledSourceCode()
if (ctrSource) { if (ctrSource) {
$contractOutput.append(getDetails(contract, ctrSource, contractName)) $contractOutput.append(getDetails(contract, ctrSource, contractName))
} }
return $contractOutput return $contractOutput
} }
this.udappAPI.reset(udappContracts, renderOutputModifier) this.appAPI.resetDapp(udappContracts, renderOutputModifier)
var $contractOutput = this.udappAPI.render() var $contractOutput = this.appAPI.renderDapp()
var $txOrigin = $('#txorigin') var $txOrigin = $('#txorigin')
this.udappAPI.getAccounts(function (err, accounts) { this.appAPI.getAccounts(function (err, accounts) {
if (err) { if (err) {
self.error(err.message) self.error(err.message)
} }
......
...@@ -3,13 +3,12 @@ var StaticAnalysisRunner = require('./staticAnalysisRunner.js') ...@@ -3,13 +3,12 @@ var StaticAnalysisRunner = require('./staticAnalysisRunner.js')
var yo = require('yo-yo') var yo = require('yo-yo')
var $ = require('jquery') var $ = require('jquery')
function staticAnalysisView (compilerEvent, rendererAPI, contentToolAPI) { function staticAnalysisView (appAPI, compilerEvent) {
this.view = null this.view = null
this.rendererAPI = rendererAPI this.appAPI = appAPI
this.runner = new StaticAnalysisRunner() this.runner = new StaticAnalysisRunner()
this.modulesView = renderModules(this.runner.modules()) this.modulesView = renderModules(this.runner.modules())
this.lastCompilationResult = null this.lastCompilationResult = null
this.contentToolAPI = contentToolAPI
var self = this var self = this
compilerEvent.register('compilationFinished', function (success, data, source) { compilerEvent.register('compilationFinished', function (success, data, source) {
self.lastCompilationResult = null self.lastCompilationResult = null
...@@ -74,10 +73,10 @@ staticAnalysisView.prototype.run = function () { ...@@ -74,10 +73,10 @@ staticAnalysisView.prototype.run = function () {
start: parseInt(split[0]), start: parseInt(split[0]),
length: parseInt(split[1]) length: parseInt(split[1])
} }
location = self.contentToolAPI.offsetToLineColumn(location, file) location = self.appAPI.offsetToLineColumn(location, file)
location = self.lastCompilationResult.sourceList[file] + ':' + (location.start.line + 1) + ':' + (location.start.column + 1) + ':' location = self.lastCompilationResult.sourceList[file] + ':' + (location.start.line + 1) + ':' + (location.start.column + 1) + ':'
} }
self.rendererAPI.renderItem(location + ' ' + item.warning, warningContainer, {type: 'warning', useSpan: true, isHTML: true}) self.appAPI.renderWarning(location + ' ' + item.warning, warningContainer, {type: 'warning', useSpan: true, isHTML: true})
}) })
}) })
if (warningContainer.html() === '') { if (warningContainer.html() === '') {
......
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