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
07335193
Commit
07335193
authored
Mar 15, 2017
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wrap awaited function by try/catch
parent
4ea30fae
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
100 additions
and
7 deletions
+100
-7
localDecoder.js
src/solidity/localDecoder.js
+5
-0
stateDecoder.js
src/solidity/stateDecoder.js
+9
-0
ArrayType.js
src/solidity/types/ArrayType.js
+18
-3
DynamicByteArray.js
src/solidity/types/DynamicByteArray.js
+28
-2
RefType.js
src/solidity/types/RefType.js
+8
-0
StringType.js
src/solidity/types/StringType.js
+12
-1
Struct.js
src/solidity/types/Struct.js
+5
-0
ValueType.js
src/solidity/types/ValueType.js
+8
-0
util.js
src/solidity/types/util.js
+7
-1
No files found.
src/solidity/localDecoder.js
View file @
07335193
...
@@ -17,7 +17,12 @@ async function solidityLocals (vmtraceIndex, internalTreeCall, stack, memory, st
...
@@ -17,7 +17,12 @@ async function solidityLocals (vmtraceIndex, internalTreeCall, stack, memory, st
name
=
'<'
+
anonymousIncr
+
'>'
name
=
'<'
+
anonymousIncr
+
'>'
anonymousIncr
++
anonymousIncr
++
}
}
try
{
locals
[
name
]
=
await
variable
.
type
.
decodeFromStack
(
variable
.
stackDepth
,
stack
,
memory
,
storageResolver
)
locals
[
name
]
=
await
variable
.
type
.
decodeFromStack
(
variable
.
stackDepth
,
stack
,
memory
,
storageResolver
)
}
catch
(
e
)
{
console
.
log
(
e
)
locals
[
name
]
=
'<decoding failed - '
+
e
.
message
+
'>'
}
}
}
}
}
return
locals
return
locals
...
...
src/solidity/stateDecoder.js
View file @
07335193
...
@@ -12,7 +12,12 @@ async function decodeState (stateVars, storageResolver) {
...
@@ -12,7 +12,12 @@ async function decodeState (stateVars, storageResolver) {
var
ret
=
{}
var
ret
=
{}
for
(
var
k
in
stateVars
)
{
for
(
var
k
in
stateVars
)
{
var
stateVar
=
stateVars
[
k
]
var
stateVar
=
stateVars
[
k
]
try
{
ret
[
stateVar
.
name
]
=
await
stateVar
.
type
.
decodeFromStorage
(
stateVar
.
storagelocation
,
storageResolver
)
ret
[
stateVar
.
name
]
=
await
stateVar
.
type
.
decodeFromStorage
(
stateVar
.
storagelocation
,
storageResolver
)
}
catch
(
e
)
{
console
.
log
(
e
)
ret
[
stateVar
.
name
]
=
'<decoding failed - '
+
e
.
message
+
'>'
}
}
}
return
ret
return
ret
}
}
...
@@ -47,7 +52,11 @@ function extractStateVariables (contractName, sourcesList) {
...
@@ -47,7 +52,11 @@ function extractStateVariables (contractName, sourcesList) {
*/
*/
async
function
solidityState
(
storageResolver
,
astList
,
contractName
)
{
async
function
solidityState
(
storageResolver
,
astList
,
contractName
)
{
var
stateVars
=
extractStateVariables
(
contractName
,
astList
)
var
stateVars
=
extractStateVariables
(
contractName
,
astList
)
try
{
return
await
decodeState
(
stateVars
,
storageResolver
)
return
await
decodeState
(
stateVars
,
storageResolver
)
}
catch
(
e
)
{
return
'<decoding failed - '
+
e
.
message
+
'>'
}
}
}
module
.
exports
=
{
module
.
exports
=
{
...
...
src/solidity/types/ArrayType.js
View file @
07335193
...
@@ -27,7 +27,16 @@ class ArrayType extends RefType {
...
@@ -27,7 +27,16 @@ class ArrayType extends RefType {
async
decodeFromStorage
(
location
,
storageResolver
)
{
async
decodeFromStorage
(
location
,
storageResolver
)
{
var
ret
=
[]
var
ret
=
[]
var
size
=
null
var
size
=
null
var
slotValue
=
await
util
.
extractHexValue
(
location
,
storageResolver
,
this
.
storageBytes
)
var
slotValue
try
{
slotValue
=
await
util
.
extractHexValue
(
location
,
storageResolver
,
this
.
storageBytes
)
}
catch
(
e
)
{
console
.
log
(
e
)
return
{
value
:
'<decoding failed - '
+
e
.
message
+
'>'
,
type
:
this
.
typeName
}
}
var
currentLocation
=
{
var
currentLocation
=
{
offset
:
0
,
offset
:
0
,
slot
:
location
.
slot
slot
:
location
.
slot
...
@@ -40,8 +49,14 @@ class ArrayType extends RefType {
...
@@ -40,8 +49,14 @@ class ArrayType extends RefType {
}
}
var
k
=
util
.
toBN
(
0
)
var
k
=
util
.
toBN
(
0
)
for
(;
k
.
lt
(
size
)
&&
k
.
ltn
(
300
);
k
.
iaddn
(
1
))
{
for
(;
k
.
lt
(
size
)
&&
k
.
ltn
(
300
);
k
.
iaddn
(
1
))
{
var
item
=
await
this
.
underlyingType
.
decodeFromStorage
(
currentLocation
,
storageResolver
)
try
{
ret
.
push
(
item
)
ret
.
push
(
await
this
.
underlyingType
.
decodeFromStorage
(
currentLocation
,
storageResolver
))
}
catch
(
e
)
{
return
{
value
:
'<decoding failed - '
+
e
.
message
+
'>'
,
type
:
this
.
typeName
}
}
if
(
this
.
underlyingType
.
storageSlots
===
1
&&
location
.
offset
+
this
.
underlyingType
.
storageBytes
<=
32
)
{
if
(
this
.
underlyingType
.
storageSlots
===
1
&&
location
.
offset
+
this
.
underlyingType
.
storageBytes
<=
32
)
{
currentLocation
.
offset
+=
this
.
underlyingType
.
storageBytes
currentLocation
.
offset
+=
this
.
underlyingType
.
storageBytes
if
(
currentLocation
.
offset
+
this
.
underlyingType
.
storageBytes
>
32
)
{
if
(
currentLocation
.
offset
+
this
.
underlyingType
.
storageBytes
>
32
)
{
...
...
src/solidity/types/DynamicByteArray.js
View file @
07335193
...
@@ -10,18 +10,44 @@ class DynamicByteArray extends RefType {
...
@@ -10,18 +10,44 @@ class DynamicByteArray extends RefType {
}
}
async
decodeFromStorage
(
location
,
storageResolver
)
{
async
decodeFromStorage
(
location
,
storageResolver
)
{
var
value
=
await
util
.
extractHexValue
(
location
,
storageResolver
,
this
.
storageBytes
)
var
value
=
'0x0'
try
{
value
=
await
util
.
extractHexValue
(
location
,
storageResolver
,
this
.
storageBytes
)
}
catch
(
e
)
{
console
.
log
(
e
)
return
{
value
:
'<decoding failed - '
+
e
.
message
+
'>'
,
type
:
this
.
typeName
}
}
var
bn
=
new
BN
(
value
,
16
)
var
bn
=
new
BN
(
value
,
16
)
if
(
bn
.
testn
(
0
))
{
if
(
bn
.
testn
(
0
))
{
var
length
=
bn
.
div
(
new
BN
(
2
))
var
length
=
bn
.
div
(
new
BN
(
2
))
var
dataPos
=
new
BN
(
helper
.
sha3
(
location
.
slot
).
replace
(
'0x'
,
''
),
16
)
var
dataPos
=
new
BN
(
helper
.
sha3
(
location
.
slot
).
replace
(
'0x'
,
''
),
16
)
var
ret
=
''
var
ret
=
''
var
currentSlot
=
await
util
.
readFromStorage
(
dataPos
,
storageResolver
)
var
currentSlot
=
'0x'
try
{
currentSlot
=
await
util
.
readFromStorage
(
dataPos
,
storageResolver
)
}
catch
(
e
)
{
console
.
log
(
e
)
return
{
value
:
'<decoding failed - '
+
e
.
message
+
'>'
,
type
:
this
.
typeName
}
}
while
(
length
.
gt
(
ret
.
length
)
&&
ret
.
length
<
32000
)
{
while
(
length
.
gt
(
ret
.
length
)
&&
ret
.
length
<
32000
)
{
currentSlot
=
currentSlot
.
replace
(
'0x'
,
''
)
currentSlot
=
currentSlot
.
replace
(
'0x'
,
''
)
ret
+=
currentSlot
ret
+=
currentSlot
dataPos
=
dataPos
.
add
(
new
BN
(
1
))
dataPos
=
dataPos
.
add
(
new
BN
(
1
))
try
{
currentSlot
=
await
util
.
readFromStorage
(
dataPos
,
storageResolver
)
currentSlot
=
await
util
.
readFromStorage
(
dataPos
,
storageResolver
)
}
catch
(
e
)
{
console
.
log
(
e
)
return
{
value
:
'<decoding failed - '
+
e
.
message
+
'>'
,
type
:
this
.
typeName
}
}
}
}
return
{
return
{
value
:
'0x'
+
ret
.
replace
(
/
(
00
)
+$/
,
''
),
value
:
'0x'
+
ret
.
replace
(
/
(
00
)
+$/
,
''
),
...
...
src/solidity/types/RefType.js
View file @
07335193
...
@@ -29,7 +29,15 @@ class RefType {
...
@@ -29,7 +29,15 @@ class RefType {
var
offset
=
stack
[
stack
.
length
-
1
-
stackDepth
]
var
offset
=
stack
[
stack
.
length
-
1
-
stackDepth
]
if
(
this
.
isInStorage
())
{
if
(
this
.
isInStorage
())
{
offset
=
util
.
toBN
(
offset
)
offset
=
util
.
toBN
(
offset
)
try
{
return
await
this
.
decodeFromStorage
({
offset
:
0
,
slot
:
offset
},
storageResolver
)
return
await
this
.
decodeFromStorage
({
offset
:
0
,
slot
:
offset
},
storageResolver
)
}
catch
(
e
)
{
console
.
log
(
e
)
return
{
error
:
'<decoding failed - '
+
e
.
message
+
'>'
,
type
:
this
.
typeName
}
}
}
else
if
(
this
.
isInMemory
())
{
}
else
if
(
this
.
isInMemory
())
{
offset
=
parseInt
(
offset
,
16
)
offset
=
parseInt
(
offset
,
16
)
return
this
.
decodeFromMemoryInternal
(
offset
,
memory
)
return
this
.
decodeFromMemoryInternal
(
offset
,
memory
)
...
...
src/solidity/types/StringType.js
View file @
07335193
...
@@ -8,12 +8,23 @@ class StringType extends DynamicBytes {
...
@@ -8,12 +8,23 @@ class StringType extends DynamicBytes {
}
}
async
decodeFromStorage
(
location
,
storageResolver
)
{
async
decodeFromStorage
(
location
,
storageResolver
)
{
var
decoded
=
await
super
.
decodeFromStorage
(
location
,
storageResolver
)
var
decoded
=
'0x'
try
{
decoded
=
await
super
.
decodeFromStorage
(
location
,
storageResolver
)
}
catch
(
e
)
{
console
.
log
(
e
)
return
'<decoding failed - '
+
e
.
message
+
'>'
}
return
format
(
decoded
)
return
format
(
decoded
)
}
}
async
decodeFromStack
(
stackDepth
,
stack
,
memory
)
{
async
decodeFromStack
(
stackDepth
,
stack
,
memory
)
{
try
{
return
await
super
.
decodeFromStack
(
stackDepth
,
stack
,
memory
)
return
await
super
.
decodeFromStack
(
stackDepth
,
stack
,
memory
)
}
catch
(
e
)
{
console
.
log
(
e
)
return
'<decoding failed - '
+
e
.
message
+
'>'
}
}
}
decodeFromMemoryInternal
(
offset
,
memory
)
{
decodeFromMemoryInternal
(
offset
,
memory
)
{
...
...
src/solidity/types/Struct.js
View file @
07335193
...
@@ -16,7 +16,12 @@ class Struct extends RefType {
...
@@ -16,7 +16,12 @@ class Struct extends RefType {
offset
:
location
.
offset
+
item
.
storagelocation
.
offset
,
offset
:
location
.
offset
+
item
.
storagelocation
.
offset
,
slot
:
util
.
add
(
location
.
slot
,
item
.
storagelocation
.
slot
)
slot
:
util
.
add
(
location
.
slot
,
item
.
storagelocation
.
slot
)
}
}
try
{
ret
[
item
.
name
]
=
await
item
.
type
.
decodeFromStorage
(
globalLocation
,
storageResolver
)
ret
[
item
.
name
]
=
await
item
.
type
.
decodeFromStorage
(
globalLocation
,
storageResolver
)
}
catch
(
e
)
{
console
.
log
(
e
)
ret
[
item
.
name
]
=
'<decoding failed - '
+
e
.
message
+
'>'
}
}
}
return
{
return
{
value
:
ret
,
value
:
ret
,
...
...
src/solidity/types/ValueType.js
View file @
07335193
...
@@ -17,11 +17,19 @@ class ValueType {
...
@@ -17,11 +17,19 @@ class ValueType {
* @return {Object} - decoded value
* @return {Object} - decoded value
*/
*/
async
decodeFromStorage
(
location
,
storageResolver
)
{
async
decodeFromStorage
(
location
,
storageResolver
)
{
try
{
var
value
=
await
util
.
extractHexValue
(
location
,
storageResolver
,
this
.
storageBytes
)
var
value
=
await
util
.
extractHexValue
(
location
,
storageResolver
,
this
.
storageBytes
)
return
{
return
{
value
:
this
.
decodeValue
(
value
),
value
:
this
.
decodeValue
(
value
),
type
:
this
.
typeName
type
:
this
.
typeName
}
}
}
catch
(
e
)
{
console
.
log
(
e
)
return
{
value
:
'<decoding failed - '
+
e
.
message
+
'>'
,
type
:
this
.
typeName
}
}
}
}
/**
/**
...
...
src/solidity/types/util.js
View file @
07335193
...
@@ -64,7 +64,13 @@ function extractHexByteSlice (slotValue, byteLength, offsetFromLSB) {
...
@@ -64,7 +64,13 @@ function extractHexByteSlice (slotValue, byteLength, offsetFromLSB) {
* @param {Int} byteLength - Length of the byte slice to extract
* @param {Int} byteLength - Length of the byte slice to extract
*/
*/
async
function
extractHexValue
(
location
,
storageResolver
,
byteLength
)
{
async
function
extractHexValue
(
location
,
storageResolver
,
byteLength
)
{
var
slotvalue
=
await
readFromStorage
(
location
.
slot
,
storageResolver
)
var
slotvalue
try
{
slotvalue
=
await
readFromStorage
(
location
.
slot
,
storageResolver
)
}
catch
(
e
)
{
console
.
log
(
e
)
return
'0x'
}
return
extractHexByteSlice
(
slotvalue
,
byteLength
,
location
.
offset
)
return
extractHexByteSlice
(
slotvalue
,
byteLength
,
location
.
offset
)
}
}
...
...
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