diff --git a/src/app/compiler/compiler-imports.js b/src/app/compiler/compiler-imports.js index 9be0ea60f4..adb09338eb 100644 --- a/src/app/compiler/compiler-imports.js +++ b/src/app/compiler/compiler-imports.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: '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: '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) } } ] } diff --git a/src/app/contract/publishOnSwarm.js b/src/app/contract/publishOnSwarm.js index a3d044cc7d..cd4bdb3bac 100644 --- a/src/app/contract/publishOnSwarm.js +++ b/src/app/contract/publishOnSwarm.js @@ -7,11 +7,6 @@ module.exports = (contract, fileManager, cb, swarmVerifiedPublishCallBack) => { // gather list of files to publish var sources = [] - sources.push({ - content: contract.metadata, - hash: contract.metadataHash - }) - var metadata try { metadata = JSON.parse(contract.metadata) @@ -38,7 +33,8 @@ module.exports = (contract, fileManager, cb, swarmVerifiedPublishCallBack) => { } else { sources.push({ content: content, - hash: hash + hash: hash, + filename: fileName }) } cb() @@ -48,12 +44,27 @@ module.exports = (contract, fileManager, cb, swarmVerifiedPublishCallBack) => { cb(error) } else { // publish the list of sources in order, fail if any failed + var uploaded = [] async.eachSeries(sources, function (item, cb) { - swarmVerifiedPublish(item.content, item.hash, (error) => { + swarmVerifiedPublish(item.content, item.hash, (error, result) => { 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) + }, () => { + 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) { cb(err) } 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 { - cb() + cb(null, { message: 'ok', url: 'bzz-raw://' + ret, hash: ret }) } }) } diff --git a/src/app/tabs/compile-tab.js b/src/app/tabs/compile-tab.js index 68464d5587..e4a90efa85 100644 --- a/src/app/tabs/compile-tab.js +++ b/src/app/tabs/compile-tab.js @@ -365,7 +365,7 @@ module.exports = class CompileTab { if (contract.metadata === undefined || contract.metadata.length === 0) { modalDialogCustom.alert('This contract does not implement all functions and thus cannot be published.') } else { - publishOnSwarm(contract, self._deps.fileManager, function (err) { + publishOnSwarm(contract, self._deps.fileManager, function (err, uploaded) { if (err) { try { err = JSON.stringify(err) @@ -373,7 +373,10 @@ module.exports = class CompileTab { modalDialogCustom.alert(yo`Failed to publish metadata file to swarm, please check the Swarm gateways is available ( swarm-gateways.net ).
${err}
`) } else { - modalDialogCustom.alert(yo`Metadata published successfully.
The Swarm address of the metadata file is available in the contract details.
`) + var result = yo`
${uploaded.map((value) => { + return yo`
${value.filename} :
${value.output.url}
` + })}
` + modalDialogCustom.alert(yo`Metadata published successfully.
${result}
`) } }, function (item) { // triggered each time there's a new verified publish (means hash correspond) self._deps.swarmfileProvider.addReadOnly(item.hash, item.content) diff --git a/src/lib/cmdInterpreterAPI.js b/src/lib/cmdInterpreterAPI.js index f0923d05ff..cef5a05579 100644 --- a/src/lib/cmdInterpreterAPI.js +++ b/src/lib/cmdInterpreterAPI.js @@ -30,7 +30,7 @@ class CmdInterpreterAPI { self.commandHelp = { 'remix.debug(hash)': 'Start debugging a transaction.', '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.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',