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
668daa86
Commit
668daa86
authored
Mar 14, 2017
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make retrieve value from storage async
parent
734bd145
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
31 additions
and
31 deletions
+31
-31
stateDecoder.js
src/solidity/stateDecoder.js
+2
-2
ArrayType.js
src/solidity/types/ArrayType.js
+4
-3
DynamicByteArray.js
src/solidity/types/DynamicByteArray.js
+4
-4
Mapping.js
src/solidity/types/Mapping.js
+1
-1
RefType.js
src/solidity/types/RefType.js
+2
-2
StringType.js
src/solidity/types/StringType.js
+2
-2
Struct.js
src/solidity/types/Struct.js
+3
-3
ValueType.js
src/solidity/types/ValueType.js
+2
-2
util.js
src/solidity/types/util.js
+6
-11
SolidityState.js
src/ui/SolidityState.js
+5
-1
No files found.
src/solidity/stateDecoder.js
View file @
668daa86
...
@@ -8,11 +8,11 @@ var decodeInfo = require('./decodeInfo')
...
@@ -8,11 +8,11 @@ var decodeInfo = require('./decodeInfo')
* @param {Map} storageContent - storage
* @param {Map} storageContent - storage
* @return {Map} - decoded state variable
* @return {Map} - decoded state variable
*/
*/
function
decodeState
(
stateVars
,
storageContent
)
{
async
function
decodeState
(
stateVars
,
storageContent
)
{
var
ret
=
{}
var
ret
=
{}
for
(
var
k
in
stateVars
)
{
for
(
var
k
in
stateVars
)
{
var
stateVar
=
stateVars
[
k
]
var
stateVar
=
stateVars
[
k
]
ret
[
stateVar
.
name
]
=
stateVar
.
type
.
decodeFromStorage
(
stateVar
.
storagelocation
,
storageContent
)
ret
[
stateVar
.
name
]
=
await
stateVar
.
type
.
decodeFromStorage
(
stateVar
.
storagelocation
,
storageContent
)
}
}
return
ret
return
ret
}
}
...
...
src/solidity/types/ArrayType.js
View file @
668daa86
...
@@ -23,10 +23,10 @@ class ArrayType extends RefType {
...
@@ -23,10 +23,10 @@ class ArrayType extends RefType {
this
.
arraySize
=
arraySize
this
.
arraySize
=
arraySize
}
}
decodeFromStorage
(
location
,
storageContent
)
{
async
decodeFromStorage
(
location
,
storageContent
)
{
var
ret
=
[]
var
ret
=
[]
var
size
=
null
var
size
=
null
var
slotValue
=
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
var
slotValue
=
await
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
var
currentLocation
=
{
var
currentLocation
=
{
offset
:
0
,
offset
:
0
,
slot
:
location
.
slot
slot
:
location
.
slot
...
@@ -39,7 +39,8 @@ class ArrayType extends RefType {
...
@@ -39,7 +39,8 @@ 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
))
{
ret
.
push
(
this
.
underlyingType
.
decodeFromStorage
(
currentLocation
,
storageContent
))
var
item
=
await
this
.
underlyingType
.
decodeFromStorage
(
currentLocation
,
storageContent
)
ret
.
push
(
item
)
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 @
668daa86
...
@@ -8,19 +8,19 @@ class DynamicByteArray extends RefType {
...
@@ -8,19 +8,19 @@ class DynamicByteArray extends RefType {
super
(
1
,
32
,
'bytes'
,
location
)
super
(
1
,
32
,
'bytes'
,
location
)
}
}
decodeFromStorage
(
location
,
storageContent
)
{
async
decodeFromStorage
(
location
,
storageContent
)
{
var
value
=
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
var
value
=
await
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
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
(
util
.
sha3
(
location
.
slot
).
replace
(
'0x'
,
''
),
16
)
var
dataPos
=
new
BN
(
util
.
sha3
(
location
.
slot
).
replace
(
'0x'
,
''
),
16
)
var
ret
=
''
var
ret
=
''
var
currentSlot
=
util
.
readFromStorage
(
dataPos
,
storageContent
)
var
currentSlot
=
await
util
.
readFromStorage
(
dataPos
,
storageContent
)
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
))
currentSlot
=
util
.
readFromStorage
(
dataPos
,
storageContent
)
currentSlot
=
await
util
.
readFromStorage
(
dataPos
,
storageContent
)
}
}
return
{
return
{
value
:
'0x'
+
ret
.
replace
(
/
(
00
)
+$/
,
''
),
value
:
'0x'
+
ret
.
replace
(
/
(
00
)
+$/
,
''
),
...
...
src/solidity/types/Mapping.js
View file @
668daa86
...
@@ -6,7 +6,7 @@ class Mapping extends RefType {
...
@@ -6,7 +6,7 @@ class Mapping extends RefType {
super
(
1
,
32
,
'mapping'
,
'storage'
)
super
(
1
,
32
,
'mapping'
,
'storage'
)
}
}
decodeFromStorage
(
location
,
storageContent
)
{
async
decodeFromStorage
(
location
,
storageContent
)
{
return
{
return
{
value
:
'<not implemented>'
,
value
:
'<not implemented>'
,
length
:
'0x'
,
length
:
'0x'
,
...
...
src/solidity/types/RefType.js
View file @
668daa86
...
@@ -19,7 +19,7 @@ class RefType {
...
@@ -19,7 +19,7 @@ class RefType {
* @param {Object} - storage
* @param {Object} - storage
* @return {Object} decoded value
* @return {Object} decoded value
*/
*/
decodeFromStack
(
stackDepth
,
stack
,
memory
,
storage
)
{
async
decodeFromStack
(
stackDepth
,
stack
,
memory
,
storage
)
{
if
(
stack
.
length
-
1
<
stackDepth
)
{
if
(
stack
.
length
-
1
<
stackDepth
)
{
return
{
return
{
error
:
'<decoding failed - stack underflow '
+
stackDepth
+
'>'
,
error
:
'<decoding failed - stack underflow '
+
stackDepth
+
'>'
,
...
@@ -32,7 +32,7 @@ class RefType {
...
@@ -32,7 +32,7 @@ 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
)
return
this
.
decodeFromStorage
({
offset
:
0
,
slot
:
offset
},
storage
)
return
await
this
.
decodeFromStorage
({
offset
:
0
,
slot
:
offset
},
storage
)
}
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 @
668daa86
...
@@ -7,8 +7,8 @@ class StringType extends DynamicBytes {
...
@@ -7,8 +7,8 @@ class StringType extends DynamicBytes {
this
.
typeName
=
'string'
this
.
typeName
=
'string'
}
}
decodeFromStorage
(
location
,
storageContent
)
{
async
decodeFromStorage
(
location
,
storageContent
)
{
var
decoded
=
super
.
decodeFromStorage
(
location
,
storageContent
)
var
decoded
=
await
super
.
decodeFromStorage
(
location
,
storageContent
)
return
format
(
decoded
)
return
format
(
decoded
)
}
}
...
...
src/solidity/types/Struct.js
View file @
668daa86
...
@@ -8,14 +8,14 @@ class Struct extends RefType {
...
@@ -8,14 +8,14 @@ class Struct extends RefType {
this
.
members
=
memberDetails
.
members
this
.
members
=
memberDetails
.
members
}
}
decodeFromStorage
(
location
,
storageContent
)
{
async
decodeFromStorage
(
location
,
storageContent
)
{
var
ret
=
{}
var
ret
=
{}
this
.
members
.
map
(
function
(
item
,
i
)
{
this
.
members
.
map
(
async
(
item
,
i
)
=>
{
var
globalLocation
=
{
var
globalLocation
=
{
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
)
}
}
ret
[
item
.
name
]
=
item
.
type
.
decodeFromStorage
(
globalLocation
,
storageContent
)
ret
[
item
.
name
]
=
await
item
.
type
.
decodeFromStorage
(
globalLocation
,
storageContent
)
})
})
return
{
return
{
value
:
ret
,
value
:
ret
,
...
...
src/solidity/types/ValueType.js
View file @
668daa86
...
@@ -16,8 +16,8 @@ class ValueType {
...
@@ -16,8 +16,8 @@ class ValueType {
* @param {Object} storageContent - storageContent (storage)
* @param {Object} storageContent - storageContent (storage)
* @return {Object} - decoded value
* @return {Object} - decoded value
*/
*/
decodeFromStorage
(
location
,
storageContent
)
{
async
decodeFromStorage
(
location
,
storageContent
)
{
var
value
=
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
var
value
=
await
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
return
{
return
{
value
:
this
.
decodeValue
(
value
),
value
:
this
.
decodeValue
(
value
),
type
:
this
.
typeName
type
:
this
.
typeName
...
...
src/solidity/types/util.js
View file @
668daa86
...
@@ -4,7 +4,6 @@ var BN = require('ethereumjs-util').BN
...
@@ -4,7 +4,6 @@ var BN = require('ethereumjs-util').BN
module
.
exports
=
{
module
.
exports
=
{
readFromStorage
:
readFromStorage
,
readFromStorage
:
readFromStorage
,
decodeInt
:
decodeInt
,
decodeIntFromHex
:
decodeIntFromHex
,
decodeIntFromHex
:
decodeIntFromHex
,
extractHexValue
:
extractHexValue
,
extractHexValue
:
extractHexValue
,
extractHexByteSlice
:
extractHexByteSlice
,
extractHexByteSlice
:
extractHexByteSlice
,
...
@@ -15,12 +14,6 @@ module.exports = {
...
@@ -15,12 +14,6 @@ module.exports = {
removeLocation
:
removeLocation
removeLocation
:
removeLocation
}
}
function
decodeInt
(
location
,
storageContent
,
byteLength
,
signed
)
{
var
slotvalue
=
readFromStorage
(
location
.
slot
,
storageContent
)
var
value
=
extractHexByteSlice
(
slotvalue
,
byteLength
,
location
.
offset
)
return
decodeIntFromHex
(
value
,
byteLength
,
signed
)
}
function
decodeIntFromHex
(
value
,
byteLength
,
signed
)
{
function
decodeIntFromHex
(
value
,
byteLength
,
signed
)
{
var
bigNumber
=
new
BN
(
value
,
16
)
var
bigNumber
=
new
BN
(
value
,
16
)
if
(
signed
)
{
if
(
signed
)
{
...
@@ -29,9 +22,10 @@ function decodeIntFromHex (value, byteLength, signed) {
...
@@ -29,9 +22,10 @@ function decodeIntFromHex (value, byteLength, signed) {
return
bigNumber
.
toString
(
10
)
return
bigNumber
.
toString
(
10
)
}
}
function
readFromStorage
(
slot
,
storageContent
)
{
async
function
readFromStorage
(
slot
,
storageContent
)
{
var
ret
var
ret
var
hexSlot
=
ethutil
.
bufferToHex
(
slot
)
var
hexSlot
=
ethutil
.
bufferToHex
(
slot
)
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
storageContent
[
hexSlot
]
!==
undefined
)
{
if
(
storageContent
[
hexSlot
]
!==
undefined
)
{
ret
=
storageContent
[
hexSlot
].
replace
(
/^0x/
,
''
)
ret
=
storageContent
[
hexSlot
].
replace
(
/^0x/
,
''
)
}
else
{
}
else
{
...
@@ -45,7 +39,8 @@ function readFromStorage (slot, storageContent) {
...
@@ -45,7 +39,8 @@ function readFromStorage (slot, storageContent) {
if
(
ret
.
length
<
64
)
{
if
(
ret
.
length
<
64
)
{
ret
=
(
new
Array
(
64
-
ret
.
length
+
1
).
join
(
'0'
))
+
ret
ret
=
(
new
Array
(
64
-
ret
.
length
+
1
).
join
(
'0'
))
+
ret
}
}
return
ret
return
resolve
(
ret
)
})
}
}
/**
/**
...
@@ -67,8 +62,8 @@ function extractHexByteSlice (slotValue, byteLength, offsetFromLSB) {
...
@@ -67,8 +62,8 @@ function extractHexByteSlice (slotValue, byteLength, offsetFromLSB) {
* @param {Object} storageContent - full storage mapping.
* @param {Object} storageContent - full storage mapping.
* @param {Int} byteLength - Length of the byte slice to extract
* @param {Int} byteLength - Length of the byte slice to extract
*/
*/
function
extractHexValue
(
location
,
storageContent
,
byteLength
)
{
async
function
extractHexValue
(
location
,
storageContent
,
byteLength
)
{
var
slotvalue
=
readFromStorage
(
location
.
slot
,
storageContent
)
var
slotvalue
=
await
readFromStorage
(
location
.
slot
,
storageContent
)
return
extractHexByteSlice
(
slotvalue
,
byteLength
,
location
.
offset
)
return
extractHexByteSlice
(
slotvalue
,
byteLength
,
location
.
offset
)
}
}
...
...
src/ui/SolidityState.js
View file @
668daa86
...
@@ -52,7 +52,11 @@ SolidityState.prototype.init = function () {
...
@@ -52,7 +52,11 @@ SolidityState.prototype.init = function () {
self
.
basicPanel
.
update
({})
self
.
basicPanel
.
update
({})
console
.
log
(
error
)
console
.
log
(
error
)
}
else
{
}
else
{
self
.
basicPanel
.
update
(
stateDecoder
.
decodeState
(
stateVars
,
storage
))
stateDecoder
.
decodeState
(
stateVars
,
storage
).
then
((
result
)
=>
{
if
(
!
result
.
error
)
{
self
.
basicPanel
.
update
(
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