Merge pull request #1425 from ethereum/librarieDeployCustom

Json file include network id
pull/1/head
yann300 6 years ago committed by GitHub
commit 19e62c9f19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      .circleci/config.yml
  2. 96
      src/app/files/compiler-metadata.js

@ -26,10 +26,10 @@ jobs:
- checkout
- restore_cache:
keys:
- dep-bundle-16-{{ checksum "package.json" }}
- dep-bundle-17-{{ checksum "package.json" }}
- run: npm install
- save_cache:
key: dep-bundle-16-{{ checksum "package.json" }}
key: dep-bundle-17-{{ checksum "package.json" }}
paths:
- ~/repo/node_modules
- run: npm run lint && npm run test && npm run downloadsolc && npm run make-mock-compiler && npm run build
@ -46,10 +46,10 @@ jobs:
- checkout
- restore_cache:
keys:
- dep-bundle-11-{{ checksum "package.json" }}
- dep-bundle-12-{{ checksum "package.json" }}
- run: npm install
- save_cache:
key: dep-bundle-11-{{ checksum "package.json" }}
key: dep-bundle-12-{{ checksum "package.json" }}
paths:
- ~/repo/node_modules
- run: npm run build_debugger

@ -1,65 +1,83 @@
'use strict'
var executionContext = require('../../execution-context')
class CompilerMetadata {
constructor (events, opts) {
var self = this
self._events = events
self._opts = opts
self.networks = ['VM:-', 'main:1', 'ropsten:3', 'rinkeby:4', 'kovan:42']
}
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']
var autoDeployLib = metadata['autoDeployLib']
if (!linkReferences) linkReferences = {}
if (autoDeployLib === undefined) autoDeployLib = true
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
metadata['autoDeployLib'] = autoDeployLib
provider.set(fileName, JSON.stringify(metadata, null, '\t'))
if (!success) return
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)
}
})
self.networks.forEach((network) => {
metadata[network] = self._syncContext(contract, metadata[network] || {})
})
provider.set(fileName, JSON.stringify(metadata, null, '\t'))
}
})
}
})
}
})
}
_syncContext (contract, metadata) {
var linkReferences = metadata['linkReferences']
var autoDeployLib = metadata['autoDeployLib']
if (!linkReferences) linkReferences = {}
if (autoDeployLib === undefined) autoDeployLib = true
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
metadata['autoDeployLib'] = autoDeployLib
return metadata
}
metadataOf (contractName, callback) {
var self = this
var provider = self._opts.fileManager.currentFileProvider()
var path = self._opts.fileManager.currentPath()
if (provider && path) {
var fileName = path + '/' + contractName + '.json'
provider.get(fileName, (error, content) => {
if (error) return callback(error)
try {
callback(null, JSON.parse(content))
} catch (e) {
callback(e.message)
executionContext.detectNetwork((err, { id, name } = {}) => {
if (err) {
console.log(err)
} else {
var fileName = path + '/' + contractName + '.json'
provider.get(fileName, (error, content) => {
if (error) return callback(error)
try {
var metadata = JSON.parse(content)
return callback(null, metadata[name + ':' + id] || metadata[name] || metadata[id])
} catch (e) {
callback(e.message)
}
})
}
})
}

Loading…
Cancel
Save