add compiler metadata

pull/1/head
yann300 7 years ago
parent 9ceb133c72
commit e343fe45bc
  1. 49
      src/app/files/compiler-metadata.js
  2. 8
      src/app/files/fileManager.js
  3. 16
      src/app/panels/file-panel.js

@ -0,0 +1,49 @@
'use strict'
class CompilerMetadata {
constructor (events, opts) {
var self = this
self._events = events
self._opts = opts
}
syncContractMetadata () {
var self = this
self._events.compiler.register('compilationFinished', (success, data, source) => {
if (success) {
var provider = self._opts.fileManager.currentFileProvider()
var path = self._opts.fileManager.currentPath()
if (provider && path) {
self._opts.compiler.visitContracts((contract) => {
var fileName = path + contract.name + '.json'
provider.get(fileName, (error, content) => {
if (!error) {
content = content || '{}'
var metadata
try {
metadata = JSON.parse(content)
} catch (e) {
console.log(e)
}
var linkReferences = metadata['linkReferences']
if (!linkReferences) linkReferences = {}
for (var libFile in contract.object.evm.bytecode.linkReferences) {
if (!linkReferences[libFile]) linkReferences[libFile] = {}
for (var lib in contract.object.evm.bytecode.linkReferences[libFile]) {
if (!linkReferences[libFile][lib]) {
linkReferences[libFile][lib] = '<address>'
}
}
}
metadata['linkReferences'] = linkReferences
provider.set(fileName, JSON.stringify(metadata, null, '\t'))
}
})
})
}
}
})
}
}
module.exports = CompilerMetadata

@ -71,6 +71,14 @@ class FileManager {
this.refreshTabs()
}
currentFileProvider () {
var path = this.currentPath()
if (path) {
return this.fileProviderOf(path)
}
return null
}
currentPath () {
var self = this
var currentFile = self._deps.config.get('currentFile')

@ -2,6 +2,7 @@
var async = require('async')
var $ = require('jquery')
var yo = require('yo-yo')
var CompilerMetadata = require('../files/compiler-metadata')
var remixLib = require('remix-lib')
var Gists = require('gists')
var EventManager = remixLib.EventManager
@ -48,7 +49,8 @@ function filepanel (localRegistry) {
self._deps = {
fileProviders: self._components.registry.get('fileproviders').api,
fileManager: self._components.registry.get('filemanager').api,
config: self._components.registry.get('config').api
config: self._components.registry.get('config').api,
compiler: self._components.registry.get('compiler').api
}
var fileExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['browser'])
var fileSystemExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['localhost'])
@ -57,6 +59,18 @@ function filepanel (localRegistry) {
var gistExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['gist'])
var configExplorer = new FileExplorer(self._components.registry, self._deps.fileProviders['config'])
// ----------------- editor panel ----------------------
self._compilerMetadata = new CompilerMetadata(
{
compiler: self._deps.compiler.event
},
{
fileManager: self._deps.fileManager,
compiler: self._deps.compiler
}
)
self._compilerMetadata.syncContractMetadata()
var dragbar = yo`<div onmousedown=${mousedown} class=${css.dragbar}></div>`
function remixdDialog () {

Loading…
Cancel
Save