Commit 77929cef authored by yann300's avatar yann300

fix publish to swarm

parent 6dbc097c
...@@ -68,7 +68,7 @@ module.exports = class CompilerImports { ...@@ -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) => { ...@@ -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) => { ...@@ -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) => { ...@@ -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) { ...@@ -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 })
} }
}) })
} }
...@@ -365,7 +365,7 @@ module.exports = class CompileTab { ...@@ -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 { ...@@ -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 { ...@@ -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',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment