From f6ebee85e67159bf3a425485ea2de7ff96cd1c14 Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 22 Aug 2018 18:35:34 +0200 Subject: [PATCH] option for generating metadata --- src/app/files/compiler-metadata.js | 2 ++ src/app/panels/file-panel.js | 3 ++- src/app/tabs/run-tab.js | 1 + src/app/tabs/settings-tab.js | 11 ++++++++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/app/files/compiler-metadata.js b/src/app/files/compiler-metadata.js index c9932d5900..2c660133a2 100644 --- a/src/app/files/compiler-metadata.js +++ b/src/app/files/compiler-metadata.js @@ -13,6 +13,7 @@ class CompilerMetadata { var self = this self._events.compiler.register('compilationFinished', (success, data, source) => { if (!success) return + if (!self._opts.config.get('settings/generate-contract-metadata')) return var provider = self._opts.fileManager.currentFileProvider() var path = self._opts.fileManager.currentPath() if (provider && path) { @@ -71,6 +72,7 @@ class CompilerMetadata { var fileName = path + '/' + contractName + '.json' provider.get(fileName, (error, content) => { if (error) return callback(error) + if (!content) return callback() try { var metadata = JSON.parse(content) return callback(null, metadata[name + ':' + id] || metadata[name] || metadata[id] || metadata[name.toLowerCase() + ':' + id] || metadata[name.toLowerCase()]) diff --git a/src/app/panels/file-panel.js b/src/app/panels/file-panel.js index 3a59bf4a91..51e8caff67 100644 --- a/src/app/panels/file-panel.js +++ b/src/app/panels/file-panel.js @@ -68,7 +68,8 @@ function filepanel (localRegistry) { }, { fileManager: self._deps.fileManager, - compiler: self._deps.compiler + compiler: self._deps.compiler, + config: self._deps.config } ) self._compilerMetadata.syncContractMetadata() diff --git a/src/app/tabs/run-tab.js b/src/app/tabs/run-tab.js index 92ccf86a02..c94e8ea996 100644 --- a/src/app/tabs/run-tab.js +++ b/src/app/tabs/run-tab.js @@ -397,6 +397,7 @@ function contractDropdown (events, self) { self._deps.udapp.runTx(data, runTxCallback) }) } else { + if (Object.keys(selectedContract.contract.object.evm.bytecode.linkReferences).length) self._deps.logCallback(`linking ${JSON.stringify(selectedContract.contract.object.evm.bytecode.linkReferences, null, '\t')} using ${JSON.stringify(contractMetadata.linkReferences, null, '\t')}`) txFormat.encodeConstructorCallAndLinkLibraries(selectedContract.contract.object, args, constructor, contractMetadata.linkReferences, selectedContract.contract.object.evm.bytecode.linkReferences, (error, data) => { createInstanceCallback(error, selectedContract, data) }) diff --git a/src/app/tabs/settings-tab.js b/src/app/tabs/settings-tab.js index 71cf9757f8..0053a2c205 100644 --- a/src/app/tabs/settings-tab.js +++ b/src/app/tabs/settings-tab.js @@ -26,7 +26,7 @@ module.exports = class SettingsTab { } self._view = { /* eslint-disable */ el: null, - optionVM: null, personal: null, warnPersonalMode: null, + optionVM: null, personal: null, warnPersonalMode: null, generateContractMetadata: null, pluginInput: null, versionSelector: null, version: null, theme: { dark: null, light: null }, plugins: {}, @@ -62,6 +62,8 @@ module.exports = class SettingsTab { It is not recommended (and also most likely not relevant) to use this mode with an injected provider (Mist, Metamask, ...) or with JavaScript VM. Remix never persist any passphrase.`.split('\n').map(s => s.trim()).join(' ') self._view.warnPersonalMode = yo`` + self._view.generateContractMetadata = yo`` + if (self._deps.config.get('settings/generate-contract-metadata')) self._view.generateContractMetadata.setAttribute('checked', '') self._view.pluginInput = yo`` self._view.theme.light = yo`` @@ -71,6 +73,10 @@ module.exports = class SettingsTab { self._view.config.general = yo`
General settings
+
+
${self._view.generateContractMetadata}
+ Generate contract metadata. Generate a JSON file in the contract folder. Allows to specify library addresses the contract depends on. If nothing is specified, Remix deploy libraries automatically. +
${self._view.optionVM}
Always use Ethereum VM at Load @@ -176,6 +182,9 @@ module.exports = class SettingsTab { loadPlugins([json], {removable: true}) } + function onchangeGenerateContractMetadata (event) { + self._deps.config.set('settings/generate-contract-metadata', !self._deps.config.get('settings/generate-contract-metadata')) + } function onchangeOption (event) { self._deps.config.set('settings/always-use-vm', !self._deps.config.get('settings/always-use-vm')) }