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
891b1bb7
Commit
891b1bb7
authored
Jan 02, 2017
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use async / await
parent
b4a7df75
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
91 deletions
+76
-91
.babelrc
.babelrc
+9
-1
internalCallTree.js
src/util/internalCallTree.js
+58
-81
localDecoder.js
test/solidity/localDecoder.js
+9
-9
No files found.
.babelrc
View file @
891b1bb7
{
"plugins": ["fast-async",
"plugins": [["fast-async", {
"runtimePatten": null,
"compiler": {
"promises": true,
"es7": true,
"noRuntime": true,
"wrapAwait": true
}
}],
"check-es2015-constants",
"transform-es2015-arrow-functions",
"transform-es2015-block-scoped-functions",
...
...
src/util/internalCallTree.js
View file @
891b1bb7
...
...
@@ -31,11 +31,12 @@ class InternalCallTree {
if
(
!
this
.
solidityProxy
.
loaded
())
{
console
.
log
(
'compilation result not loaded. Cannot build internal call tree'
)
}
else
{
buildTree
(
this
,
0
,
''
,
(
error
)
=>
{
if
(
!
error
)
{
this
.
event
.
trigger
(
'callTree
Ready'
,
[
this
.
scopes
,
this
.
scopeStarts
])
buildTree
(
this
,
0
,
''
).
then
((
result
)
=>
{
if
(
result
.
error
)
{
this
.
event
.
trigger
(
'callTree
BuildFailed'
,
[
result
])
}
else
{
this
.
event
.
trigger
(
'callTreeBuildFailed'
,
[
error
])
console
.
log
(
'ready'
)
this
.
event
.
trigger
(
'callTreeReady'
,
[
this
.
scopes
,
this
.
scopeStarts
])
}
})
}
...
...
@@ -82,96 +83,72 @@ class InternalCallTree {
}
}
/**
* build tree (called recursively)
*
* @param {Object} tree - instance of InternalCallTree
* @param {Int} step - index on the vm trace
* @param {String} scopeId - deepness of the current scope
* @param {Function} cb - callback
*/
function
buildTree
(
tree
,
step
,
scopeId
,
cb
)
{
async
function
buildTree
(
tree
,
step
,
scopeId
)
{
let
subScope
=
1
tree
.
scopeStarts
[
step
]
=
scopeId
tree
.
scopes
[
scopeId
]
=
{
firstStep
:
step
,
locals
:
{}
}
visitStep
(
tree
,
step
,
scopeId
,
subScope
,
function
(
error
,
result
)
{
cb
(
error
,
result
)
})
}
/**
* visit a step (called recursively)
*
* @param {Object} tree - instance of InternalCallTree
* @param {Int} step - index on the vm trace
* @param {String} scopeId - deepness of the current scope
* @param {Int} subScope - index of the next scope from current scope
* @param {Function} cb - callback
*/
function
visitStep
(
tree
,
step
,
scopeId
,
subScope
,
cb
)
{
setTimeout
(()
=>
{
extractSourceLocation
(
tree
,
step
,
(
error
,
sourceLocation
)
=>
{
if
(
error
)
{
cb
(
error
)
while
(
step
<
tree
.
traceManager
.
trace
.
length
)
{
var
sourceLocation
try
{
sourceLocation
=
await
extractSourceLocation
(
tree
,
step
)
}
catch
(
e
)
{
return
{
outStep
:
step
,
error
:
'InternalCallTree - Error resolving source location. '
+
step
+
' '
+
e
.
messager
}
}
if
(
!
sourceLocation
)
{
return
{
outStep
:
step
,
error
:
'InternalCallTree - No source Location. '
+
step
}
}
if
(
sourceLocation
.
jump
===
'i'
)
{
var
result
=
await
buildTree
(
tree
,
step
+
1
,
scopeId
===
''
?
subScope
.
toString
()
:
scopeId
+
'.'
+
subScope
)
if
(
result
.
error
)
{
return
result
}
else
{
if
(
sourceLocation
.
jump
===
'i'
)
{
buildTree
(
tree
,
step
+
1
,
scopeId
===
''
?
subScope
.
toString
()
:
scopeId
+
'.'
+
subScope
,
function
(
error
,
outStep
)
{
step
=
result
.
outStep
subScope
++
}
}
else
if
(
sourceLocation
.
jump
===
'o'
)
{
tree
.
scopes
[
scopeId
].
lastStep
=
step
return
{
outStep
:
step
+
1
}
}
else
{
if
(
tree
.
includeLocalVariables
)
{
var
variableDeclaration
=
resolveVariableDeclaration
(
tree
,
step
,
sourceLocation
)
if
(
variableDeclaration
&&
!
tree
.
scopes
[
scopeId
].
locals
[
variableDeclaration
.
attributes
.
name
])
{
tree
.
traceManager
.
getStackAt
(
step
,
(
error
,
stack
)
=>
{
if
(
!
error
)
{
visitStep
(
tree
,
outStep
,
scopeId
,
subScope
+
1
,
cb
)
}
else
{
cb
(
'error computing jump'
)
}
})
return
}
else
if
(
sourceLocation
.
jump
===
'o'
)
{
tree
.
scopes
[
scopeId
].
lastStep
=
step
cb
(
null
,
step
+
1
)
return
}
else
{
if
(
tree
.
includeLocalVariables
)
{
var
variableDeclaration
=
resolveVariableDeclaration
(
tree
,
step
,
sourceLocation
)
if
(
variableDeclaration
&&
!
tree
.
scopes
[
scopeId
].
locals
[
variableDeclaration
.
attributes
.
name
])
{
tree
.
traceManager
.
getStackAt
(
step
,
(
error
,
stack
)
=>
{
tree
.
solidityProxy
.
contractNameAt
(
step
,
(
error
,
contractName
)
=>
{
// cached
if
(
!
error
)
{
tree
.
solidityProxy
.
contractNameAt
(
step
,
(
error
,
contractName
)
=>
{
// cached
if
(
!
error
)
{
var
states
=
tree
.
solidityProxy
.
extractStatesDefinitions
()
tree
.
scopes
[
scopeId
].
locals
[
variableDeclaration
.
attributes
.
name
]
=
{
name
:
variableDeclaration
.
attributes
.
name
,
type
:
decodeInfo
.
parseType
(
variableDeclaration
.
attributes
.
type
,
states
,
contractName
),
stackHeight
:
stack
.
length
}
}
})
var
states
=
tree
.
solidityProxy
.
extractStatesDefinitions
()
tree
.
scopes
[
scopeId
].
locals
[
variableDeclaration
.
attributes
.
name
]
=
{
name
:
variableDeclaration
.
attributes
.
name
,
type
:
decodeInfo
.
parseType
(
variableDeclaration
.
attributes
.
type
,
states
,
contractName
),
stackHeight
:
stack
.
length
}
}
})
}
}
step
++
}
if
(
tree
.
traceManager
.
inRange
(
step
))
{
visitStep
(
tree
,
step
,
scopeId
,
subScope
,
cb
)
}
else
{
cb
(
null
,
step
)
})
}
}
})
},
0
)
step
++
}
}
return
{
outStep
:
step
}
}
function
extractSourceLocation
(
tree
,
step
,
cb
)
{
tree
.
traceManager
.
getCurrentCalledAddressAt
(
step
,
(
error
,
address
)
=>
{
if
(
!
error
)
{
tree
.
sourceLocationTracker
.
getSourceLocationFromVMTraceIndex
(
address
,
step
,
tree
.
solidityProxy
.
contracts
,
(
error
,
sourceLocation
)
=>
{
if
(
!
error
)
{
cb
(
null
,
sourceLocation
)
}
else
{
cb
(
'InternalCallTree - Cannot retrieve sourcelocation for step '
+
step
)
}
})
}
else
{
cb
(
'InternalCallTree - Cannot retrieve address for step '
+
step
)
}
function
extractSourceLocation
(
tree
,
step
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
tree
.
traceManager
.
getCurrentCalledAddressAt
(
step
,
(
error
,
address
)
=>
{
if
(
!
error
)
{
tree
.
sourceLocationTracker
.
getSourceLocationFromVMTraceIndex
(
address
,
step
,
tree
.
solidityProxy
.
contracts
,
(
error
,
sourceLocation
)
=>
{
if
(
!
error
)
{
return
resolve
(
sourceLocation
)
}
else
{
return
reject
(
'InternalCallTree - Cannot retrieve sourcelocation for step '
+
step
)
}
})
}
else
{
return
reject
(
'InternalCallTree - Cannot retrieve address for step '
+
step
)
}
})
})
}
...
...
test/solidity/localDecoder.js
View file @
891b1bb7
...
...
@@ -2,20 +2,20 @@
var
tape
=
require
(
'tape'
)
var
compiler
=
require
(
'solc'
)
var
intLocal
=
require
(
'./contracts/intLocal'
)
var
TraceManager
=
require
(
'../../src/trace/traceManager'
)
var
CodeManager
=
require
(
'../../src/code/codeManager'
)
var
TraceManager
=
require
(
'../../
babelify-
src/trace/traceManager'
)
var
CodeManager
=
require
(
'../../
babelify-
src/code/codeManager'
)
var
VM
=
require
(
'ethereumjs-vm'
)
var
Tx
=
require
(
'ethereumjs-tx'
)
var
Block
=
require
(
'ethereumjs-block'
)
var
BN
=
require
(
'ethereumjs-util'
).
BN
var
utileth
=
require
(
'ethereumjs-util'
)
var
Web3Providers
=
require
(
'../../src/web3Provider/web3Providers'
)
var
traceHelper
=
require
(
'../../src/helpers/traceHelper'
)
var
util
=
require
(
'../../src/helpers/global'
)
var
SolidityProxy
=
require
(
'../../src/solidity/solidityProxy'
)
var
InternalCallTree
=
require
(
'../../src/util/internalCallTree'
)
var
EventManager
=
require
(
'../../src/lib/eventManager'
)
var
localDecoder
=
require
(
'../../src/solidity/localDecoder'
)
var
Web3Providers
=
require
(
'../../
babelify-
src/web3Provider/web3Providers'
)
var
traceHelper
=
require
(
'../../
babelify-
src/helpers/traceHelper'
)
var
util
=
require
(
'../../
babelify-
src/helpers/global'
)
var
SolidityProxy
=
require
(
'../../
babelify-
src/solidity/solidityProxy'
)
var
InternalCallTree
=
require
(
'../../
babelify-
src/util/internalCallTree'
)
var
EventManager
=
require
(
'../../
babelify-
src/lib/eventManager'
)
var
localDecoder
=
require
(
'../../
babelify-
src/solidity/localDecoder'
)
tape
(
'solidity'
,
function
(
t
)
{
t
.
test
(
'local decoder'
,
function
(
st
)
{
...
...
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