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
1a109717
Commit
1a109717
authored
Jan 10, 2017
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move decodeFromStorage, decodeFromStack, decodeFromMemory to ValueType
parent
20c32ddf
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
57 additions
and
110 deletions
+57
-110
Address.js
src/solidity/types/Address.js
+3
-14
Bool.js
src/solidity/types/Bool.js
+5
-14
DynamicByteArray.js
src/solidity/types/DynamicByteArray.js
+4
-0
Enum.js
src/solidity/types/Enum.js
+9
-29
FixedByteArray.js
src/solidity/types/FixedByteArray.js
+2
-18
Int.js
src/solidity/types/Int.js
+3
-15
Mapping.js
src/solidity/types/Mapping.js
+4
-5
StringType.js
src/solidity/types/StringType.js
+5
-0
Uint.js
src/solidity/types/Uint.js
+2
-14
ValueType.js
src/solidity/types/ValueType.js
+19
-0
misc.js
test/solidity/localsTests/misc.js
+1
-1
No files found.
src/solidity/types/Address.js
View file @
1a109717
...
@@ -7,24 +7,13 @@ class Address extends ValueType {
...
@@ -7,24 +7,13 @@ class Address extends ValueType {
super
(
1
,
20
,
'address'
)
super
(
1
,
20
,
'address'
)
}
}
decodeFromStorage
(
location
,
storageContent
)
{
decodeValue
(
value
)
{
var
value
=
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
if
(
!
value
)
{
return
'0x'
+
value
.
toUpperCase
()
}
decodeFromStack
(
stackDepth
,
stack
,
memory
)
{
if
(
stackDepth
>=
stack
.
length
)
{
return
'0x0000000000000000000000000000000000000000'
return
'0x0000000000000000000000000000000000000000'
}
else
{
}
else
{
return
'0x'
+
util
.
extractHexByteSlice
(
stack
[
stack
.
length
-
1
-
stackDepth
],
this
.
storageBytes
,
0
)
return
'0x'
+
util
.
extractHexByteSlice
(
value
,
this
.
storageBytes
,
0
).
toUpperCase
(
)
}
}
}
}
decodeFromMemory
(
offset
,
memory
)
{
var
value
=
memory
.
substr
(
offset
,
64
)
value
=
util
.
extractHexByteSlice
(
value
,
this
.
storageBytes
,
0
)
return
value
}
}
}
module
.
exports
=
Address
module
.
exports
=
Address
src/solidity/types/Bool.js
View file @
1a109717
'use strict'
'use strict'
var
util
=
require
(
'./util'
)
var
ValueType
=
require
(
'./ValueType'
)
var
ValueType
=
require
(
'./ValueType'
)
var
util
=
require
(
'./util'
)
class
Bool
extends
ValueType
{
class
Bool
extends
ValueType
{
constructor
()
{
constructor
()
{
super
(
1
,
1
,
'bool'
)
super
(
1
,
1
,
'bool'
)
}
}
decodeFromStorage
(
location
,
storageContent
)
{
decodeValue
(
value
)
{
var
value
=
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
if
(
!
value
)
{
return
value
!==
'00'
}
decodeFromStack
(
stackDepth
,
stack
,
memory
)
{
if
(
stack
.
length
-
1
<
stackDepth
)
{
return
false
return
false
}
else
{
}
else
{
return
util
.
extractHexByteSlice
(
stack
[
stack
.
length
-
1
-
stackDepth
],
this
.
storageBytes
,
0
)
!==
'00'
value
=
util
.
extractHexByteSlice
(
value
,
this
.
storageBytes
,
0
)
return
value
!==
'00'
}
}
}
}
decodeFromMemory
(
offset
,
memory
)
{
var
value
=
memory
.
substr
(
offset
,
64
)
return
util
.
extractHexByteSlice
(
value
,
this
.
storageBytes
,
0
)
!==
'00'
}
}
}
module
.
exports
=
Bool
module
.
exports
=
Bool
src/solidity/types/DynamicByteArray.js
View file @
1a109717
...
@@ -8,6 +8,10 @@ class DynamicByteArray extends ValueType {
...
@@ -8,6 +8,10 @@ class DynamicByteArray extends ValueType {
super
(
1
,
32
,
'bytes'
)
super
(
1
,
32
,
'bytes'
)
}
}
decodeValue
(
value
)
{
return
'0x'
+
value
.
toUpperCase
()
}
decodeFromStorage
(
location
,
storageContent
)
{
decodeFromStorage
(
location
,
storageContent
)
{
var
value
=
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
var
value
=
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
var
bn
=
new
BN
(
value
,
16
)
var
bn
=
new
BN
(
value
,
16
)
...
...
src/solidity/types/Enum.js
View file @
1a109717
'use strict'
'use strict'
var
util
=
require
(
'./util'
)
var
ValueType
=
require
(
'./ValueType'
)
var
ValueType
=
require
(
'./ValueType'
)
class
Enum
extends
ValueType
{
class
Enum
extends
ValueType
{
...
@@ -14,36 +13,17 @@ class Enum extends ValueType {
...
@@ -14,36 +13,17 @@ class Enum extends ValueType {
this
.
enumDef
=
enumDef
this
.
enumDef
=
enumDef
}
}
decodeFromStorage
(
location
,
storageContent
)
{
decodeValue
(
value
)
{
var
value
=
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
if
(
!
value
)
{
value
=
parseInt
(
value
,
16
)
return
this
.
enumDef
.
children
[
0
].
attributes
.
name
return
output
(
value
,
this
.
enumDef
)
}
decodeFromStack
(
stackDepth
,
stack
,
memory
)
{
var
defaultValue
=
0
if
(
stack
.
length
-
1
<
stackDepth
)
{
defaultValue
=
0
}
else
{
}
else
{
defaultValue
=
util
.
extractHexByteSlice
(
stack
[
stack
.
length
-
1
-
stackDepth
],
this
.
storageBytes
,
0
)
value
=
parseInt
(
value
,
16
)
defaultValue
=
parseInt
(
defaultValue
,
16
)
if
(
this
.
enumDef
.
children
.
length
>
value
)
{
return
this
.
enumDef
.
children
[
value
].
attributes
.
name
}
else
{
return
'INVALID_ENUM<'
+
value
+
'>'
}
}
}
return
output
(
defaultValue
,
this
.
enumDef
)
}
decodeFromMemory
(
offset
,
memory
)
{
var
value
=
memory
.
substr
(
offset
,
64
)
value
=
util
.
extractHexByteSlice
(
value
,
this
.
storageBytes
,
0
)
value
=
parseInt
(
value
,
16
)
return
output
(
value
,
this
.
enumDef
)
}
}
function
output
(
value
,
enumDef
)
{
if
(
enumDef
.
children
.
length
>
value
)
{
return
enumDef
.
children
[
value
].
attributes
.
name
}
else
{
return
'INVALID_ENUM<'
+
value
+
'>'
}
}
}
}
...
...
src/solidity/types/FixedByteArray.js
View file @
1a109717
'use strict'
'use strict'
var
util
=
require
(
'./util'
)
var
ValueType
=
require
(
'./ValueType'
)
var
ValueType
=
require
(
'./ValueType'
)
class
FixedByteArray
extends
ValueType
{
class
FixedByteArray
extends
ValueType
{
...
@@ -7,23 +6,8 @@ class FixedByteArray extends ValueType {
...
@@ -7,23 +6,8 @@ class FixedByteArray extends ValueType {
super
(
1
,
storageBytes
,
'bytesX'
)
super
(
1
,
storageBytes
,
'bytesX'
)
}
}
decodeFromStorage
(
location
,
storageContent
)
{
decodeValue
(
value
)
{
var
value
=
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
return
'0x'
+
value
.
substr
(
0
,
2
*
this
.
storageBytes
).
toUpperCase
()
return
'0x'
+
value
.
toUpperCase
()
}
decodeFromStack
(
stackDepth
,
stack
,
memory
)
{
if
(
stack
.
length
-
1
<
stackDepth
)
{
return
'0x'
}
else
{
var
value
=
stack
[
stack
.
length
-
1
-
stackDepth
]
return
'0x'
+
value
.
substr
(
2
,
2
*
this
.
storageBytes
).
toUpperCase
()
}
}
decodeFromMemory
(
offset
,
memory
)
{
var
value
=
memory
.
substr
(
offset
,
64
)
return
util
.
extractHexByteSlice
(
value
,
this
.
storageBytes
,
0
).
toUpperCase
()
}
}
}
}
...
...
src/solidity/types/Int.js
View file @
1a109717
...
@@ -7,21 +7,9 @@ class Int extends ValueType {
...
@@ -7,21 +7,9 @@ class Int extends ValueType {
super
(
1
,
storageBytes
,
'int'
)
super
(
1
,
storageBytes
,
'int'
)
}
}
decodeFromStorage
(
location
,
storageContent
)
{
decodeValue
(
value
)
{
return
util
.
decodeInt
(
location
,
storageContent
,
this
.
storageBytes
,
true
)
value
=
util
.
extractHexByteSlice
(
value
,
this
.
storageBytes
,
0
)
}
return
util
.
decodeIntFromHex
(
value
,
this
.
storageBytes
,
true
)
decodeFromStack
(
stackDepth
,
stack
,
memory
)
{
if
(
stackDepth
>=
stack
.
length
)
{
return
'0'
}
else
{
return
util
.
decodeIntFromHex
(
stack
[
stack
.
length
-
1
-
stackDepth
].
replace
(
'0x'
,
''
),
32
,
true
)
}
}
decodeFromMemory
(
offset
,
memory
)
{
var
value
=
memory
.
substr
(
offset
,
64
)
return
util
.
decodeIntFromHex
(
value
,
32
,
true
)
}
}
}
}
...
...
src/solidity/types/Mapping.js
View file @
1a109717
'use strict'
'use strict'
var
RefType
=
require
(
'./RefType'
)
class
Mapping
{
class
Mapping
extends
RefType
{
constructor
()
{
constructor
()
{
this
.
storageSlots
=
1
super
(
1
,
32
,
'mapping'
)
this
.
storageBytes
=
32
this
.
typeName
=
'mapping'
}
}
decode
FromStorage
(
location
,
storageContent
)
{
decode
Value
(
value
)
{
return
'<not implemented>'
return
'<not implemented>'
}
}
}
}
...
...
src/solidity/types/StringType.js
View file @
1a109717
...
@@ -7,6 +7,11 @@ class StringType extends DynamicBytes {
...
@@ -7,6 +7,11 @@ class StringType extends DynamicBytes {
this
.
typeName
=
'string'
this
.
typeName
=
'string'
}
}
decodeValue
(
value
)
{
var
decoded
=
super
.
decodeValue
(
value
)
return
format
(
decoded
)
}
decodeFromStorage
(
location
,
storageContent
)
{
decodeFromStorage
(
location
,
storageContent
)
{
var
decoded
=
super
.
decodeFromStorage
(
location
,
storageContent
)
var
decoded
=
super
.
decodeFromStorage
(
location
,
storageContent
)
return
format
(
decoded
)
return
format
(
decoded
)
...
...
src/solidity/types/Uint.js
View file @
1a109717
...
@@ -7,20 +7,8 @@ class Uint extends ValueType {
...
@@ -7,20 +7,8 @@ class Uint extends ValueType {
super
(
1
,
storageBytes
,
'uint'
)
super
(
1
,
storageBytes
,
'uint'
)
}
}
decodeFromStorage
(
location
,
storageContent
)
{
decodeValue
(
value
)
{
return
util
.
decodeInt
(
location
,
storageContent
,
this
.
storageBytes
,
false
)
value
=
util
.
extractHexByteSlice
(
value
,
this
.
storageBytes
,
0
)
}
decodeFromStack
(
stackDepth
,
stack
,
memory
)
{
if
(
stackDepth
>=
stack
.
length
)
{
return
'0'
}
else
{
return
util
.
decodeIntFromHex
(
stack
[
stack
.
length
-
1
-
stackDepth
].
replace
(
'0x'
,
''
),
this
.
storageBytes
,
false
)
}
}
decodeFromMemory
(
offset
,
memory
)
{
var
value
=
memory
.
substr
(
offset
,
64
)
return
util
.
decodeIntFromHex
(
value
,
this
.
storageBytes
,
false
)
return
util
.
decodeIntFromHex
(
value
,
this
.
storageBytes
,
false
)
}
}
}
}
...
...
src/solidity/types/ValueType.js
View file @
1a109717
'use strict'
'use strict'
var
util
=
require
(
'./util'
)
class
ValueType
{
class
ValueType
{
constructor
(
storageSlots
,
storageBytes
,
typeName
)
{
constructor
(
storageSlots
,
storageBytes
,
typeName
)
{
...
@@ -6,6 +7,24 @@ class ValueType {
...
@@ -6,6 +7,24 @@ class ValueType {
this
.
storageBytes
=
storageBytes
this
.
storageBytes
=
storageBytes
this
.
typeName
=
typeName
this
.
typeName
=
typeName
}
}
decodeFromStorage
(
location
,
storageContent
)
{
var
value
=
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
return
this
.
decodeValue
(
value
)
}
decodeFromStack
(
stackDepth
,
stack
,
memory
)
{
if
(
stackDepth
>=
stack
.
length
)
{
return
this
.
decodeValue
(
''
)
}
else
{
return
this
.
decodeValue
(
stack
[
stack
.
length
-
1
-
stackDepth
].
replace
(
'0x'
,
''
))
}
}
decodeFromMemory
(
offset
,
memory
)
{
var
value
=
memory
.
substr
(
offset
,
64
)
return
this
.
decodeValue
(
util
.
extractHexByteSlice
(
value
,
this
.
storageBytes
,
0
))
}
}
}
module
.
exports
=
ValueType
module
.
exports
=
ValueType
test/solidity/localsTests/misc.js
View file @
1a109717
...
@@ -32,7 +32,7 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
...
@@ -32,7 +32,7 @@ module.exports = function (st, vm, privateKey, contractBytecode, compilationResu
st
.
equals
(
locals
[
'boolFalse'
],
false
)
st
.
equals
(
locals
[
'boolFalse'
],
false
)
st
.
equals
(
locals
[
'boolTrue'
],
true
)
st
.
equals
(
locals
[
'boolTrue'
],
true
)
st
.
equals
(
locals
[
'testEnum'
],
'three'
)
st
.
equals
(
locals
[
'testEnum'
],
'three'
)
st
.
equals
(
locals
[
'sender'
],
'0x4
b0897b0513fdc7c541b6d9d7e929c4e5364d2db
'
)
st
.
equals
(
locals
[
'sender'
],
'0x4
B0897B0513FDC7C541B6D9D7E929C4E5364D2DB
'
)
st
.
equals
(
locals
[
'_bytes1'
],
'0x99'
)
st
.
equals
(
locals
[
'_bytes1'
],
'0x99'
)
st
.
equals
(
locals
[
'__bytes1'
],
'0x99'
)
st
.
equals
(
locals
[
'__bytes1'
],
'0x99'
)
st
.
equals
(
locals
[
'__bytes2'
],
'0x99AB'
)
st
.
equals
(
locals
[
'__bytes2'
],
'0x99AB'
)
...
...
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