Commit 7ff2e3fa authored by yann300's avatar yann300

group API

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