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
e7d48971
Commit
e7d48971
authored
Nov 24, 2016
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix dynamic bytes
parent
38786dbe
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
29 additions
and
21 deletions
+29
-21
Address.js
src/solidity/types/Address.js
+1
-1
Bool.js
src/solidity/types/Bool.js
+2
-2
DynamicByteArray.js
src/solidity/types/DynamicByteArray.js
+8
-11
Enum.js
src/solidity/types/Enum.js
+1
-1
FixedByteArray.js
src/solidity/types/FixedByteArray.js
+2
-2
StringType.js
src/solidity/types/StringType.js
+1
-1
util.js
src/solidity/types/util.js
+14
-2
storageDecoder.js
test/solidity/storageDecoder.js
+0
-1
No files found.
src/solidity/types/Address.js
View file @
e7d48971
...
...
@@ -8,7 +8,7 @@ function Address () {
}
Address
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
return
util
.
extractValu
e
(
location
,
storageContent
,
this
.
storageBytes
)
return
'0x'
+
util
.
extractHexByt
e
(
location
,
storageContent
,
this
.
storageBytes
)
}
module
.
exports
=
Address
src/solidity/types/Bool.js
View file @
e7d48971
...
...
@@ -8,8 +8,8 @@ function Bool () {
}
Bool
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
var
value
=
util
.
extract
Valu
e
(
location
,
storageContent
,
this
.
storageBytes
)
return
value
!==
'0
x0
0'
var
value
=
util
.
extract
HexByt
e
(
location
,
storageContent
,
this
.
storageBytes
)
return
value
!==
'00'
}
module
.
exports
=
Bool
src/solidity/types/DynamicByteArray.js
View file @
e7d48971
...
...
@@ -9,26 +9,23 @@ function DynamicByteArray () {
}
DynamicByteArray
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
var
value
=
util
.
extract
Valu
e
(
location
,
storageContent
,
this
.
storageBytes
)
var
key
=
util
.
dynamicTypePointer
(
location
)
var
value
=
util
.
extract
HexByt
e
(
location
,
storageContent
,
this
.
storageBytes
)
var
key
=
util
.
sha3
(
location
.
slot
)
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'
,
''
)
var
regex
=
/
(
00
)
+$/
while
(
currentSlot
)
{
currentSlot
=
currentSlot
.
replace
(
'0x'
,
''
).
replace
(
regex
,
''
)
ret
+=
currentSlot
key
=
key
.
add
(
new
BN
(
1
))
currentSlot
=
storageContent
[
'0x'
+
key
.
toString
(
16
)]
}
return
ret
.
substr
(
0
,
length
)
return
'0x'
+
ret
}
else
{
var
size
=
value
.
substr
(
value
.
length
-
2
,
2
)
return
value
.
substr
(
0
,
parseInt
(
size
,
16
)
+
2
)
return
'0x'
+
value
.
substr
(
0
,
parseInt
(
size
,
16
)
)
}
}
...
...
src/solidity/types/Enum.js
View file @
e7d48971
...
...
@@ -14,7 +14,7 @@ function Enum (enumDef) {
}
Enum
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
var
value
=
util
.
extract
Valu
e
(
location
,
storageContent
,
this
.
storageBytes
)
var
value
=
util
.
extract
HexByt
e
(
location
,
storageContent
,
this
.
storageBytes
)
value
=
parseInt
(
value
)
return
this
.
enumDef
.
children
[
value
].
attributes
.
name
}
...
...
src/solidity/types/FixedByteArray.js
View file @
e7d48971
...
...
@@ -9,8 +9,8 @@ function FixedByteArray (storageBytes) {
}
FixedByteArray
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
var
value
=
util
.
extract
Valu
e
(
location
,
storageContent
,
this
.
storageBytes
)
return
'0x'
+
utileth
.
unpad
(
value
.
replace
(
'0x'
,
''
)
).
toUpperCase
()
var
value
=
util
.
extract
HexByt
e
(
location
,
storageContent
,
this
.
storageBytes
)
return
'0x'
+
utileth
.
unpad
(
value
).
toUpperCase
()
}
module
.
exports
=
FixedByteArray
src/solidity/types/StringType.js
View file @
e7d48971
...
...
@@ -10,8 +10,8 @@ function StringType () {
StringType
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
var
value
=
this
.
dynamicBytes
.
decodeFromStorage
(
location
,
storageContent
)
value
=
value
.
replace
(
'0x'
,
''
)
var
ret
=
''
value
=
value
.
replace
(
'0x'
,
''
)
for
(
var
k
=
0
;
k
<
value
.
length
;
k
+=
2
)
{
var
raw
=
value
.
substr
(
k
,
2
)
var
str
=
String
.
fromCharCode
(
parseInt
(
raw
,
16
))
...
...
src/solidity/types/util.js
View file @
e7d48971
...
...
@@ -3,9 +3,10 @@ var ethutil = require('ethereumjs-util')
var
BN
=
require
(
'ethereumjs-util'
).
BN
module
.
exports
=
{
extractHexByteSlice
:
extractHexByteSlice
,
readFromStorage
:
readFromStorage
,
decodeInt
:
decodeInt
decodeInt
:
decodeInt
,
extractHexByte
:
extractHexByte
,
sha3
:
sha3
}
function
decodeInt
(
location
,
storageContent
,
byteLength
,
signed
)
{
...
...
@@ -40,3 +41,14 @@ function extractHexByteSlice (slotValue, byteLength, offsetFromLSB) {
var
offset
=
slotValue
.
length
-
2
*
offsetFromLSB
-
2
*
byteLength
return
slotValue
.
substr
(
offset
,
2
*
byteLength
)
}
function
extractHexByte
(
location
,
storageContent
,
byteLength
)
{
var
slotvalue
=
readFromStorage
(
location
.
slot
,
storageContent
)
return
extractHexByteSlice
(
slotvalue
,
byteLength
,
location
.
offset
)
}
function
sha3
(
slot
)
{
var
remoteSlot
=
ethutil
.
bufferToHex
(
ethutil
.
setLengthLeft
(
slot
,
32
))
var
key
=
ethutil
.
sha3
(
remoteSlot
)
return
ethutil
.
bufferToHex
(
key
)
}
test/solidity/storageDecoder.js
View file @
e7d48971
...
...
@@ -49,7 +49,6 @@ function testIntStorage (st) {
st
.
equal
(
decoded
[
'i256'
],
'0'
)
st
.
equal
(
decoded
[
'i'
],
'0'
)
st
.
equal
(
decoded
[
'ishrink'
],
'0'
)
st
.
end
()
}
function
testByteStorage
(
st
)
{
...
...
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