Merge pull request #1551 from ethereum/addNewCompilationMetadata

Contract metadata
pull/3094/head
yann300 6 years ago committed by GitHub
commit 11f25faf61
  1. 21
      src/app/files/compiler-metadata.js
  2. 2
      src/app/tabs/run-tab.js
  3. 6
      test-browser/tests/simpleContract.js

@ -18,6 +18,8 @@ class CompilerMetadata {
var path = self._opts.fileManager.currentPath() var path = self._opts.fileManager.currentPath()
if (provider && path) { if (provider && path) {
self._opts.compiler.visitContracts((contract) => { self._opts.compiler.visitContracts((contract) => {
if (contract.file !== source.target) return
var fileName = path + '/' + contract.name + '.json' var fileName = path + '/' + contract.name + '.json'
provider.get(fileName, (error, content) => { provider.get(fileName, (error, content) => {
if (!error) { if (!error) {
@ -29,11 +31,23 @@ class CompilerMetadata {
console.log(e) console.log(e)
} }
var deploy = metadata.deploy || {}
self.networks.forEach((network) => { self.networks.forEach((network) => {
metadata[network] = self._syncContext(contract, metadata[network] || {}) deploy[network] = self._syncContext(contract, deploy[network] || {})
}) })
provider.set(fileName, JSON.stringify(metadata, null, '\t')) var data = {
deploy,
data: {
bytecode: contract.object.evm.bytecode,
deployedBytecode: contract.object.evm.deployedBytecode,
gasEstimates: contract.object.evm.gasEstimates,
methodIdentifiers: contract.object.evm.methodIdentifiers
},
abi: contract.object.abi
}
provider.set(fileName, JSON.stringify(data, null, '\t'))
} }
}) })
}) })
@ -60,7 +74,7 @@ class CompilerMetadata {
return metadata return metadata
} }
metadataOf (contractName, callback) { deployMetadataOf (contractName, callback) {
var self = this var self = this
var provider = self._opts.fileManager.currentFileProvider() var provider = self._opts.fileManager.currentFileProvider()
var path = self._opts.fileManager.currentPath() var path = self._opts.fileManager.currentPath()
@ -75,6 +89,7 @@ class CompilerMetadata {
if (!content) return callback() if (!content) return callback()
try { try {
var metadata = JSON.parse(content) var metadata = JSON.parse(content)
metadata = metadata.deploy || {}
return callback(null, metadata[name + ':' + id] || metadata[name] || metadata[id] || metadata[name.toLowerCase() + ':' + id] || metadata[name.toLowerCase()]) return callback(null, metadata[name + ':' + id] || metadata[name] || metadata[id] || metadata[name.toLowerCase() + ':' + id] || metadata[name.toLowerCase()])
} catch (e) { } catch (e) {
callback(e.message) callback(e.message)

@ -440,7 +440,7 @@ function contractDropdown (events, self) {
var forceSend = () => { var forceSend = () => {
var constructor = txHelper.getConstructorInterface(selectedContract.contract.object.abi) var constructor = txHelper.getConstructorInterface(selectedContract.contract.object.abi)
self._deps.filePanel.compilerMetadata().metadataOf(selectedContract.name, (error, contractMetadata) => { self._deps.filePanel.compilerMetadata().deployMetadataOf(selectedContract.name, (error, contractMetadata) => {
if (error) return self._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error) if (error) return self._deps.logCallback(`creation of ${selectedContract.name} errored: ` + error)
if (!contractMetadata || (contractMetadata && contractMetadata.autoDeployLib)) { if (!contractMetadata || (contractMetadata && contractMetadata.autoDeployLib)) {
txFormat.buildData(selectedContract.name, selectedContract.contract.object, compiler.getContracts(), true, constructor, args, (error, data) => { txFormat.buildData(selectedContract.name, selectedContract.contract.object, compiler.getContracts(), true, constructor, args, (error, data) => {

@ -118,7 +118,7 @@ function checkDeployShouldFail (browser, callback) {
contractHelper.switchFile(browser, 'browser/test.json', () => { contractHelper.switchFile(browser, 'browser/test.json', () => {
browser.getEditorValue((content) => { browser.getEditorValue((content) => {
var config = JSON.parse(content) var config = JSON.parse(content)
config['VM:-'].autoDeployLib = false config.deploy['VM:-'].autoDeployLib = false
browser.setEditorValue(JSON.stringify(config), () => { browser.setEditorValue(JSON.stringify(config), () => {
contractHelper.switchFile(browser, 'browser/Untitled5.sol', () => { contractHelper.switchFile(browser, 'browser/Untitled5.sol', () => {
contractHelper.selectContract(browser, 'test', () => { // deploy lib contractHelper.selectContract(browser, 'test', () => { // deploy lib
@ -136,8 +136,8 @@ function checkDeployShouldSucceed (browser, address, callback) {
contractHelper.switchFile(browser, 'browser/test.json', () => { contractHelper.switchFile(browser, 'browser/test.json', () => {
browser.getEditorValue((content) => { browser.getEditorValue((content) => {
var config = JSON.parse(content) var config = JSON.parse(content)
config['VM:-'].autoDeployLib = false config.deploy['VM:-'].autoDeployLib = false
config['VM:-']['linkReferences']['browser/Untitled5.sol'].lib = address config.deploy['VM:-']['linkReferences']['browser/Untitled5.sol'].lib = address
browser.setEditorValue(JSON.stringify(config), () => { browser.setEditorValue(JSON.stringify(config), () => {
contractHelper.switchFile(browser, 'browser/Untitled5.sol', () => { contractHelper.switchFile(browser, 'browser/Untitled5.sol', () => {
contractHelper.selectContract(browser, 'test', () => { // deploy lib contractHelper.selectContract(browser, 'test', () => { // deploy lib

Loading…
Cancel
Save