Commit c704745c authored by yann300's avatar yann300 Committed by GitHub

Merge pull request #816 from ethereum/addGasEstimation

Add gas costs
parents 63b07198 a9e69a24
...@@ -171,5 +171,6 @@ module.exports = { ...@@ -171,5 +171,6 @@ module.exports = {
return { error: 'Failed to decode output: ' + e } return { error: 'Failed to decode output: ' + e }
} }
} }
return {}
} }
} }
...@@ -67,7 +67,14 @@ class TxListener { ...@@ -67,7 +67,14 @@ class TxListener {
if (this._loopId && executionContext.getProvider() !== 'vm') return // we seems to already listen on a "web3" network if (this._loopId && executionContext.getProvider() !== 'vm') return // we seems to already listen on a "web3" network
executionContext.web3().eth.getTransaction(txResult.transactionHash, (error, tx) => { executionContext.web3().eth.getTransaction(txResult.transactionHash, (error, tx) => {
if (error) return console.log(error) if (error) return console.log(error)
if (txResult && txResult.result && txResult.result.vm) tx.returnValue = txResult.result.vm.return if (txResult && txResult.result) {
if (txResult.result.vm) {
tx.returnValue = txResult.result.vm.return
if (txResult.result.vm.gasUsed) tx.executionCost = txResult.result.vm.gasUsed.toString(10)
}
if (txResult.result.gasUsed) tx.transactionCost = txResult.result.gasUsed.toString(10)
}
tx.envMode = executionContext.getProvider() tx.envMode = executionContext.getProvider()
this._resolve([tx], () => { this._resolve([tx], () => {
}) })
......
...@@ -175,7 +175,9 @@ function renderKnownTransaction (self, data) { ...@@ -175,7 +175,9 @@ function renderKnownTransaction (self, data) {
'decoded input': data.resolvedData && data.resolvedData.params ? JSON.stringify(typeConversion.stringify(data.resolvedData.params), null, '\t') : ' - ', 'decoded input': data.resolvedData && data.resolvedData.params ? JSON.stringify(typeConversion.stringify(data.resolvedData.params), null, '\t') : ' - ',
'decoded output': data.resolvedData && data.resolvedData.decodedReturnValue ? JSON.stringify(typeConversion.stringify(data.resolvedData.decodedReturnValue), null, '\t') : ' - ', 'decoded output': data.resolvedData && data.resolvedData.decodedReturnValue ? JSON.stringify(typeConversion.stringify(data.resolvedData.decodedReturnValue), null, '\t') : ' - ',
logs: data.logs, logs: data.logs,
val: data.tx.value val: data.tx.value,
transactionCost: data.tx.transactionCost,
executionCost: data.tx.executionCost
}) })
tx.appendChild(table) tx.appendChild(table)
} }
...@@ -239,7 +241,9 @@ function renderUnknownTransaction (self, data) { ...@@ -239,7 +241,9 @@ function renderUnknownTransaction (self, data) {
input: data.tx.input, input: data.tx.input,
hash: data.tx.hash, hash: data.tx.hash,
gas: data.tx.gas, gas: data.tx.gas,
logs: data.logs logs: data.logs,
transactionCost: data.tx.transactionCost,
executionCost: data.tx.executionCost
}) })
tx.appendChild(table) tx.appendChild(table)
} }
...@@ -314,11 +318,27 @@ function createTable (opts) { ...@@ -314,11 +318,27 @@ function createTable (opts) {
var gas = yo` var gas = yo`
<tr class="${css.tr}"> <tr class="${css.tr}">
<td class="${css.td}"> gas </td> <td class="${css.td}"> gas </td>
<td class="${css.td}"><i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(opts.gas) }} title='Copy to clipboard'></i>${opts.gas}</td> <td class="${css.td}"><i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(opts.gas) }} title='Copy to clipboard'></i>${opts.gas} gas</td>
</tr class="${css.tr}"> </tr class="${css.tr}">
` `
if (opts.gas) table.appendChild(gas) if (opts.gas) table.appendChild(gas)
if (opts.transactionCost) {
table.appendChild(yo`
<tr class="${css.tr}">
<td class="${css.td}"> transaction cost </td>
<td class="${css.td}"><i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(opts.transactionCost) }} title='Copy to clipboard'></i>${opts.transactionCost} gas</td>
</tr class="${css.tr}">`)
}
if (opts.executionCost) {
table.appendChild(yo`
<tr class="${css.tr}">
<td class="${css.td}"> execution cost </td>
<td class="${css.td}"><i class="fa fa-clipboard ${css.clipboardCopy}" aria-hidden="true" onclick=${function () { copy(opts.executionCost) }} title='Copy to clipboard'></i>${opts.executionCost} gas</td>
</tr class="${css.tr}">`)
}
var hash = yo` var hash = yo`
<tr class="${css.tr}"> <tr class="${css.tr}">
<td class="${css.td}"> hash </td> <td class="${css.td}"> hash </td>
......
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