Merge pull request #1511 from ethereum/variousFixes2

Various fixes
pull/1/head
yann300 6 years ago committed by GitHub
commit c263a39c5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/app/compiler/compiler-imports.js
  2. 31
      src/app/contract/publishOnSwarm.js
  3. 4
      src/app/files/browser-files-tree.js
  4. 7
      src/app/files/browser-files.js
  5. 16
      src/app/files/fileManager.js
  6. 20
      src/app/plugin/pluginAPI.js
  7. 7
      src/app/tabs/compile-tab.js
  8. 2
      src/lib/cmdInterpreterAPI.js
  9. 1
      test-browser/plugin/index.html
  10. 5
      test-browser/plugin/plugin.js

@ -68,7 +68,7 @@ module.exports = class CompilerImports {
{ type: 'github', match: /^(https?:\/\/)?(www.)?github.com\/([^/]*\/[^/]*)\/(.*)/, handler: (match, cb) => { this.handleGithubCall(match[3], match[4], cb) } }, { type: 'github', match: /^(https?:\/\/)?(www.)?github.com\/([^/]*\/[^/]*)\/(.*)/, handler: (match, cb) => { this.handleGithubCall(match[3], match[4], cb) } },
{ type: 'http', match: /^(http?:\/\/?(.*))$/, handler: (match, cb) => { this.handleHttpCall(match[1], match[2], cb) } }, { type: 'http', match: /^(http?:\/\/?(.*))$/, handler: (match, cb) => { this.handleHttpCall(match[1], match[2], cb) } },
{ type: 'https', match: /^(https?:\/\/?(.*))$/, handler: (match, cb) => { this.handleHttpCall(match[1], match[2], cb) } }, { type: 'https', match: /^(https?:\/\/?(.*))$/, handler: (match, cb) => { this.handleHttpCall(match[1], match[2], cb) } },
{ type: 'swarm', match: /^(bzz[ri]?:\/\/?(.*))$/, handler: (match, cb) => { this.handleSwarmImport(match[1], match[2], cb) } }, { type: 'swarm', match: /^(bzz-raw?:\/\/?(.*))$/, handler: (match, cb) => { this.handleSwarmImport(match[1], match[2], cb) } },
{ type: 'ipfs', match: /^(ipfs:\/\/?.+)/, handler: (match, cb) => { this.handleIPFS(match[1], cb) } } { type: 'ipfs', match: /^(ipfs:\/\/?.+)/, handler: (match, cb) => { this.handleIPFS(match[1], cb) } }
] ]
} }

@ -7,11 +7,6 @@ module.exports = (contract, fileManager, cb, swarmVerifiedPublishCallBack) => {
// gather list of files to publish // gather list of files to publish
var sources = [] var sources = []
sources.push({
content: contract.metadata,
hash: contract.metadataHash
})
var metadata var metadata
try { try {
metadata = JSON.parse(contract.metadata) metadata = JSON.parse(contract.metadata)
@ -38,7 +33,8 @@ module.exports = (contract, fileManager, cb, swarmVerifiedPublishCallBack) => {
} else { } else {
sources.push({ sources.push({
content: content, content: content,
hash: hash hash: hash,
filename: fileName
}) })
} }
cb() cb()
@ -48,12 +44,27 @@ module.exports = (contract, fileManager, cb, swarmVerifiedPublishCallBack) => {
cb(error) cb(error)
} else { } else {
// publish the list of sources in order, fail if any failed // publish the list of sources in order, fail if any failed
var uploaded = []
async.eachSeries(sources, function (item, cb) { async.eachSeries(sources, function (item, cb) {
swarmVerifiedPublish(item.content, item.hash, (error) => { swarmVerifiedPublish(item.content, item.hash, (error, result) => {
if (!error && swarmVerifiedPublishCallBack) swarmVerifiedPublishCallBack(item) if (!error && swarmVerifiedPublishCallBack) swarmVerifiedPublishCallBack(item)
item.output = result
uploaded.push(item)
// TODO this is a fix cause Solidity metadata does not contain the right swarm hash (poc 0.3)
metadata.sources[item.filename].urls[0] = result.url
cb(error) cb(error)
}) })
}, cb) }, () => {
swarmVerifiedPublish(JSON.stringify(metadata), '', (error, result) => {
uploaded.push({
content: contract.metadata,
hash: contract.metadataHash,
filename: 'metadata.json',
output: result
})
cb(error, uploaded)
})
})
} }
}) })
} }
@ -63,9 +74,9 @@ function swarmVerifiedPublish (content, expectedHash, cb) {
if (err) { if (err) {
cb(err) cb(err)
} else if (ret !== expectedHash) { } else if (ret !== expectedHash) {
cb('Hash mismatch') cb(null, { message: 'hash mismatch between solidity bytecode and uploaded content.', url: 'bzz-raw://' + ret, hash: ret })
} else { } else {
cb() cb(null, { message: 'ok', url: 'bzz-raw://' + ret, hash: ret })
} }
}) })
} }

