add/remove modules API && remove publishOnSwarm logic (already in hiw own module)

pull/1/head
yann300 7 years ago
parent 3b17684ed8
commit 06115a3f04
  1. 182
      src/app.js

@ -479,23 +479,6 @@ function run () {
var offsetToLineColumnConverter = new OffsetToLineColumnConverter(compiler.event)
// ----------------- 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 = {
error: (file, error) => {
if (file === config.get('currentFile')) {
@ -507,124 +490,48 @@ function run () {
switchToFile(errFile)
}
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()
// ----------------- 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, {
removable: false,
removable_instances: true
})
udapp.reset({}, transactionContextAPI)
udapp.event.register('debugRequested', this, function (txResult) {
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 --------------------
var rhpAPI = {
config: config,
warnCompilerLoading: (msg) => {
renderer.clear()
if (msg) renderer.error(msg, $('#output'), {type: 'warning'})
setEditorSize (delta) {
$('#righthand-panel').css('width', delta)
self._view.centerpanel.style.right = delta + 'px'
document.querySelector(`.${css.dragbar2}`).style.right = delta + 'px'
onResize()
},
executionContextChange: (context) => {
return executionContext.executionContextChange(context)
@ -634,12 +541,49 @@ function run () {
},
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 = {
compiler: compiler.event,
app: self.event,
udapp: udapp.event
udapp: udapp.event,
editor: editor.event
}
self._components.righthandpanel = new RighthandPanel(rhpAPI, rhpEvents, {})
self._view.rightpanel.appendChild(self._components.righthandpanel.render())

Loading…
Cancel
Save