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
e85fd4ce
Commit
e85fd4ce
authored
Nov 28, 2016
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix rebasing from decodeComplexType
parent
3a4a36d0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
96 deletions
+28
-96
ArrayType.js
src/solidity/types/ArrayType.js
+3
-3
util.js
src/solidity/types/util.js
+19
-46
storageDecoder.js
test/solidity/storageDecoder.js
+6
-47
No files found.
src/solidity/types/ArrayType.js
View file @
e85fd4ce
...
@@ -23,7 +23,7 @@ function ArrayType (underlyingType, arraySize) {
...
@@ -23,7 +23,7 @@ function ArrayType (underlyingType, arraySize) {
ArrayType
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
ArrayType
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
var
ret
=
[]
var
ret
=
[]
var
size
=
null
var
size
=
null
var
slotValue
=
util
.
extractValue
(
location
,
storageContent
,
this
.
storageBytes
)
var
slotValue
=
util
.
extract
Hex
Value
(
location
,
storageContent
,
this
.
storageBytes
)
if
(
!
slotValue
)
{
if
(
!
slotValue
)
{
return
[]
return
[]
}
}
...
@@ -32,8 +32,8 @@ ArrayType.prototype.decodeFromStorage = function (location, storageContent) {
...
@@ -32,8 +32,8 @@ ArrayType.prototype.decodeFromStorage = function (location, storageContent) {
slot
:
location
.
slot
slot
:
location
.
slot
}
}
if
(
this
.
arraySize
===
'dynamic'
)
{
if
(
this
.
arraySize
===
'dynamic'
)
{
size
=
util
.
toBN
(
slotValue
)
size
=
util
.
toBN
(
'0x'
+
slotValue
)
currentLocation
.
slot
=
util
.
dynamicTypePointer
(
location
.
slot
)
currentLocation
.
slot
=
util
.
sha3
(
location
.
slot
)
if
(
!
storageContent
[
currentLocation
.
slot
])
{
if
(
!
storageContent
[
currentLocation
.
slot
])
{
return
[]
return
[]
}
}
...
...
src/solidity/types/util.js
View file @
e85fd4ce
...
@@ -6,7 +6,9 @@ module.exports = {
...
@@ -6,7 +6,9 @@ module.exports = {
readFromStorage
:
readFromStorage
,
readFromStorage
:
readFromStorage
,
decodeInt
:
decodeInt
,
decodeInt
:
decodeInt
,
extractHexValue
:
extractHexValue
,
extractHexValue
:
extractHexValue
,
sha3
:
sha3
sha3
:
sha3
,
toBN
:
toBN
,
add
:
add
}
}
function
decodeInt
(
location
,
storageContent
,
byteLength
,
signed
)
{
function
decodeInt
(
location
,
storageContent
,
byteLength
,
signed
)
{
...
@@ -31,36 +33,6 @@ function readFromStorage (slot, storageContent) {
...
@@ -31,36 +33,6 @@ function readFromStorage (slot, storageContent) {
}
else
{
}
else
{
ret
=
'000000000000000000000000000000000000000000000000000000000000000'
ret
=
'000000000000000000000000000000000000000000000000000000000000000'
}
}
return
extractSlotValue
(
storageContent
[
slot
],
storageBytes
,
location
)
},
dynamicTypePointer
:
function
(
slot
)
{
var
remoteSlot
=
toLongHex
(
slot
)
var
key
=
ethutil
.
sha3
(
remoteSlot
)
return
ethutil
.
bufferToHex
(
key
)
},
toLongHex
:
toLongHex
,
toBN
:
toBN
,
add
:
add
}
function
toLongHex
(
slot
)
{
if
(
slot
instanceof
BN
)
{
slot
=
'0x'
+
slot
.
toString
(
16
)
}
return
ethutil
.
bufferToHex
(
ethutil
.
setLengthLeft
(
slot
,
32
))
}
function
extractSlotValue
(
slotValue
,
storageBytes
,
location
)
{
slotValue
=
slotValue
.
replace
(
'0x'
,
''
)
var
offset
=
slotValue
.
length
-
2
*
location
.
offset
-
2
*
storageBytes
if
(
offset
>=
0
)
{
return
'0x'
+
slotValue
.
substr
(
offset
,
2
*
storageBytes
)
}
else
if
(
offset
+
2
*
storageBytes
>
0
)
{
return
'0x'
+
slotValue
.
substr
(
0
,
2
*
storageBytes
+
offset
)
}
else
{
return
'0x0'
}
}
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
...
@@ -80,21 +52,6 @@ function extractHexByteSlice (slotValue, byteLength, offsetFromLSB) {
...
@@ -80,21 +52,6 @@ function extractHexByteSlice (slotValue, byteLength, offsetFromLSB) {
return
slotValue
.
substr
(
offset
,
2
*
byteLength
)
return
slotValue
.
substr
(
offset
,
2
*
byteLength
)
}
}
function
toBN
(
value
)
{
if
(
value
instanceof
BN
)
{
return
value
}
else
if
(
value
.
indexOf
&&
value
.
indexOf
(
'0x'
)
===
0
)
{
value
=
ethutil
.
unpad
(
value
.
replace
(
'Ox'
,
''
))
value
=
new
BN
(
value
===
''
?
'0'
:
value
,
16
)
}
else
if
(
!
isNaN
(
value
))
{
value
=
new
BN
(
value
)
}
return
value
}
function
add
(
value1
,
value2
)
{
return
toBN
(
value1
).
add
(
toBN
(
value2
))
}
/**
/**
* @returns a hex encoded storage content at the given @arg location. it does not have Ox prefix but always has the full length.
* @returns a hex encoded storage content at the given @arg location. it does not have Ox prefix but always has the full length.
*
*
...
@@ -112,3 +69,19 @@ function sha3 (slot) {
...
@@ -112,3 +69,19 @@ function sha3 (slot) {
var
key
=
ethutil
.
sha3
(
remoteSlot
)
var
key
=
ethutil
.
sha3
(
remoteSlot
)
return
ethutil
.
bufferToHex
(
key
)
return
ethutil
.
bufferToHex
(
key
)
}
}
function
toBN
(
value
)
{
if
(
value
instanceof
BN
)
{
return
value
}
else
if
(
value
.
indexOf
&&
value
.
indexOf
(
'0x'
)
===
0
)
{
value
=
ethutil
.
unpad
(
value
.
replace
(
'Ox'
,
''
))
value
=
new
BN
(
value
===
''
?
'0'
:
value
,
16
)
}
else
if
(
!
isNaN
(
value
))
{
value
=
new
BN
(
value
)
}
return
value
}
function
add
(
value1
,
value2
)
{
return
toBN
(
value1
).
add
(
toBN
(
value2
))
}
test/solidity/storageDecoder.js
View file @
e85fd4ce
...
@@ -55,47 +55,6 @@ function testIntStorage (st) {
...
@@ -55,47 +55,6 @@ function testIntStorage (st) {
function
testByteStorage
(
st
)
{
function
testByteStorage
(
st
)
{
var
byteStorage
=
require
(
'./contracts/byteStorage'
)
var
byteStorage
=
require
(
'./contracts/byteStorage'
)
var
output
=
compiler
.
compile
(
byteStorage
.
contract
,
0
)
var
output
=
compiler
.
compile
(
byteStorage
.
contract
,
0
)
var
decoded
=
stateDecoder
.
solidityState
(
byteStorage
.
storage
,
output
.
sources
,
'byteStorage'
)
st
.
equal
(
decoded
[
'b1'
],
false
)
st
.
equal
(
decoded
[
'a1'
],
'0xfe350f199f244ac9a79038d254400b632a633225'
)
st
.
equal
(
decoded
[
'b2'
],
true
)
st
.
equal
(
decoded
[
'dynb1'
],
'0x64796e616d69636279746573'
)
st
.
equal
(
decoded
[
'stab'
],
'0x1'
)
st
.
equal
(
decoded
[
'stab1'
],
'0x12'
)
st
.
equal
(
decoded
[
'stab2'
],
'0x1579'
)
st
.
equal
(
decoded
[
'stab3'
],
'0x359356'
)
st
.
equal
(
decoded
[
'stab4'
],
'0x2375'
)
st
.
equal
(
decoded
[
'stab5'
],
'0x2357645'
)
st
.
equal
(
decoded
[
'stab6'
],
'0x324435'
)
st
.
equal
(
decoded
[
'stab7'
],
'0x324324'
)
st
.
equal
(
decoded
[
'stab8'
],
'0x324554645765'
)
st
.
equal
(
decoded
[
'stab9'
],
'0x3434543'
)
st
.
equal
(
decoded
[
'stab10'
],
'0x4543543654657'
)
st
.
equal
(
decoded
[
'stab11'
],
'0x54354654'
)
st
.
equal
(
decoded
[
'stab12'
],
'0x3'
)
st
.
equal
(
decoded
[
'stab13'
],
'0x3243242345435'
)
st
.
equal
(
decoded
[
'stab14'
],
'0x32454354354353'
)
st
.
equal
(
decoded
[
'stab15'
],
'0x32454434435'
)
st
.
equal
(
decoded
[
'stab16'
],
'0x3245435444'
)
st
.
equal
(
decoded
[
'stab17'
],
'0x32454343243243245'
)
st
.
equal
(
decoded
[
'stab18'
],
'0x324534325435435'
)
st
.
equal
(
decoded
[
'stab19'
],
'0x324543435435435'
)
st
.
equal
(
decoded
[
'stab20'
],
'0x32454543543AB35'
)
st
.
equal
(
decoded
[
'stab21'
],
'0x32454432423435'
)
st
.
equal
(
decoded
[
'stab22'
],
'0x324543AEF5'
)
st
.
equal
(
decoded
[
'stab23'
],
'0x3245435FFF'
)
st
.
equal
(
decoded
[
'stab24'
],
'0x3245435F'
)
st
.
equal
(
decoded
[
'stab25'
],
'0x3245435F'
)
st
.
equal
(
decoded
[
'stab26'
],
'0x3245435F'
)
st
.
equal
(
decoded
[
'stab27'
],
'0x3245FFFFFFF'
)
st
.
equal
(
decoded
[
'stab28'
],
'0x3241235'
)
st
.
equal
(
decoded
[
'stab29'
],
'0x325213213'
)
st
.
equal
(
decoded
[
'stab30'
],
'0x3245435232423'
)
st
.
equal
(
decoded
[
'stab31'
],
'0x3245435123'
)
st
.
equal
(
decoded
[
'stab32'
],
'0x324324423432543543AB'
)
st
.
equal
(
decoded
[
'enumDec'
],
'd'
)
st
.
equal
(
decoded
[
'str1'
],
'short'
)
st
.
equal
(
decoded
[
'str2'
],
'long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long__long'
)
for
(
var
storage
of
[
byteStorage
.
storage
,
shrinkStorage
(
byteStorage
.
storage
)])
{
for
(
var
storage
of
[
byteStorage
.
storage
,
shrinkStorage
(
byteStorage
.
storage
)])
{
var
decoded
=
stateDecoder
.
solidityState
(
storage
,
output
.
sources
,
'byteStorage'
)
var
decoded
=
stateDecoder
.
solidityState
(
storage
,
output
.
sources
,
'byteStorage'
)
st
.
equal
(
decoded
[
'b1'
],
false
)
st
.
equal
(
decoded
[
'b1'
],
false
)
...
@@ -270,15 +229,15 @@ function testStructArrayStorage (st) {
...
@@ -270,15 +229,15 @@ function testStructArrayStorage (st) {
st
.
equal
(
decoded
[
'dyn2'
][
1
][
3
][
1
],
'-23'
)
st
.
equal
(
decoded
[
'dyn2'
][
1
][
3
][
1
],
'-23'
)
st
.
equal
(
decoded
[
'dyn2'
][
1
][
3
][
2
],
'-28'
)
st
.
equal
(
decoded
[
'dyn2'
][
1
][
3
][
2
],
'-28'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
0
][
0
].
i8
,
'34'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
0
][
0
].
i8
,
'34'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
0
][
0
].
str
,
'test_str_short'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
0
][
0
].
str
.
value
,
'test_str_short'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
0
][
1
].
i8
,
'-123'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
0
][
1
].
i8
,
'-123'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
0
][
1
].
str
,
'test_str_long test_str_lo ngtest_str_longtest_str_ longtest_str_longtest_ str_longtest_str_l ongtest_str_long'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
0
][
1
].
str
.
value
,
'test_str_long test_str_lo ngtest_str_longtest_str_ longtest_str_longtest_ str_longtest_str_l ongtest_str_long'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
1
][
0
].
i8
,
'50'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
1
][
0
].
i8
,
'50'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
1
][
0
].
str
,
'test_str_short'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
1
][
0
].
str
.
value
,
'test_str_short'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
2
][
0
].
i8
,
'60'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
2
][
0
].
i8
,
'60'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
2
][
0
].
str
,
'test_str_short'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
2
][
0
].
str
.
value
,
'test_str_short'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
2
][
1
].
i8
,
'84'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
2
][
1
].
i8
,
'84'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
2
][
1
].
str
,
'test_str_long test_str_lo ngtest_str_longtest_str_ longtest_str_longtest_ str_longtest_str_l ongtest_str_long'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
2
][
1
].
str
.
value
,
'test_str_long test_str_lo ngtest_str_longtest_str_ longtest_str_longtest_ str_longtest_str_l ongtest_str_long'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
2
][
2
].
i8
,
'-34'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
2
][
2
].
i8
,
'-34'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
2
][
2
].
str
,
'test_str_short'
)
st
.
equal
(
decoded
[
'arrayStruct'
][
2
][
2
].
str
.
value
,
'test_str_short'
)
}
}
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