@ -53,11 +53,12 @@ function FilesTree (name, storage) {
return content return content
} }
this.set = function (path, content) { this.set = function (path, content, cb) {
var unprefixedpath = this.removePrefix(path) var unprefixedpath = this.removePrefix(path)
updateRefs(unprefixedpath, 'add') updateRefs(unprefixedpath, 'add')
var exists = storage.exists(unprefixedpath) var exists = storage.exists(unprefixedpath)
if (!storage.set(unprefixedpath, content)) { if (!storage.set(unprefixedpath, content)) {
if (cb) cb('error updating ' + path)
return false return false
} }
if (!exists) { if (!exists) {
@ -65,6 +66,7 @@ function FilesTree (name, storage) {
} else { } else {
event.trigger('fileChanged', [this.type + '/' + unprefixedpath]) event.trigger('fileChanged', [this.type + '/' + unprefixedpath])
} }
if (cb) cb()
return true return true
} }

@ -38,16 +38,18 @@ function Files (storage) {
return content return content
} }
this.set = function (path, content) { this.set = function (path, content, cb) {
var unprefixedpath = this.removePrefix(path) var unprefixedpath = this.removePrefix(path)
// NOTE: ignore the config file // NOTE: ignore the config file
if (path === '.remix.config') { if (path === '.remix.config') {
if (cb) cb('change not allowed')
return false return false
} }
if (!this.isReadOnly(unprefixedpath)) { if (!this.isReadOnly(unprefixedpath)) {
var exists = storage.exists(unprefixedpath) var exists = storage.exists(unprefixedpath)
if (!storage.set(unprefixedpath, content)) { if (!storage.set(unprefixedpath, content)) {
if (cb) cb('error updating ' + path)
return false return false
} }
if (!exists) { if (!exists) {
@ -55,9 +57,10 @@ function Files (storage) {
} else { } else {
event.trigger('fileChanged', [this.type + '/' + unprefixedpath]) event.trigger('fileChanged', [this.type + '/' + unprefixedpath])
} }
if (cb) cb()
return true return true
} }
if (cb) cb('is read only')
return false return false
} }

@ -195,6 +195,22 @@ class FileManager {
} }
} }
} }
syncEditor (path) {
var self = this
var currentFile = this._deps.config.get('currentFile')
if (path !== currentFile) return
var provider = this.fileProviderOf(currentFile)
if (provider) {
provider.get(currentFile, (error, content) => {
if (error) console.log(error)
self._deps.editor.setText(content)
})
} else {
console.log('cannot save ' + currentFile + '. Does not belong to any explorer')
}
}
} }
module.exports = FileManager module.exports = FileManager

