Merge pull request #598 from ethereum/resetValue

Reset value field to 0 after each transaction
pull/1/head
yann300 7 years ago committed by GitHub
commit d3537b3196
  1. 167
      src/app.js
  2. 14
      src/app/contract-tab.js
  3. 17
      src/app/execution-context.js
  4. 7
      src/app/righthand-panel.js
  5. 3
      src/universal-dapp.js

@ -479,20 +479,106 @@ var run = function () {
}
var renderer = new Renderer(rendererAPI, compiler.event)
// ------------------------------------------------------------
var executionContext = new ExecutionContext()
// ----------------- UniversalDApp -----------------
var udapp = new UniversalDApp(executionContext, {
removable: false,
removable_instances: true
})
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')
}
Object.keys(metadata.sources).forEach(function (fileName) {
// find hash
var hash
try {
hash = metadata.sources[fileName].urls[0].match('bzzr://(.+)')[1]
} catch (e) {
return cb('Metadata inconsistency')
}
sources.push({
content: files.get(fileName),
hash: hash
})
})
// 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) {
alert('Failed to publish metadata: ' + err)
} else {
alert('Metadata published successfully')
}
})
})
// ---------------- Righthand-panel --------------------
var rhpAPI = {
config: config,
onResize: onResize,
reAdjust: reAdjust,
renderer: renderer
warnCompilerLoading: (msg) => {
renderer.clear()
if (msg) {
renderer.error(msg, $('#output'), {type: 'warning'})
}
},
executionContextChange: (context) => {
return executionContext.executionContextChange(context)
},
executionContextProvider: () => {
return executionContext.getProvider()
}
}
var rhpEvents = {
compiler: compiler.event,
app: self.event
app: self.event,
udapp: udapp.event
}
var righthandPanel = new RighthandPanel(document.body, rhpAPI, rhpEvents, {}) // eslint-disable-line
// ------------------------------------------------------------
var executionContext = new ExecutionContext()
// ----------------- editor resize ---------------
function onResize () {
@ -635,79 +721,6 @@ var run = function () {
transactionDebugger.addProvider('web3', executionContext.web3())
transactionDebugger.switchProvider(executionContext.getProvider())
// ----------------- UniversalDApp -----------------
var udapp = new UniversalDApp(executionContext, {
removable: false,
removable_instances: true
})
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')
}
Object.keys(metadata.sources).forEach(function (fileName) {
// find hash
var hash
try {
hash = metadata.sources[fileName].urls[0].match('bzzr://(.+)')[1]
} catch (e) {
return cb('Metadata inconsistency')
}
sources.push({
content: files.get(fileName),
hash: hash
})
})
// 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) {
alert('Failed to publish metadata: ' + err)
} else {
alert('Metadata published successfully')
}
})
})
// ----------------- StaticAnalysis -----------------
var staticAnalysisAPI = {
renderWarning: (label, warningContainer, type) => {

@ -107,5 +107,19 @@ function contractTab (container, appAPI, appEvents, opts) {
<div id="output" class="${css.contract}"></div>
</div>
`
appEvents.udapp.register('transactionExecuted', (to, data, lookupOnly, txResult) => {
if (!lookupOnly) el.querySelector('#value').value = '0'
})
/* ---------------------------------------------------------------------------
DROPDOWN
--------------------------------------------------------------------------- */
var selectExEnv = el.querySelector('#selectExEnvOptions')
selectExEnv.addEventListener('change', function (event) {
if (!appAPI.executionContextChange(selectExEnv.options[selectExEnv.selectedIndex].value)) {
selectExEnv.value = appAPI.executionContextProvider()
}
})
selectExEnv.value = appAPI.executionContextProvider()
container.appendChild(el)
}

@ -91,10 +91,10 @@ function ExecutionContext () {
this.setContext = function (context, endPointUrl) {
executionContext = context
executionContextChange(context, endPointUrl)
this.executionContextChange(context, endPointUrl)
}
function executionContextChange (context, endPointUrl) {
this.executionContextChange = function (context, endPointUrl) {
if (context === 'web3' && !confirm('Are you sure you want to connect to an ethereum node?')) {
return false
} else if (context === 'injected' && injectedProvider === undefined) {
@ -131,19 +131,6 @@ function ExecutionContext () {
}
self.event.trigger('web3EndpointChanged')
}
/* ---------------------------------------------------------------------------
DROPDOWN
--------------------------------------------------------------------------- */
var selectExEnv = document.querySelector('#selectExEnvOptions')
selectExEnv.addEventListener('change', function (event) {
if (!executionContextChange(selectExEnv.options[selectExEnv.selectedIndex].value)) {
selectExEnv.value = executionContext
}
})
selectExEnv.value = executionContext
}
module.exports = ExecutionContext

@ -67,12 +67,7 @@ function RighthandPanel (container, appAPI, events, opts) {
// ----------------- tabbed menu -----------------
var tabbedMenuAPI = {
warnCompilerLoading: function (msg) {
appAPI.renderer.clear()
if (msg) {
appAPI.renderer.error(msg, $('#output'), {type: 'warning'})
}
}
warnCompilerLoading: appAPI.warnCompilerLoading
}
// load tabbed menu component
var tabContainer // @TODO

@ -686,6 +686,7 @@ UniversalDApp.prototype.getCallButton = function (args) {
var decoded
self.runTx({ to: args.address, data: data, useCall: lookupOnly }, function (err, txResult) {
self.event.trigger('transactionExecuted', [args.address, data, lookupOnly, txResult])
if (!txResult) {
replaceOutput($result, $('<span/>').text('callback contain no result ' + err).addClass('error'))
return
@ -865,7 +866,7 @@ UniversalDApp.prototype.runTx = function (args, cb) {
// query value
function (callback) {
tx.value = 0
if (tx.useCall) return callback()
if (self.transactionContextAPI.getValue) {
self.transactionContextAPI.getValue(function (err, ret) {
if (err) {

Loading…
Cancel
Save