|
|
@ -479,23 +479,6 @@ function run () { |
|
|
|
var offsetToLineColumnConverter = new OffsetToLineColumnConverter(compiler.event) |
|
|
|
var offsetToLineColumnConverter = new OffsetToLineColumnConverter(compiler.event) |
|
|
|
|
|
|
|
|
|
|
|
// ----------------- Renderer -----------------
|
|
|
|
// ----------------- Renderer -----------------
|
|
|
|
var transactionContextAPI = { |
|
|
|
|
|
|
|
getAddress: (cb) => { |
|
|
|
|
|
|
|
cb(null, $('#txorigin').val()) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
getValue: (cb) => { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
var comp = $('#value').val().split(' ') |
|
|
|
|
|
|
|
cb(null, executionContext.web3().toWei(comp[0], comp.slice(1).join(' '))) |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
cb(e) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
getGasLimit: (cb) => { |
|
|
|
|
|
|
|
cb(null, $('#gasLimit').val()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var rendererAPI = { |
|
|
|
var rendererAPI = { |
|
|
|
error: (file, error) => { |
|
|
|
error: (file, error) => { |
|
|
|
if (file === config.get('currentFile')) { |
|
|
|
if (file === config.get('currentFile')) { |
|
|
@ -507,124 +490,48 @@ function run () { |
|
|
|
switchToFile(errFile) |
|
|
|
switchToFile(errFile) |
|
|
|
} |
|
|
|
} |
|
|
|
editor.gotoLine(errLine, errCol) |
|
|
|
editor.gotoLine(errLine, errCol) |
|
|
|
}, |
|
|
|
} |
|
|
|
currentCompiledSourceCode: () => { |
|
|
|
|
|
|
|
if (compiler.lastCompilationResult.source) { |
|
|
|
|
|
|
|
return compiler.lastCompilationResult.source.sources[compiler.lastCompilationResult.source.target] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return '' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
resetDapp: (udappContracts, renderOutputModifier) => { |
|
|
|
|
|
|
|
udapp.reset(udappContracts, transactionContextAPI, renderOutputModifier) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
renderDapp: () => { |
|
|
|
|
|
|
|
return udapp.render() |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
getAccounts: (callback) => { |
|
|
|
|
|
|
|
udapp.getAccounts(callback) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
getBalance: (address, callback) => { |
|
|
|
|
|
|
|
udapp.getBalance(address, (error, balance) => { |
|
|
|
|
|
|
|
if (error) { |
|
|
|
|
|
|
|
callback(error) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
callback(null, executionContext.web3().fromWei(balance, 'ether')) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
currentblockGasLimit: () => { return executionContext.currentblockGasLimit() } |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
var renderer = new Renderer(rendererAPI, compiler.event) |
|
|
|
var renderer = new Renderer(rendererAPI) |
|
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
var executionContext = new ExecutionContext() |
|
|
|
var executionContext = new ExecutionContext() |
|
|
|
|
|
|
|
|
|
|
|
// ----------------- UniversalDApp -----------------
|
|
|
|
// ----------------- UniversalDApp -----------------
|
|
|
|
|
|
|
|
var transactionContextAPI = { |
|
|
|
|
|
|
|
getAddress: (cb) => { |
|
|
|
|
|
|
|
cb(null, $('#txorigin').val()) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
getValue: (cb) => { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
var comp = $('#value').val().split(' ') |
|
|
|
|
|
|
|
cb(null, executionContext.web3().toWei(comp[0], comp.slice(1).join(' '))) |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
cb(e) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
getGasLimit: (cb) => { |
|
|
|
|
|
|
|
cb(null, $('#gasLimit').val()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var udapp = new UniversalDApp(executionContext, { |
|
|
|
var udapp = new UniversalDApp(executionContext, { |
|
|
|
removable: false, |
|
|
|
removable: false, |
|
|
|
removable_instances: true |
|
|
|
removable_instances: true |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
udapp.reset({}, transactionContextAPI) |
|
|
|
udapp.event.register('debugRequested', this, function (txResult) { |
|
|
|
udapp.event.register('debugRequested', this, function (txResult) { |
|
|
|
startdebugging(txResult.transactionHash) |
|
|
|
startdebugging(txResult.transactionHash) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
function swarmVerifiedPublish (content, expectedHash, cb) { |
|
|
|
|
|
|
|
swarmgw.put(content, function (err, ret) { |
|
|
|
|
|
|
|
if (err) { |
|
|
|
|
|
|
|
cb(err) |
|
|
|
|
|
|
|
} else if (ret !== expectedHash) { |
|
|
|
|
|
|
|
cb('Hash mismatch') |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
cb() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function publishOnSwarm (contract, cb) { |
|
|
|
|
|
|
|
// gather list of files to publish
|
|
|
|
|
|
|
|
var sources = [] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sources.push({ |
|
|
|
|
|
|
|
content: contract.metadata, |
|
|
|
|
|
|
|
hash: contract.metadataHash |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var metadata |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
metadata = JSON.parse(contract.metadata) |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
return cb(e) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (metadata === undefined) { |
|
|
|
|
|
|
|
return cb('No metadata') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async.eachSeries(Object.keys(metadata.sources), function (fileName, cb) { |
|
|
|
|
|
|
|
// find hash
|
|
|
|
|
|
|
|
var hash |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
hash = metadata.sources[fileName].urls[0].match('bzzr://(.+)')[1] |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
return cb('Metadata inconsistency') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fileProviderOf(fileName).get(fileName, (error, content) => { |
|
|
|
|
|
|
|
if (error) { |
|
|
|
|
|
|
|
console.log(error) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
sources.push({ |
|
|
|
|
|
|
|
content: content, |
|
|
|
|
|
|
|
hash: hash |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
cb() |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, function () { |
|
|
|
|
|
|
|
// publish the list of sources in order, fail if any failed
|
|
|
|
|
|
|
|
async.eachSeries(sources, function (item, cb) { |
|
|
|
|
|
|
|
swarmVerifiedPublish(item.content, item.hash, cb) |
|
|
|
|
|
|
|
}, cb) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
udapp.event.register('publishContract', this, function (contract) { |
|
|
|
|
|
|
|
publishOnSwarm(contract, function (err) { |
|
|
|
|
|
|
|
if (err) { |
|
|
|
|
|
|
|
modalDialogCustom.alert('Failed to publish metadata: ' + err) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
modalDialogCustom.alert('Metadata published successfully') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ---------------- Righthand-panel --------------------
|
|
|
|
// ---------------- Righthand-panel --------------------
|
|
|
|
var rhpAPI = { |
|
|
|
var rhpAPI = { |
|
|
|
config: config, |
|
|
|
config: config, |
|
|
|
warnCompilerLoading: (msg) => { |
|
|
|
setEditorSize (delta) { |
|
|
|
renderer.clear() |
|
|
|
$('#righthand-panel').css('width', delta) |
|
|
|
if (msg) renderer.error(msg, $('#output'), {type: 'warning'}) |
|
|
|
self._view.centerpanel.style.right = delta + 'px' |
|
|
|
|
|
|
|
document.querySelector(`.${css.dragbar2}`).style.right = delta + 'px' |
|
|
|
|
|
|
|
onResize() |
|
|
|
}, |
|
|
|
}, |
|
|
|
executionContextChange: (context) => { |
|
|
|
executionContextChange: (context) => { |
|
|
|
return executionContext.executionContextChange(context) |
|
|
|
return executionContext.executionContextChange(context) |
|
|
@ -634,12 +541,49 @@ function run () { |
|
|
|
}, |
|
|
|
}, |
|
|
|
packageFiles: (cb) => { |
|
|
|
packageFiles: (cb) => { |
|
|
|
packageFiles(cb) |
|
|
|
packageFiles(cb) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
getContracts: () => { |
|
|
|
|
|
|
|
if (compiler.lastCompilationResult && compiler.lastCompilationResult.data) { |
|
|
|
|
|
|
|
return compiler.lastCompilationResult.data.contracts |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
udapp: () => { |
|
|
|
|
|
|
|
return udapp |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
executionContext: () => { |
|
|
|
|
|
|
|
return executionContext |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
fileProviderOf: (path) => { |
|
|
|
|
|
|
|
return fileProviderOf(path) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
getBalance: (address, callback) => { |
|
|
|
|
|
|
|
udapp.getBalance(address, (error, balance) => { |
|
|
|
|
|
|
|
if (error) { |
|
|
|
|
|
|
|
callback(error) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
callback(null, executionContext.web3().fromWei(balance, 'ether')) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
compilationMessage: (message, container, options) => { |
|
|
|
|
|
|
|
renderer.error(message, container, options) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
currentCompiledSourceCode: () => { |
|
|
|
|
|
|
|
if (compiler.lastCompilationResult.source) { |
|
|
|
|
|
|
|
return compiler.lastCompilationResult.source.sources[compiler.lastCompilationResult.source.target] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return '' |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
resetDapp: (contracts) => { |
|
|
|
|
|
|
|
udapp.reset(contracts, transactionContextAPI) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
var rhpEvents = { |
|
|
|
var rhpEvents = { |
|
|
|
compiler: compiler.event, |
|
|
|
compiler: compiler.event, |
|
|
|
app: self.event, |
|
|
|
app: self.event, |
|
|
|
udapp: udapp.event |
|
|
|
udapp: udapp.event, |
|
|
|
|
|
|
|
editor: editor.event |
|
|
|
} |
|
|
|
} |
|
|
|
self._components.righthandpanel = new RighthandPanel(rhpAPI, rhpEvents, {}) |
|
|
|
self._components.righthandpanel = new RighthandPanel(rhpAPI, rhpEvents, {}) |
|
|
|
self._view.rightpanel.appendChild(self._components.righthandpanel.render()) |
|
|
|
self._view.rightpanel.appendChild(self._components.righthandpanel.render()) |
|
|
|