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
8eab1ca4
Commit
8eab1ca4
authored
May 29, 2017
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mapping: cache the initial decoded state
parent
e40d76ef
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
42 deletions
+61
-42
Mapping.js
src/solidity/types/Mapping.js
+32
-19
storageViewer.js
src/storage/storageViewer.js
+28
-22
SolidityState.js
src/ui/SolidityState.js
+1
-1
No files found.
src/solidity/types/Mapping.js
View file @
8eab1ca4
...
@@ -8,30 +8,25 @@ class Mapping extends RefType {
...
@@ -8,30 +8,25 @@ class Mapping extends RefType {
super
(
1
,
32
,
fullType
,
'storage'
)
super
(
1
,
32
,
fullType
,
'storage'
)
this
.
keyType
=
underlyingTypes
.
keyType
this
.
keyType
=
underlyingTypes
.
keyType
this
.
valueType
=
underlyingTypes
.
valueType
this
.
valueType
=
underlyingTypes
.
valueType
this
.
initialDecodedState
=
null
}
}
async
decodeFromStorage
(
location
,
storageResolver
)
{
async
decodeFromStorage
(
location
,
storageResolver
)
{
var
mappingsPreimages
if
(
!
this
.
initialDecodedState
)
{
// cache the decoded initial storage
try
{
var
mappingsInitialPreimages
mappingsPreimages
=
await
storageResolver
.
mappingsLocation
()
try
{
}
catch
(
e
)
{
mappingsInitialPreimages
=
await
storageResolver
.
initialMappingsLocation
()
return
{
this
.
initialDecodedState
=
await
this
.
decodeMappingsLocation
(
mappingsInitialPreimages
,
location
,
storageResolver
)
value
:
e
.
message
,
}
catch
(
e
)
{
type
:
this
.
typeName
return
{
value
:
e
.
message
,
type
:
this
.
typeName
}
}
}
}
}
var
mapSlot
=
util
.
normalizeHex
(
ethutil
.
bufferToHex
(
location
.
slot
))
var
mappingPreimages
=
await
storageResolver
.
mappingsLocation
()
var
mappingPreimages
=
mappingsPreimages
[
mapSlot
]
var
ret
=
await
this
.
decodeMappingsLocation
(
mappingPreimages
,
location
,
storageResolver
)
// fetch mapping storage changes
var
ret
=
{}
ret
=
Object
.
assign
({},
this
.
initialDecodedState
,
ret
)
// merge changes
for
(
var
i
in
mappingPreimages
)
{
var
mapLocation
=
getMappingLocation
(
i
,
location
.
slot
)
var
globalLocation
=
{
offset
:
location
.
offset
,
slot
:
mapLocation
}
ret
[
i
]
=
await
this
.
valueType
.
decodeFromStorage
(
globalLocation
,
storageResolver
)
}
return
{
return
{
value
:
ret
,
value
:
ret
,
type
:
this
.
typeName
type
:
this
.
typeName
...
@@ -47,6 +42,24 @@ class Mapping extends RefType {
...
@@ -47,6 +42,24 @@ class Mapping extends RefType {
type
:
this
.
typeName
type
:
this
.
typeName
}
}
}
}
async
decodeMappingsLocation
(
preimages
,
location
,
storageResolver
)
{
var
mapSlot
=
util
.
normalizeHex
(
ethutil
.
bufferToHex
(
location
.
slot
))
if
(
!
preimages
[
mapSlot
])
{
return
{}
}
var
ret
=
{}
for
(
var
i
in
preimages
[
mapSlot
])
{
var
mapLocation
=
getMappingLocation
(
i
,
location
.
slot
)
var
globalLocation
=
{
offset
:
location
.
offset
,
slot
:
mapLocation
}
ret
[
i
]
=
await
this
.
valueType
.
decodeFromStorage
(
globalLocation
,
storageResolver
)
console
.
log
(
'global location'
,
globalLocation
,
i
,
ret
[
i
])
}
return
ret
}
}
}
function
getMappingLocation
(
key
,
position
)
{
function
getMappingLocation
(
key
,
position
)
{
...
...
src/storage/storageViewer.js
View file @
8eab1ca4
...
@@ -11,7 +11,8 @@ class StorageViewer {
...
@@ -11,7 +11,8 @@ class StorageViewer {
constructor
(
_context
,
_storageResolver
,
_traceManager
)
{
constructor
(
_context
,
_storageResolver
,
_traceManager
)
{
this
.
context
=
_context
this
.
context
=
_context
this
.
storageResolver
=
_storageResolver
this
.
storageResolver
=
_storageResolver
this
.
completeMapingsLocationPromise
=
null
this
.
initialMappingsLocationPromise
=
null
this
.
currentMappingsLocationPromise
=
null
_traceManager
.
accumulateStorageChanges
(
this
.
context
.
stepIndex
,
this
.
context
.
address
,
{},
(
error
,
storageChanges
)
=>
{
_traceManager
.
accumulateStorageChanges
(
this
.
context
.
stepIndex
,
this
.
context
.
address
,
{},
(
error
,
storageChanges
)
=>
{
if
(
!
error
)
{
if
(
!
error
)
{
this
.
storageChanges
=
storageChanges
this
.
storageChanges
=
storageChanges
...
@@ -67,38 +68,43 @@ class StorageViewer {
...
@@ -67,38 +68,43 @@ class StorageViewer {
}
}
/**
/**
* return all the possible mappings locations for the current context (cached)
* return all the possible mappings locations for the current context (cached)
do not return state changes during the current transaction
*
*
* @param {Function} callback
* @param {Function} callback
*/
*/
async
mappingsLocation
()
{
async
initialMappingsLocation
()
{
if
(
!
this
.
completeMapingsLocationPromise
)
{
if
(
!
this
.
initialMappingsLocationPromise
)
{
this
.
completeMapingsLocationPromise
=
new
Promise
((
resolve
,
reject
)
=>
{
this
.
initialMappingsLocationPromise
=
new
Promise
((
resolve
,
reject
)
=>
{
if
(
this
.
completeMappingsLocation
)
{
return
this
.
completeMappingsLocation
}
this
.
storageResolver
.
initialPreimagesMappings
(
this
.
context
.
tx
,
this
.
context
.
stepIndex
,
this
.
context
.
address
,
(
error
,
initialMappingsLocation
)
=>
{
this
.
storageResolver
.
initialPreimagesMappings
(
this
.
context
.
tx
,
this
.
context
.
stepIndex
,
this
.
context
.
address
,
(
error
,
initialMappingsLocation
)
=>
{
if
(
error
)
{
if
(
error
)
{
reject
(
error
)
reject
(
error
)
}
else
{
}
else
{
this
.
extractMappingsLocationChanges
(
this
.
storageChanges
,
(
error
,
mappingsLocationChanges
)
=>
{
resolve
(
initialMappingsLocation
)
if
(
error
)
{
}
return
reject
(
error
)
})
}
})
this
.
completeMappingsLocation
=
Object
.
assign
({},
initialMappingsLocation
)
}
for
(
var
key
in
mappingsLocationChanges
)
{
return
this
.
initialMappingsLocationPromise
if
(
!
initialMappingsLocation
[
key
])
{
}
initialMappingsLocation
[
key
]
=
{}
}
/**
this
.
completeMappingsLocation
[
key
]
=
Object
.
assign
({},
initialMappingsLocation
[
key
],
mappingsLocationChanges
[
key
])
* return all the possible mappings locations for the current context (cached) and current mapping slot. returns state changes during the current transaction
}
*
resolve
(
this
.
completeMappingsLocation
)
* @param {Function} callback
})
*/
async
mappingsLocation
()
{
if
(
!
this
.
currentMappingsLocationPromise
)
{
this
.
currentMappingsLocationPromise
=
new
Promise
((
resolve
,
reject
)
=>
{
this
.
extractMappingsLocationChanges
(
this
.
storageChanges
,
(
error
,
mappingsLocationChanges
)
=>
{
if
(
error
)
{
reject
(
error
)
}
else
{
resolve
(
mappingsLocationChanges
)
}
}
})
})
})
})
}
}
return
this
.
c
ompleteMa
pingsLocationPromise
return
this
.
c
urrentMap
pingsLocationPromise
}
}
/**
/**
...
...
src/ui/SolidityState.js
View file @
8eab1ca4
...
@@ -64,7 +64,7 @@ SolidityState.prototype.init = function () {
...
@@ -64,7 +64,7 @@ SolidityState.prototype.init = function () {
console
.
log
(
error
)
console
.
log
(
error
)
}
else
{
}
else
{
self
.
stateVariablesByAddresses
[
address
]
=
stateVars
self
.
stateVariablesByAddresses
[
address
]
=
stateVars
extractStateVariables
(
self
,
stateVars
)
extractStateVariables
(
self
,
stateVars
,
address
)
}
}
})
})
}
}
...
...
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