Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
55748f8e
Commit
55748f8e
authored
Aug 30, 2017
by
yann300
Committed by
GitHub
Aug 30, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #733 from ethereum/fixTxResult
refactor vm error check
parents
42b5e163
be7e0531
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
21 deletions
+59
-21
txExecution.js
src/app/execution/txExecution.js
+29
-0
run-tab.js
src/app/tabs/run-tab.js
+7
-18
universal-dapp.js
src/universal-dapp.js
+23
-3
No files found.
src/app/execution/txExecution.js
View file @
55748f8e
'use strict'
var
yo
=
require
(
'yo-yo'
)
module
.
exports
=
{
/**
...
...
@@ -29,5 +30,33 @@ module.exports = {
// see universaldapp.js line 660 => 700 to check possible values of txResult (error case)
callback
(
error
,
txResult
)
})
},
/**
* check if the vm has errored
*
* @param {Object} txResult - the value returned by the vm
* @return {Object} - { error: true/false, message: DOMNode }
*/
checkVMError
:
function
(
txResult
)
{
var
ret
=
{
error
:
false
,
message
:
''
}
if
(
!
txResult
.
result
.
vm
.
exceptionError
)
{
return
ret
}
var
error
=
yo
`<span> VM error:
${
txResult
.
result
.
vm
.
exceptionError
}
</span>`
var
msg
if
(
txResult
.
result
.
vm
.
exceptionError
===
'invalid opcode'
)
{
msg
=
yo
`<ul><li>The constructor should be payable if you send it value.</li>
<li>The execution might have thrown.</li></ul>`
ret
.
error
=
true
}
else
if
(
txResult
.
result
.
vm
.
exceptionError
===
'out of gas'
)
{
msg
=
yo
`<div>The transaction ran out of gas. Please increase the Gas Limit.</div>`
ret
.
error
=
true
}
ret
.
message
=
yo
`<div>
${
error
}
${
msg
}
Debug the transaction to get more information</div>`
return
ret
}
}
src/app/tabs/run-tab.js
View file @
55748f8e
...
...
@@ -304,8 +304,13 @@ function contractDropdown (appAPI, appEvents, instanceContainer) {
txExecution
.
createContract
(
data
,
appAPI
.
udapp
(),
(
error
,
txResult
)
=>
{
if
(
!
error
)
{
var
isVM
=
appAPI
.
executionContext
().
isVM
()
if
(
isVM
&&
alertVMErrorIfAny
(
txResult
))
return
if
(
isVM
)
{
var
vmError
=
txExecution
.
checkVMError
(
txResult
)
if
(
vmError
.
error
)
{
modalDialogCustom
.
alert
(
vmError
.
message
)
return
}
}
noInstancesText
.
style
.
display
=
'none'
var
address
=
isVM
?
txResult
.
result
.
createdAddress
:
txResult
.
result
.
contractAddress
instanceContainer
.
appendChild
(
appAPI
.
udapp
().
renderInstance
(
contract
,
address
,
selectContractNames
.
value
))
...
...
@@ -319,22 +324,6 @@ function contractDropdown (appAPI, appEvents, instanceContainer) {
})
}
function
alertVMErrorIfAny
(
txResult
)
{
if
(
!
txResult
.
result
.
vm
.
exceptionError
)
{
return
null
}
var
error
=
yo
`<span> VM error:
${
txResult
.
result
.
vm
.
exceptionError
}
</span>`
var
msg
if
(
txResult
.
result
.
vm
.
exceptionError
===
'invalid opcode'
)
{
msg
=
yo
`<ul><li>The constructor should be payable if you send it value.</li>
<li>The execution might have thrown.</li></ul>`
}
else
if
(
txResult
.
result
.
vm
.
exceptionError
===
'out of gas'
)
{
msg
=
yo
`<div>The transaction ran out of gas. Please increase the Gas Limit.</div>`
}
modalDialogCustom
.
alert
(
yo
`<div>
${
error
}
${
msg
}
Debug the transaction to get more information</div>`
)
return
error
+
msg
}
function
loadFromAddress
(
appAPI
)
{
noInstancesText
.
style
.
display
=
'none'
var
contractNames
=
document
.
querySelector
(
`.
${
css
.
contractNames
.
classNames
[
0
]}
`
)
...
...
src/universal-dapp.js
View file @
55748f8e
/* global
alert
*/
/* global */
'use strict'
var
$
=
require
(
'jquery'
)
...
...
@@ -13,6 +13,7 @@ var txFormat = require('./app/execution/txFormat')
var
txHelper
=
require
(
'./app/execution/txHelper'
)
var
txExecution
=
require
(
'./app/execution/txExecution'
)
var
helper
=
require
(
'./lib/helper'
)
var
modalDialogCustom
=
require
(
'./app/ui/modal-dialog-custom'
)
// copy to copyToClipboard
const
copy
=
require
(
'clipboard-copy'
)
...
...
@@ -309,17 +310,25 @@ UniversalDApp.prototype.getCallButton = function (args) {
if
(
!
error
)
{
txExecution
.
callFunction
(
args
.
address
,
data
,
args
.
funABI
,
self
,
(
error
,
txResult
)
=>
{
if
(
!
error
)
{
var
isVM
=
self
.
executionContext
.
isVM
()
if
(
isVM
)
{
var
vmError
=
txExecution
.
checkVMError
(
txResult
)
if
(
vmError
.
error
)
{
modalDialogCustom
.
alert
(
vmError
.
message
)
return
}
}
if
(
lookupOnly
)
{
txFormat
.
decodeResponse
(
self
.
executionContext
.
isVM
()
?
txResult
.
result
.
vm
.
return
:
ethJSUtil
.
toBuffer
(
txResult
.
result
),
args
.
funABI
,
(
error
,
decoded
)
=>
{
$outputOverride
.
html
(
error
?
'error'
+
error
:
decoded
)
})
}
}
else
{
alert
(
error
)
modalDialogCustom
.
alert
(
error
)
}
})
}
else
{
alert
(
error
)
modalDialogCustom
.
alert
(
error
)
}
})
}
...
...
@@ -436,6 +445,17 @@ UniversalDApp.prototype.runTx = function (args, cb) {
if
(
!
args
.
useCall
)
{
self
.
event
.
trigger
(
'transactionExecuted'
,
[
error
,
args
.
to
,
args
.
data
,
false
,
result
])
}
if
(
error
)
{
if
(
typeof
(
error
)
!==
'string'
)
{
if
(
error
.
message
)
{
error
=
error
.
message
}
else
{
try
{
error
=
'error: '
+
JSON
.
stringify
(
error
)
}
catch
(
e
)
{}
}
}
}
callback
(
error
,
result
)
})
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment