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
38786dbe
Commit
38786dbe
authored
Nov 17, 2016
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
decode:
- address - bool - dynamic byte array - enum - fixed byte array - string
parent
be8e28b6
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
230 additions
and
8 deletions
+230
-8
Address.js
src/solidity/types/Address.js
+2
-1
Bool.js
src/solidity/types/Bool.js
+3
-1
DynamicByteArray.js
src/solidity/types/DynamicByteArray.js
+23
-1
Enum.js
src/solidity/types/Enum.js
+4
-1
FixedByteArray.js
src/solidity/types/FixedByteArray.js
+4
-1
StringType.js
src/solidity/types/StringType.js
+11
-1
Uint.js
src/solidity/types/Uint.js
+0
-2
byteStorage.js
test/solidity/contracts/byteStorage.js
+135
-0
storageDecoder.js
test/solidity/storageDecoder.js
+48
-0
No files found.
src/solidity/types/Address.js
View file @
38786dbe
'use strict'
var
util
=
require
(
'./util'
)
function
Address
()
{
this
.
storageSlots
=
1
...
...
@@ -7,7 +8,7 @@ function Address () {
}
Address
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
return
'<not implemented yet>'
return
util
.
extractValue
(
location
,
storageContent
,
this
.
storageBytes
)
}
module
.
exports
=
Address
src/solidity/types/Bool.js
View file @
38786dbe
'use strict'
var
util
=
require
(
'./util'
)
function
Bool
()
{
this
.
storageSlots
=
1
...
...
@@ -7,7 +8,8 @@ function Bool () {
}
Bool
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
return
'<not implemented yet>'
var
value
=
util
.
extractValue
(
location
,
storageContent
,
this
.
storageBytes
)
return
value
!==
'0x00'
}
module
.
exports
=
Bool
src/solidity/types/DynamicByteArray.js
View file @
38786dbe
'use strict'
var
util
=
require
(
'./util'
)
var
BN
=
require
(
'ethereumjs-util'
).
BN
function
DynamicByteArray
()
{
this
.
storageSlots
=
1
...
...
@@ -7,7 +9,27 @@ function DynamicByteArray () {
}
DynamicByteArray
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
return
'<not implemented yet>'
var
value
=
util
.
extractValue
(
location
,
storageContent
,
this
.
storageBytes
)
var
key
=
util
.
dynamicTypePointer
(
location
)
if
(
storageContent
[
key
]
&&
storageContent
[
key
]
!==
'0x'
)
{
var
ret
=
''
var
length
=
parseInt
(
value
)
-
1
var
slots
=
Math
.
ceil
(
length
/
64
)
var
currentSlot
=
storageContent
[
key
]
key
=
new
BN
(
key
.
replace
(
'0x'
,
''
),
16
)
for
(
var
k
=
0
;
k
<
slots
;
k
++
)
{
if
(
!
currentSlot
)
{
break
}
ret
+=
currentSlot
.
replace
(
'0x'
,
''
)
key
=
key
.
add
(
new
BN
(
1
))
currentSlot
=
storageContent
[
'0x'
+
key
.
toString
(
16
)]
}
return
ret
.
substr
(
0
,
length
)
}
else
{
var
size
=
value
.
substr
(
value
.
length
-
2
,
2
)
return
value
.
substr
(
0
,
parseInt
(
size
,
16
)
+
2
)
}
}
module
.
exports
=
DynamicByteArray
src/solidity/types/Enum.js
View file @
38786dbe
'use strict'
var
util
=
require
(
'./util'
)
function
Enum
(
enumDef
)
{
this
.
enumDef
=
enumDef
...
...
@@ -13,7 +14,9 @@ function Enum (enumDef) {
}
Enum
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
return
'<not implemented yet>'
var
value
=
util
.
extractValue
(
location
,
storageContent
,
this
.
storageBytes
)
value
=
parseInt
(
value
)
return
this
.
enumDef
.
children
[
value
].
attributes
.
name
}
module
.
exports
=
Enum
src/solidity/types/FixedByteArray.js
View file @
38786dbe
'use strict'
var
util
=
require
(
'./util'
)
var
utileth
=
require
(
'ethereumjs-util'
)
function
FixedByteArray
(
storageBytes
)
{
this
.
storageSlots
=
1
...
...
@@ -7,7 +9,8 @@ function FixedByteArray (storageBytes) {
}
FixedByteArray
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
return
'<not implemented yet>'
var
value
=
util
.
extractValue
(
location
,
storageContent
,
this
.
storageBytes
)
return
'0x'
+
utileth
.
unpad
(
value
.
replace
(
'0x'
,
''
)).
toUpperCase
()
}
module
.
exports
=
FixedByteArray
src/solidity/types/StringType.js
View file @
38786dbe
'use strict'
var
DynamicBytes
=
require
(
'./DynamicByteArray'
)
function
StringType
()
{
this
.
storageSlots
=
1
this
.
storageBytes
=
32
this
.
typeName
=
'string'
this
.
dynamicBytes
=
new
DynamicBytes
()
}
StringType
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
return
'<not implemented yet>'
var
value
=
this
.
dynamicBytes
.
decodeFromStorage
(
location
,
storageContent
)
value
=
value
.
replace
(
'0x'
,
''
)
var
ret
=
''
for
(
var
k
=
0
;
k
<
value
.
length
;
k
+=
2
)
{
var
raw
=
value
.
substr
(
k
,
2
)
var
str
=
String
.
fromCharCode
(
parseInt
(
raw
,
16
))
ret
+=
str
}
return
ret
}
module
.
exports
=
StringType
src/solidity/types/Uint.js
View file @
38786dbe
'use strict'
var
IntType
=
require
(
'./Int'
)
var
util
=
require
(
'./util'
)
function
Uint
(
storageBytes
)
{
this
.
storageSlots
=
1
this
.
storageBytes
=
storageBytes
this
.
typeName
=
'uint'
this
.
decodeInt
=
new
IntType
(
storageBytes
)
}
Uint
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
test/solidity/contracts/byteStorage.js
0 → 100644
View file @
38786dbe
'use strict'
module
.
exports
=
{
contract
:
`
contract byteStorage {
enum enum1 {
a,
b,
c,
d
}
bool b1;
address a1;
bool b2;
bytes dynb1;
byte stab;
bytes1 stab1;
bytes2 stab2;
bytes3 stab3;
bytes4 stab4;
bytes5 stab5;
bytes6 stab6;
bytes7 stab7;
bytes8 stab8;
bytes9 stab9;
bytes10 stab10;
bytes11 stab11;
bytes12 stab12;
bytes13 stab13;
bytes14 stab14;
bytes15 stab15;
bytes16 stab16;
bytes17 stab17;
bytes18 stab18;
bytes19 stab19;
bytes20 stab20;
bytes21 stab21;
bytes22 stab22;
bytes23 stab23;
bytes24 stab24;
bytes25 stab25;
bytes26 stab26;
bytes27 stab27;
bytes28 stab28;
bytes29 stab29;
bytes30 stab30;
bytes31 stab31;
bytes32 stab32;
enum1 enumDec;
string str1;
string str2;
function byteStorage () {
b1 = false;
a1 = 0xfe350f199f244ac9a79038d254400b632a633225;
b2 = true;
dynb1 = 'dynamicbytes';
stab = 0x1;
stab1 = 0x12;
stab2 = 0x1579;
stab3 = 0x359356;
stab4 = 0x2375;
stab5 = 0x2357645;
stab6 = 0x324435;
stab7 = 0x324324;
stab8 = 0x324554645765;
stab9 = 0x3434543;
stab10 = 0x4543543654657;
stab11 = 0x54354654;
stab12 = 0x3;
stab13 = 0x3243242345435;
stab14 = 0x32454354354353;
stab15 = 0x32454434435;
stab16 = 0x3245435444;
stab17 = 0x32454343243243245;
stab18 = 0x324534325435435;
stab19 = 0x324543435435435;
stab20 = 0x32454543543AB35;
stab21 = 0x32454432423435;
stab22 = 0x324543AEF5;
stab23 = 0x3245435FFF;
stab24 = 0x3245435F;
stab25 = 0x3245435F;
stab26 = 0x3245435F;
stab27 = 0x3245FFFFFFF;
stab28 = 0x3241235;
stab29 = 0x325213213;
stab30 = 0x3245435232423;
stab31 = 0x3245435123;
stab32 = 0x324324423432543543AB;
enumDec = enum1.d;
str1 = 'short';
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';
}
}
`
,
storage
:
{
'0x0000000000000000000000000000000000000000000000000000000000000000'
:
'0x0000000000000000000001fe350f199f244ac9a79038d254400b632a63322500'
,
'0x0000000000000000000000000000000000000000000000000000000000000001'
:
'0x64796e616d696362797465730000000000000000000000000000000000000018'
,
'0x0000000000000000000000000000000000000000000000000000000000000002'
:
'0x0000000000000032432400000032443500023576450000237535935615791201'
,
'0x0000000000000000000000000000000000000000000000000000000000000003'
:
'0x0000000000000000045435436546570000000000034345430000324554645765'
,
'0x0000000000000000000000000000000000000000000000000000000000000004'
:
'0x0000000000000000000000000000000000000000030000000000000054354654'
,
'0x0000000000000000000000000000000000000000000000000000000000000005'
:
'0x0000000000000000000000003245435435435300000000000003243242345435'
,
'0x0000000000000000000000000000000000000000000000000000000000000006'
:
'0x0000000000000000000000003245435444000000000000000000032454434435'
,
'0x0000000000000000000000000000000000000000000000000000000000000007'
:
'0x0000000000000000000000000000000000000000000000032454343243243245'
,
'0x0000000000000000000000000000000000000000000000000000000000000008'
:
'0x0000000000000000000000000000000000000000000000000324534325435435'
,
'0x0000000000000000000000000000000000000000000000000000000000000009'
:
'0x0000000000000000000000000000000000000000000000000324543435435435'
,
'0x000000000000000000000000000000000000000000000000000000000000000a'
:
'0x000000000000000000000000000000000000000000000000032454543543ab35'
,
'0x000000000000000000000000000000000000000000000000000000000000000b'
:
'0x0000000000000000000000000000000000000000000000000032454432423435'
,
'0x000000000000000000000000000000000000000000000000000000000000000c'
:
'0x000000000000000000000000000000000000000000000000000000324543aef5'
,
'0x000000000000000000000000000000000000000000000000000000000000000d'
:
'0x0000000000000000000000000000000000000000000000000000003245435fff'
,
'0x000000000000000000000000000000000000000000000000000000000000000e'
:
'0x000000000000000000000000000000000000000000000000000000003245435f'
,
'0x000000000000000000000000000000000000000000000000000000000000000f'
:
'0x000000000000000000000000000000000000000000000000000000003245435f'
,
'0x0000000000000000000000000000000000000000000000000000000000000010'
:
'0x000000000000000000000000000000000000000000000000000000003245435f'
,
'0x0000000000000000000000000000000000000000000000000000000000000011'
:
'0x000000000000000000000000000000000000000000000000000003245fffffff'
,
'0x0000000000000000000000000000000000000000000000000000000000000012'
:
'0x0000000000000000000000000000000000000000000000000000000003241235'
,
'0x0000000000000000000000000000000000000000000000000000000000000013'
:
'0x0000000000000000000000000000000000000000000000000000000325213213'
,
'0x0000000000000000000000000000000000000000000000000000000000000014'
:
'0x0000000000000000000000000000000000000000000000000003245435232423'
,
'0x0000000000000000000000000000000000000000000000000000000000000015'
:
'0x0000000000000000000000000000000000000000000000000000003245435123'
,
'0x0000000000000000000000000000000000000000000000000000000000000016'
:
'0x00000000000000000000000000000000000000000000324324423432543543ab'
,
'0x0000000000000000000000000000000000000000000000000000000000000017'
:
'0x0000000000000000000000000000000000000000000000000000000000000003'
,
'0x0000000000000000000000000000000000000000000000000000000000000018'
:
'0x73686f727400000000000000000000000000000000000000000000000000000a'
,
'0x0000000000000000000000000000000000000000000000000000000000000019'
:
'0x000000000000000000000000000000000000000000000000000000000000023d'
,
'0x944998273e477b495144fb8794c914197f3ccb46be2900f4698fd0ef743c9695'
:
'0x6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f'
,
'0x944998273e477b495144fb8794c914197f3ccb46be2900f4698fd0ef743c9696'
:
'0x6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e67'
,
'0x944998273e477b495144fb8794c914197f3ccb46be2900f4698fd0ef743c9697'
:
'0x5f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f'
,
'0x944998273e477b495144fb8794c914197f3ccb46be2900f4698fd0ef743c9698'
:
'0x6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f'
,
'0x944998273e477b495144fb8794c914197f3ccb46be2900f4698fd0ef743c9699'
:
'0x6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e67'
,
'0x944998273e477b495144fb8794c914197f3ccb46be2900f4698fd0ef743c969a'
:
'0x5f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f'
,
'0x944998273e477b495144fb8794c914197f3ccb46be2900f4698fd0ef743c969b'
:
'0x6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f'
,
'0x944998273e477b495144fb8794c914197f3ccb46be2900f4698fd0ef743c969c'
:
'0x6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e67'
,
'0x944998273e477b495144fb8794c914197f3ccb46be2900f4698fd0ef743c969d'
:
'0x5f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e675f5f6c6f6e670000'
}
}
test/solidity/storageDecoder.js
View file @
38786dbe
...
...
@@ -6,6 +6,8 @@ var stateDecoder = require('../../src/index').solidity.stateDecoder
tape
(
'solidity'
,
function
(
t
)
{
t
.
test
(
'storage decoder'
,
function
(
st
)
{
testIntStorage
(
st
)
testByteStorage
(
st
)
st
.
end
()
})
})
...
...
@@ -50,6 +52,52 @@ function testIntStorage (st) {
st
.
end
()
}
function
testByteStorage
(
st
)
{
var
byteStorage
=
require
(
'./contracts/byteStorage'
)
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'
)
}
function
shrinkStorage
(
storage
)
{
var
shrinkedStorage
=
{}
var
regex
=
/0x
(
00
)
*
(
..
)
/
...
...
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