Commit c2700c22 authored by yann300's avatar yann300

execute batch in serie

parent a93da3de
...@@ -358,48 +358,61 @@ Please make a backup of your contracts and start using http://remix.ethereum.org ...@@ -358,48 +358,61 @@ Please make a backup of your contracts and start using http://remix.ethereum.org
and interpret them as commands and interpret them as commands
*/ */
var cmdInterpreter = new CommandInterpreter() var cmdInterpreter = new CommandInterpreter()
cmdInterpreter.event.register('debug', (hash) => { cmdInterpreter.event.register('debug', (hash, cb) => {
startdebugging(hash) startdebugging(hash)
if (cb) cb()
}) })
cmdInterpreter.event.register('loadgist', (id) => { cmdInterpreter.event.register('loadgist', (id, cb) => {
loadFromGist({gist: id}) loadFromGist({gist: id})
if (cb) cb()
}) })
cmdInterpreter.event.register('loadurl', (url) => { cmdInterpreter.event.register('loadurl', (url, cb) => {
importExternal(url, (err, content) => { importExternal(url, (err, content) => {
if (err) { if (err) {
toolTip(`Unable to load ${url} from swarm: ${err}`) toolTip(`Unable to load ${url} from swarm: ${err}`)
if (cb) cb(err)
} else { } else {
try { try {
content = JSON.parse(content) content = JSON.parse(content)
for (var k in content.sources) { async.eachOfSeries(content.sources, (value, file, callbackSource) => {
var url = content.sources[k].urls[0] // @TODO retrieve all other contents ? var url = value.urls[0] // @TODO retrieve all other contents ?
importExternal(url, (error, content) => { importExternal(url, (error, content) => {
if (error) { if (error) {
toolTip(`Cannot retrieve the content of ${url}: ${error}`) toolTip(`Cannot retrieve the content of ${url}: ${error}`)
} }
callbackSource()
}) })
} }, (error) => {
} catch (e) { if (cb) cb(error)
filesProviders['swarm'].addReadOnly(url, content) })
} } catch (e) {}
if (cb) cb()
} }
}) })
}) })
cmdInterpreter.event.register('setproviderurl', (url) => { cmdInterpreter.event.register('setproviderurl', (url, cb) => {
executionContext.setProviderFromEndpoint(url, 'web3', (error) => { executionContext.setProviderFromEndpoint(url, 'web3', (error) => {
if (error) toolTip(error) if (error) toolTip(error)
if (cb) cb()
}) })
}) })
cmdInterpreter.event.register('batch', (url) => { cmdInterpreter.event.register('batch', (url, cb) => {
var content = editor.get(editor.current()) var content = editor.get(editor.current())
if (!content) { if (!content) {
toolTip('no content to execute') toolTip('no content to execute')
if (cb) cb()
return
} }
var split = content.split('\n') var split = content.split('\n')
async.eachSeries(split, (value, cb) => { async.eachSeries(split, (value, cb) => {
cmdInterpreter.interpret(value) ? cb() : cb(`Cannot run ${value}. stopping`) if (!cmdInterpreter.interpret(value, (error) => {
error ? cb(`Cannot run ${value}. stopping`) : cb()
})) {
cb(`Cannot interpret ${value}. stopping`)
}
}, (error) => { }, (error) => {
if (error) toolTip(error) if (error) toolTip(error)
if (cb) cb()
}) })
}) })
......
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