Merge pull request #779 from ethereum/returnValueForVM

decoded ouput if VM
pull/1/head
yann300 8 years ago committed by GitHub
commit 04016be5c3
  1. 12
      src/app/execution/txFormat.js
  2. 14
      src/app/execution/txListener.js
  3. 10
      src/app/execution/txLogger.js
  4. 20
      src/universal-dapp.js
  5. 2
      test-browser/tests/compiling.js

@ -122,8 +122,7 @@ module.exports = {
}
},
decodeResponse: function (response, fnabi, callback) {
// Only decode if there supposed to be fields
decodeResponseToTreeView: function (response, fnabi) {
var treeView = new TreeView({
extractData: (item, parent, key) => {
var ret = {}
@ -136,6 +135,11 @@ module.exports = {
return ret
}
})
return treeView.render(this.decodeResponse(response, fnabi))
},
decodeResponse: function (response, fnabi) {
// Only decode if there supposed to be fields
if (fnabi.outputs && fnabi.outputs.length > 0) {
try {
var i
@ -159,9 +163,9 @@ module.exports = {
}
}
return callback(null, treeView.render(json))
return json
} catch (e) {
return callback('Failed to decode output: ' + e)
return { error: 'Failed to decode output: ' + e }
}
}
}

@ -6,6 +6,7 @@ var EventManager = require('ethereum-remix').lib.EventManager
var remix = require('ethereum-remix')
var codeUtil = remix.util.code
var executionContext = require('../../execution-context')
var txFormat = require('./txFormat')
/**
* poll web3 each 2s if web3
@ -32,6 +33,7 @@ class TxListener {
})
opt.event.udapp.register('transactionExecuted', (error, to, data, lookupOnly, txResult) => {
if (error) return
if (lookupOnly) return
// we go for that case if
// in VM mode
// in web3 mode && listen remix txs only
@ -39,6 +41,8 @@ class TxListener {
if (this._loopId) return // we seems to already listen on the network
executionContext.web3().eth.getTransaction(txResult.transactionHash, (error, tx) => {
if (error) return console.log(error)
if (txResult && txResult.result && txResult.result.vm) tx.returnValue = txResult.result.vm.return
this._resolve([tx], () => {
})
})
@ -158,7 +162,9 @@ class TxListener {
async.each(transactions, (tx, cb) => {
this._resolveTx(tx, (error, resolvedData) => {
if (error) cb(error)
if (resolvedData) this.event.trigger('txResolved', [tx, resolvedData])
if (resolvedData) {
this.event.trigger('txResolved', [tx, resolvedData])
}
this.event.trigger('newTransaction', [tx])
cb()
})
@ -224,11 +230,15 @@ class TxListener {
if (!isCtor) {
for (var fn in compiledContracts[contractName].functionHashes) {
if (compiledContracts[contractName].functionHashes[fn] === inputData.substring(0, 8)) {
var fnabi = getFunction(abi, fn)
this._resolvedTransactions[tx.hash] = {
contractName: contractName,
to: tx.to,
fn: fn,
params: this._decodeInputParams(inputData.substring(8), getFunction(abi, fn))
params: this._decodeInputParams(inputData.substring(8), fnabi)
}
if (tx.returnValue) {
this._resolvedTransactions[tx.hash].decodedReturnValue = txFormat.decodeResponse(tx.returnValue, fnabi)
}
return this._resolvedTransactions[tx.hash]
}

@ -146,6 +146,7 @@ function renderKnownTransaction (self, data) {
hash: data.tx.hash,
input: data.tx.input,
'decoded input': data.resolvedData && data.resolvedData.params ? JSON.stringify(value(data.resolvedData.params), null, '\t') : ' - ',
'decoded output': data.resolvedData && data.resolvedData.decodedReturnValue ? JSON.stringify(value(data.resolvedData.decodedReturnValue), null, '\t') : ' - ',
logs: JSON.stringify(data.logs, null, '\t') || '0',
val: data.tx.value
})
@ -318,6 +319,15 @@ function createTable (opts) {
table.appendChild(inputDecoded)
}
if (opts['decoded output']) {
var outputDecoded = yo`
<tr class="${css.tr}">
<td class="${css.td}"> decoded output </td>
<td class="${css.td}" id="decodedoutput" >${opts['decoded output']}</td>
</tr class="${css.tr}">`
table.appendChild(outputDecoded)
}
var logs = yo`
<tr class="${css.tr}">
<td class="${css.td}"> logs </td>

@ -78,6 +78,8 @@ var css = csjs`
}
.buttonsContainer {
margin-top: 2%;
}
.contractActions {
display: flex;
}
.instanceButton {}
@ -319,9 +321,8 @@ UniversalDApp.prototype.getCallButton = function (args) {
}
}
if (lookupOnly) {
txFormat.decodeResponse(executionContext.isVM() ? txResult.result.vm.return : ethJSUtil.toBuffer(txResult.result), args.funABI, (error, decoded) => {
$outputOverride.html(error ? 'error' + error : decoded)
})
var decoded = txFormat.decodeResponseToTreeView(executionContext.isVM() ? txResult.result.vm.return : ethJSUtil.toBuffer(txResult.result), args.funABI)
$outputOverride.html(decoded)
}
} else {
modalDialogCustom.alert(error)
@ -332,12 +333,17 @@ UniversalDApp.prototype.getCallButton = function (args) {
}
})
}
// TODO the auto call to constant function has been removed. needs to readd it later.
var $contractProperty = $(`<div class="contractProperty ${css.buttonsContainer}"></div>`)
$contractProperty
.append(button)
.append((lookupOnly && !inputs.length) ? $outputOverride : inputField)
var $contractActions = $(`<div class="${css.contractActions}" ></div>`)
$contractProperty.append($contractActions)
$contractActions.append(button)
if (inputs.length) {
$contractActions.append(inputField)
}
if (lookupOnly) {
$contractProperty.append($outputOverride)
}
if (lookupOnly) {
$contractProperty.addClass('constant')

@ -34,6 +34,8 @@ function runTests (browser) {
.click('.instance button[title="f - transact (not payable)"]')
.waitForElementPresent('#editor-container div[class^="terminal"] span[id="tx0xa178c603400a184ce5fedbcfab392d9b77822f6ffa7facdec693aded214523bc"]')
.assert.containsText('#editor-container div[class^="terminal"] span[id="tx0xa178c603400a184ce5fedbcfab392d9b77822f6ffa7facdec693aded214523bc"]', '[vm] from:0xca3...a733c, to:browser/Untitled.sol:TestContract.f() 0x692...77b3a, value:0 wei, data:0x261...21ff0, 0 logs, hash:0xa17...523bc')
.click('#editor-container div[class^="terminal"] span[id="tx0xa178c603400a184ce5fedbcfab392d9b77822f6ffa7facdec693aded214523bc"] button[class^="details"]')
.assert.containsText('#editor-container div[class^="terminal"] span[id="tx0xa178c603400a184ce5fedbcfab392d9b77822f6ffa7facdec693aded214523bc"] table[class^="txTable"] #decodedoutput', `"uint256": "8"`)
.end()
/*
@TODO: need to check now the return value of the function

Loading…
Cancel
Save