@ -48,7 +48,11 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) =>
}, },
udapp: { udapp: {
runTx: (mod, tx, cb) => { runTx: (mod, tx, cb) => {
if (executionContext.getProvider() !== 'vm') return cb('plugin API does not allow sending a transaction through a web3 connection. Only vm mode is allowed') executionContext.detectNetwork((error, network) => {
if (error) return cb(error)
if (network.name === 'Main' && network.id === '1') {
return cb('It is not allowed to make this action against mainnet')
}
udapp.silentRunTx(tx, (error, result) => { udapp.silentRunTx(tx, (error, result) => {
if (error) return cb(error) if (error) return cb(error)
cb(null, { cb(null, {
@ -60,10 +64,16 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) =>
createdAddress: result.result.createdAddress ? '0x' + result.result.createdAddress.toString('hex') : undefined createdAddress: result.result.createdAddress ? '0x' + result.result.createdAddress.toString('hex') : undefined
}) })
}) })
})
}, },
getAccounts: (mod, cb) => { getAccounts: (mod, cb) => {
if (executionContext.getProvider() !== 'vm') return cb('plugin API does not allow retrieving accounts through a web3 connection. Only vm mode is allowed') executionContext.detectNetwork((error, network) => {
if (error) return cb(error)
if (network.name === 'Main' && network.id === '1') {
return cb('It is not allowed to make this action against mainnet')
}
udapp.getAccounts(cb) udapp.getAccounts(cb)
})
}, },
createVMAccount: (mod, privateKey, balance, cb) => { createVMAccount: (mod, privateKey, balance, cb) => {
if (executionContext.getProvider() !== 'vm') return cb('plugin API does not allow creating a new account through web3 connection. Only vm mode is allowed') if (executionContext.getProvider() !== 'vm') return cb('plugin API does not allow creating a new account through web3 connection. Only vm mode is allowed')
@ -73,6 +83,9 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) =>
} }
}, },
editor: { editor: {
getFilesFromPath: (mod, path, cb) => {
fileManager.filesFromPath(path, cb)
},
getCurrentFile: (mod, cb) => { getCurrentFile: (mod, cb) => {
var path = fileManager.currentFile() var path = fileManager.currentFile()
if (!path) { if (!path) {
@ -97,7 +110,8 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) =>
if (provider) { if (provider) {
// TODO add approval to user for external plugin to set the content of the given `path` // TODO add approval to user for external plugin to set the content of the given `path`
provider.set(path, content, (error) => { provider.set(path, content, (error) => {
cb(error) if (error) return cb(error)
fileManager.syncEditor(path)
}) })
} else { } else {
cb(path + ' not available') cb(path + ' not available')

@ -365,7 +365,7 @@ module.exports = class CompileTab {
if (contract.metadata === undefined || contract.metadata.length === 0) { if (contract.metadata === undefined || contract.metadata.length === 0) {
modalDialogCustom.alert('This contract does not implement all functions and thus cannot be published.') modalDialogCustom.alert('This contract does not implement all functions and thus cannot be published.')
} else { } else {
publishOnSwarm(contract, self._deps.fileManager, function (err) { publishOnSwarm(contract, self._deps.fileManager, function (err, uploaded) {
if (err) { if (err) {
try { try {
err = JSON.stringify(err) err = JSON.stringify(err)
@ -373,7 +373,10 @@ module.exports = class CompileTab {
modalDialogCustom.alert(yo`<span>Failed to publish metadata file to swarm, please check the Swarm gateways is available ( swarm-gateways.net ).<br /> modalDialogCustom.alert(yo`<span>Failed to publish metadata file to swarm, please check the Swarm gateways is available ( swarm-gateways.net ).<br />
${err}</span>`) ${err}</span>`)
} else { } else {
modalDialogCustom.alert(yo`<span>Metadata published successfully.<br />The Swarm address of the metadata file is available in the contract details.</span>`) var result = yo`<div>${uploaded.map((value) => {
return yo`<div><b>${value.filename}</b> : <pre>${value.output.url}</pre></div>`
})}</div>`
modalDialogCustom.alert(yo`<span>Metadata published successfully.<br> <pre>${result}</pre> </span>`)
} }
}, function (item) { // triggered each time there's a new verified publish (means hash correspond) }, function (item) { // triggered each time there's a new verified publish (means hash correspond)
self._deps.swarmfileProvider.addReadOnly(item.hash, item.content) self._deps.swarmfileProvider.addReadOnly(item.hash, item.content)

@ -30,7 +30,7 @@ class CmdInterpreterAPI {
self.commandHelp = { self.commandHelp = {
'remix.debug(hash)': 'Start debugging a transaction.', 'remix.debug(hash)': 'Start debugging a transaction.',
'remix.loadgist(id)': 'Load a gist in the file explorer.', 'remix.loadgist(id)': 'Load a gist in the file explorer.',
'remix.loadurl(url)': 'Load the given url in the file explorer. The url can be of type github, swarm or ipfs.', 'remix.loadurl(url)': 'Load the given url in the file explorer. The url can be of type github, swarm, ipfs or raw http',
'remix.setproviderurl(url)': 'Change the current provider to Web3 provider and set the url endpoint.', 'remix.setproviderurl(url)': 'Change the current provider to Web3 provider and set the url endpoint.',
'remix.execute(filepath)': 'Run the script specified by file path. If filepath is empty, script currently displayed in the editor is executed.', 'remix.execute(filepath)': 'Run the script specified by file path. If filepath is empty, script currently displayed in the editor is executed.',
'remix.exeCurrent()': 'Run the script currently displayed in the editor', 'remix.exeCurrent()': 'Run the script currently displayed in the editor',

@ -48,6 +48,7 @@
<input type="button" id="getcontentof">getcontentof</input> <br> <input type="button" id="getcontentof">getcontentof</input> <br>
<input type="button" id="getcurrent">getcurrent</input> <br> <input type="button" id="getcurrent">getcurrent</input> <br>
<input type="button" id="sethighlight">sethighlight</input> <br> <input type="button" id="sethighlight">sethighlight</input> <br>
<input type="button" id="getfilesfrompath">getfilesfrompath</input> <br>
<br> <br>
<div id='compilationdata'></div> <div id='compilationdata'></div>
</body> </body>

@ -73,4 +73,9 @@ window.onload = function () {
extension.call('editor', 'highlight', [document.getElementById('filename').value, document.getElementById('valuetosend').value, document.getElementById('valuetosend2').value], extension.call('editor', 'highlight', [document.getElementById('filename').value, document.getElementById('valuetosend').value, document.getElementById('valuetosend2').value],
function (error, result) { console.log(error, result) }) function (error, result) { console.log(error, result) })
}) })
document.querySelector('input#getfilesfrompath').addEventListener('click', function () {
extension.call('editor', 'getFilesFromPath', [document.getElementById('filename').value],
function (error, result) { console.log(error, result) })
})
} }

Loading…
Cancel
Save