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
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
40 additions
and
40 deletions
+40
-40
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
+15
-20
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')
* @param {Map} storageContent - storage
* @return {Map} - decoded state variable
*/
function
decodeState
(
stateVars
,
storageContent
)
{
async
function
decodeState
(
stateVars
,
storageContent
)
{
var
ret
=
{}
for
(
var
k
in
stateVars
)
{
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
}
...
...
src/solidity/types/ArrayType.js
View file @
668daa86
...
...
@@ -23,10 +23,10 @@ class ArrayType extends RefType {
this
.
arraySize
=
arraySize
}
decodeFromStorage
(
location
,
storageContent
)
{
async
decodeFromStorage
(
location
,
storageContent
)
{
var
ret
=
[]
var
size
=
null
var
slotValue
=
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
var
slotValue
=
await
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
var
currentLocation
=
{
offset
:
0
,
slot
:
location
.
slot
...
...
@@ -39,7 +39,8 @@ class ArrayType extends RefType {
}
var
k
=
util
.
toBN
(
0
)
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
)
{
currentLocation
.
offset
+=
this
.
underlyingType
.
storageBytes
if
(
currentLocation
.
offset
+
this
.
underlyingType
.
storageBytes
>
32
)
{
...
...
src/solidity/types/DynamicByteArray.js
View file @
668daa86
...
...
@@ -8,19 +8,19 @@ class DynamicByteArray extends RefType {
super
(
1
,
32
,
'bytes'
,
location
)
}
decodeFromStorage
(
location
,
storageContent
)
{
var
value
=
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
async
decodeFromStorage
(
location
,
storageContent
)
{
var
value
=
await
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
var
bn
=
new
BN
(
value
,
16
)
if
(
bn
.
testn
(
0
))
{
var
length
=
bn
.
div
(
new
BN
(
2
))
var
dataPos
=
new
BN
(
util
.
sha3
(
location
.
slot
).
replace
(
'0x'
,
''
),
16
)
var
ret
=
''
var
currentSlot
=
util
.
readFromStorage
(
dataPos
,
storageContent
)
var
currentSlot
=
await
util
.
readFromStorage
(
dataPos
,
storageContent
)
while
(
length
.
gt
(
ret
.
length
)
&&
ret
.
length
<
32000
)
{
currentSlot
=
currentSlot
.
replace
(
'0x'
,
''
)
ret
+=
currentSlot
dataPos
=
dataPos
.
add
(
new
BN
(
1
))
currentSlot
=
util
.
readFromStorage
(
dataPos
,
storageContent
)
currentSlot
=
await
util
.
readFromStorage
(
dataPos
,
storageContent
)
}
return
{
value
:
'0x'
+
ret
.
replace
(
/
(
00
)
+$/
,
''
),
...
...
src/solidity/types/Mapping.js
View file @
668daa86
...
...
@@ -6,7 +6,7 @@ class Mapping extends RefType {
super
(
1
,
32
,
'mapping'
,
'storage'
)
}
decodeFromStorage
(
location
,
storageContent
)
{
async
decodeFromStorage
(
location
,
storageContent
)
{
return
{
value
:
'<not implemented>'
,
length
:
'0x'
,
...
...
src/solidity/types/RefType.js
View file @
668daa86
...
...
@@ -19,7 +19,7 @@ class RefType {
* @param {Object} - storage
* @return {Object} decoded value
*/
decodeFromStack
(
stackDepth
,
stack
,
memory
,
storage
)
{
async
decodeFromStack
(
stackDepth
,
stack
,
memory
,
storage
)
{
if
(
stack
.
length
-
1
<
stackDepth
)
{
return
{
error
:
'<decoding failed - stack underflow '
+
stackDepth
+
'>'
,
...
...
@@ -32,7 +32,7 @@ class RefType {
var
offset
=
stack
[
stack
.
length
-
1
-
stackDepth
]
if
(
this
.
isInStorage
())
{
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
())
{
offset
=
parseInt
(
offset
,
16
)
return
this
.
decodeFromMemoryInternal
(
offset
,
memory
)
...
...
src/solidity/types/StringType.js
View file @
668daa86
...
...
@@ -7,8 +7,8 @@ class StringType extends DynamicBytes {
this
.
typeName
=
'string'
}
decodeFromStorage
(
location
,
storageContent
)
{
var
decoded
=
super
.
decodeFromStorage
(
location
,
storageContent
)
async
decodeFromStorage
(
location
,
storageContent
)
{
var
decoded
=
await
super
.
decodeFromStorage
(
location
,
storageContent
)
return
format
(
decoded
)
}
...
...
src/solidity/types/Struct.js
View file @
668daa86
...
...
@@ -8,14 +8,14 @@ class Struct extends RefType {
this
.
members
=
memberDetails
.
members
}
decodeFromStorage
(
location
,
storageContent
)
{
async
decodeFromStorage
(
location
,
storageContent
)
{
var
ret
=
{}
this
.
members
.
map
(
function
(
item
,
i
)
{
this
.
members
.
map
(
async
(
item
,
i
)
=>
{
var
globalLocation
=
{
offset
:
location
.
offset
+
item
.
storagelocation
.
offset
,
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
{
value
:
ret
,
...
...
src/solidity/types/ValueType.js
View file @
668daa86
...
...
@@ -16,8 +16,8 @@ class ValueType {
* @param {Object} storageContent - storageContent (storage)
* @return {Object} - decoded value
*/
decodeFromStorage
(
location
,
storageContent
)
{
var
value
=
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
async
decodeFromStorage
(
location
,
storageContent
)
{
var
value
=
await
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
return
{
value
:
this
.
decodeValue
(
value
),
type
:
this
.
typeName
...
...
src/solidity/types/util.js
View file @
668daa86
...
...
@@ -4,7 +4,6 @@ var BN = require('ethereumjs-util').BN
module
.
exports
=
{
readFromStorage
:
readFromStorage
,
decodeInt
:
decodeInt
,
decodeIntFromHex
:
decodeIntFromHex
,
extractHexValue
:
extractHexValue
,
extractHexByteSlice
:
extractHexByteSlice
,
...
...
@@ -15,12 +14,6 @@ module.exports = {
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
)
{
var
bigNumber
=
new
BN
(
value
,
16
)
if
(
signed
)
{
...
...
@@ -29,23 +22,25 @@ function decodeIntFromHex (value, byteLength, signed) {
return
bigNumber
.
toString
(
10
)
}
function
readFromStorage
(
slot
,
storageContent
)
{
async
function
readFromStorage
(
slot
,
storageContent
)
{
var
ret
var
hexSlot
=
ethutil
.
bufferToHex
(
slot
)
if
(
storageContent
[
hexSlot
]
!==
undefined
)
{
ret
=
storageContent
[
hexSlot
].
replace
(
/^0x/
,
''
)
}
else
{
hexSlot
=
ethutil
.
bufferToHex
(
ethutil
.
setLengthLeft
(
slot
,
32
))
return
new
Promise
((
resolve
,
reject
)
=>
{
if
(
storageContent
[
hexSlot
]
!==
undefined
)
{
ret
=
storageContent
[
hexSlot
].
replace
(
/^0x/
,
''
)
}
else
{
ret
=
'000000000000000000000000000000000000000000000000000000000000000'
hexSlot
=
ethutil
.
bufferToHex
(
ethutil
.
setLengthLeft
(
slot
,
32
))
if
(
storageContent
[
hexSlot
]
!==
undefined
)
{
ret
=
storageContent
[
hexSlot
].
replace
(
/^0x/
,
''
)
}
else
{
ret
=
'000000000000000000000000000000000000000000000000000000000000000'
}
}
}
if
(
ret
.
length
<
64
)
{
ret
=
(
new
Array
(
64
-
ret
.
length
+
1
).
join
(
'0'
))
+
ret
}
return
ret
if
(
ret
.
length
<
64
)
{
ret
=
(
new
Array
(
64
-
ret
.
length
+
1
).
join
(
'0'
))
+
ret
}
return
resolve
(
ret
)
})
}
/**
...
...
@@ -67,8 +62,8 @@ function extractHexByteSlice (slotValue, byteLength, offsetFromLSB) {
* @param {Object} storageContent - full storage mapping.
* @param {Int} byteLength - Length of the byte slice to extract
*/
function
extractHexValue
(
location
,
storageContent
,
byteLength
)
{
var
slotvalue
=
readFromStorage
(
location
.
slot
,
storageContent
)
async
function
extractHexValue
(
location
,
storageContent
,
byteLength
)
{
var
slotvalue
=
await
readFromStorage
(
location
.
slot
,
storageContent
)
return
extractHexByteSlice
(
slotvalue
,
byteLength
,
location
.
offset
)
}
...
...
src/ui/SolidityState.js
View file @
668daa86
...
...
@@ -52,7 +52,11 @@ SolidityState.prototype.init = function () {
self
.
basicPanel
.
update
({})
console
.
log
(
error
)
}
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