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: '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) } }
]
}

@ -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 })
}
})
}

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

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

@ -48,7 +48,11 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) =>
},
udapp: {
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) => {
if (error) return cb(error)
cb(null, {
@ -60,10 +64,16 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) =>
createdAddress: result.result.createdAddress ? '0x' + result.result.createdAddress.toString('hex') : undefined
})
})
})
},
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)
})
},
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')
@ -73,6 +83,9 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) =>
}
},
editor: {
getFilesFromPath: (mod, path, cb) => {
fileManager.filesFromPath(path, cb)
},
getCurrentFile: (mod, cb) => {
var path = fileManager.currentFile()
if (!path) {
@ -97,7 +110,8 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) =>
if (provider) {
// TODO add approval to user for external plugin to set the content of the given `path`
provider.set(path, content, (error) => {
cb(error)
if (error) return cb(error)
fileManager.syncEditor(path)
})
} else {
cb(path + ' not available')

@ -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`<span>Failed to publish metadata file to swarm, please check the Swarm gateways is available ( swarm-gateways.net ).<br />
${err}</span>`)
} 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)
self._deps.swarmfileProvider.addReadOnly(item.hash, item.content)

@ -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',

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

@ -73,4 +73,9 @@ window.onload = function () {
extension.call('editor', 'highlight', [document.getElementById('filename').value, document.getElementById('valuetosend').value, document.getElementById('valuetosend2').value],
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