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
e7c45d29
Commit
e7c45d29
authored
Jan 09, 2017
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use es6 class for type
parent
d2da5fd6
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
104 additions
and
129 deletions
+104
-129
Address.js
src/solidity/types/Address.js
+11
-10
ArrayType.js
src/solidity/types/ArrayType.js
+11
-7
Bool.js
src/solidity/types/Bool.js
+5
-4
DynamicByteArray.js
src/solidity/types/DynamicByteArray.js
+10
-31
Enum.js
src/solidity/types/Enum.js
+8
-6
FixedByteArray.js
src/solidity/types/FixedByteArray.js
+11
-10
Int.js
src/solidity/types/Int.js
+5
-4
Mapping.js
src/solidity/types/Mapping.js
+5
-3
StringType.js
src/solidity/types/StringType.js
+13
-18
Struct.js
src/solidity/types/Struct.js
+8
-31
Uint.js
src/solidity/types/Uint.js
+5
-4
ValueType.js
src/solidity/types/ValueType.js
+11
-0
internalCallTree.js
src/util/internalCallTree.js
+1
-1
No files found.
src/solidity/types/Address.js
View file @
e7c45d29
'use strict'
var
util
=
require
(
'./util'
)
var
ValueType
=
require
(
'./ValueType'
)
function
Address
()
{
this
.
storageSlots
=
1
this
.
storageBytes
=
20
this
.
typeName
=
'address'
}
class
Address
extends
ValueType
{
constructor
()
{
super
(
1
,
20
,
'address'
)
}
Address
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
decodeFromStorage
(
location
,
storageContent
)
{
var
value
=
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
return
'0x'
+
value
.
toUpperCase
()
}
}
Address
.
prototype
.
decodeLocals
=
function
(
stackDepth
,
stack
,
memory
)
{
decodeLocals
(
stackDepth
,
stack
,
memory
)
{
if
(
stackDepth
>=
stack
.
length
)
{
return
'0x0000000000000000000000000000000000000000'
}
else
{
return
'0x'
+
util
.
extractHexByteSlice
(
stack
[
stack
.
length
-
1
-
stackDepth
],
this
.
storageBytes
,
0
)
}
}
}
Address
.
prototype
.
decodeFromMemory
=
function
(
offset
,
memory
)
{
decodeFromMemory
(
offset
,
memory
)
{
var
value
=
memory
.
substr
(
offset
,
64
)
value
=
util
.
extractHexByteSlice
(
value
,
this
.
storageBytes
,
0
)
return
value
}
}
module
.
exports
=
Address
src/solidity/types/ArrayType.js
View file @
e7c45d29
...
...
@@ -2,7 +2,9 @@
var
util
=
require
(
'./util'
)
var
BN
=
require
(
'ethereumjs-util'
).
BN
function
ArrayType
(
underlyingType
,
arraySize
)
{
class
ArrayType
{
constructor
(
underlyingType
,
arraySize
)
{
this
.
typeName
=
'array'
this
.
storageBytes
=
32
this
.
underlyingType
=
underlyingType
...
...
@@ -18,9 +20,9 @@ function ArrayType (underlyingType, arraySize) {
this
.
storageSlots
=
arraySize
*
underlyingType
.
storageSlots
}
}
}
}
ArrayType
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
decodeFromStorage
(
location
,
storageContent
)
{
var
ret
=
[]
var
size
=
null
var
slotValue
=
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
...
...
@@ -52,9 +54,9 @@ ArrayType.prototype.decodeFromStorage = function (location, storageContent) {
value
:
ret
,
length
:
'0x'
+
size
.
toString
(
16
)
}
}
}
ArrayType
.
prototype
.
decodeLocals
=
function
(
stackDepth
,
stack
,
memory
)
{
decodeLocals
(
stackDepth
,
stack
,
memory
)
{
if
(
stack
.
length
-
1
<
stackDepth
)
{
return
[]
}
else
{
// TODO manage decoding locals from storage
...
...
@@ -62,9 +64,9 @@ ArrayType.prototype.decodeLocals = function (stackDepth, stack, memory) {
offset
=
2
*
parseInt
(
offset
,
16
)
return
this
.
decodeFromMemory
(
offset
,
memory
)
}
}
}
ArrayType
.
prototype
.
decodeFromMemory
=
function
(
offset
,
memory
)
{
decodeFromMemory
(
offset
,
memory
)
{
var
ret
=
[]
var
length
=
extractLength
(
this
,
offset
,
memory
)
if
(
this
.
arraySize
===
'dynamic'
)
{
...
...
@@ -80,6 +82,8 @@ ArrayType.prototype.decodeFromMemory = function (offset, memory) {
offset
+=
64
}
return
ret
}
}
function
extractLength
(
type
,
offset
,
memory
)
{
...
...
src/solidity/types/Bool.js
View file @
e7c45d29
'use strict'
var
util
=
require
(
'./util'
)
var
ValueType
=
require
(
'./ValueType'
)
function
Bool
()
{
this
.
storageSlots
=
1
this
.
storageBytes
=
1
this
.
typeName
=
'bool'
class
Bool
extends
ValueType
{
constructor
()
{
super
(
1
,
1
,
'bool'
)
}
}
Bool
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/DynamicByteArray.js
View file @
e7c45d29
'use strict'
var
util
=
require
(
'./util'
)
var
BN
=
require
(
'ethereumjs-util'
).
BN
var
ValueType
=
require
(
'./ValueType'
)
function
DynamicByteArray
()
{
this
.
storageSlots
=
1
this
.
storageBytes
=
32
this
.
typeName
=
'bytes'
}
class
DynamicByteArray
extends
ValueType
{
constructor
()
{
super
(
1
,
32
,
'bytes'
)
}
DynamicByteArray
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
decodeFromStorage
(
location
,
storageContent
)
{
var
value
=
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
var
bn
=
new
BN
(
value
,
16
)
if
(
bn
.
testn
(
0
))
{
...
...
@@ -33,31 +33,9 @@ DynamicByteArray.prototype.decodeFromStorage = function (location, storageConten
length
:
'0x'
+
size
.
toString
(
16
)
}
}
}
DynamicByteArray
.
prototype
.
decodeLocals
=
function
(
stackDepth
,
stack
,
memory
)
{
if
(
stack
.
length
-
1
<
stackDepth
)
{
return
{
value
:
'0x'
,
length
:
'0x0'
}
}
else
{
var
offset
=
stack
[
stack
.
length
-
1
-
stackDepth
]
offset
=
2
*
parseInt
(
offset
,
16
)
return
this
.
decodeFromMemory
(
offset
,
memory
)
}
}
DynamicByteArray
.
prototype
.
decodeFromMemory
=
function
(
offset
,
memory
)
{
var
length
=
memory
.
substr
(
offset
,
64
)
length
=
2
*
parseInt
(
length
,
16
)
return
{
length
:
'0x'
+
length
.
toString
(
16
),
value
:
'0x'
+
memory
.
substr
(
offset
+
64
,
length
)
}
}
DynamicByteArray
.
prototype
.
decodeLocals
=
function
(
stackDepth
,
stack
,
memory
)
{
decodeLocals
(
stackDepth
,
stack
,
memory
)
{
if
(
stack
.
length
-
1
<
stackDepth
)
{
return
{
value
:
'0x'
,
...
...
@@ -68,15 +46,16 @@ DynamicByteArray.prototype.decodeLocals = function (stackDepth, stack, memory) {
offset
=
2
*
parseInt
(
offset
,
16
)
return
this
.
decodeFromMemory
(
offset
,
memory
)
}
}
}
DynamicByteArray
.
prototype
.
decodeFromMemory
=
function
(
offset
,
memory
)
{
decodeFromMemory
(
offset
,
memory
)
{
var
length
=
memory
.
substr
(
offset
,
64
)
length
=
2
*
parseInt
(
length
,
16
)
return
{
length
:
'0x'
+
length
.
toString
(
16
),
value
:
'0x'
+
memory
.
substr
(
offset
+
64
,
length
)
}
}
}
module
.
exports
=
DynamicByteArray
src/solidity/types/Enum.js
View file @
e7c45d29
'use strict'
var
util
=
require
(
'./util'
)
var
ValueType
=
require
(
'./ValueType'
)
function
Enum
(
enumDef
)
{
this
.
enumDef
=
enumDef
this
.
typeName
=
'enum'
this
.
storageSlots
=
1
class
Enum
extends
ValueType
{
constructor
(
enumDef
)
{
var
storageBytes
=
0
var
length
=
enumDef
.
children
.
length
this
.
storageBytes
=
0
while
(
length
>
1
)
{
length
=
length
/
256
this
.
storageBytes
++
storageBytes
++
}
super
(
1
,
storageBytes
,
'enum'
)
this
.
enumDef
=
enumDef
}
}
...
...
src/solidity/types/FixedByteArray.js
View file @
e7c45d29
'use strict'
var
util
=
require
(
'./util'
)
var
ValueType
=
require
(
'./ValueType'
)
function
FixedByteArray
(
storageBytes
)
{
this
.
storageSlots
=
1
this
.
storageBytes
=
storageBytes
this
.
typeName
=
'bytesX'
}
class
FixedByteArray
extends
ValueType
{
constructor
(
storageBytes
)
{
super
(
1
,
storageBytes
,
'bytesX'
)
}
FixedByteArray
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
decodeFromStorage
(
location
,
storageContent
)
{
var
value
=
util
.
extractHexValue
(
location
,
storageContent
,
this
.
storageBytes
)
return
'0x'
+
value
.
toUpperCase
()
}
}
FixedByteArray
.
prototype
.
decodeLocals
=
function
(
stackDepth
,
stack
,
memory
)
{
decodeLocals
(
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
()
}
}
}
FixedByteArray
.
prototype
.
decodeFromMemory
=
function
(
offset
,
memory
)
{
decodeFromMemory
(
offset
,
memory
)
{
var
value
=
memory
.
substr
(
offset
,
64
)
return
util
.
extractHexByteSlice
(
value
,
this
.
storageBytes
,
0
).
toUpperCase
()
}
}
module
.
exports
=
FixedByteArray
src/solidity/types/Int.js
View file @
e7c45d29
'use strict'
var
util
=
require
(
'./util'
)
var
ValueType
=
require
(
'./ValueType'
)
function
Int
(
storageBytes
)
{
this
.
storageSlots
=
1
this
.
storageBytes
=
storageBytes
this
.
typeName
=
'int'
class
Int
extends
ValueType
{
constructor
(
storageBytes
)
{
super
(
1
,
storageBytes
,
'int'
)
}
}
Int
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/Mapping.js
View file @
e7c45d29
'use strict'
function
Mapping
()
{
class
Mapping
{
constructor
()
{
this
.
storageSlots
=
1
this
.
storageBytes
=
32
this
.
typeName
=
'mapping'
}
}
Mapping
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
decodeFromStorage
(
location
,
storageContent
)
{
return
'<not implemented>'
}
}
module
.
exports
=
Mapping
src/solidity/types/StringType.js
View file @
e7c45d29
'use strict'
var
DynamicBytes
=
require
(
'./DynamicByteArray'
)
function
StringType
()
{
this
.
storageSlots
=
1
this
.
storageBytes
=
32
class
StringType
extends
DynamicBytes
{
constructor
()
{
super
()
this
.
typeName
=
'string'
this
.
dynamicBytes
=
new
DynamicBytes
()
}
StringType
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
var
decoded
=
this
.
dynamicBytes
.
decodeFromStorage
(
location
,
storageContent
)
return
format
(
decoded
)
}
}
StringType
.
prototype
.
decodeLocals
=
function
(
stackDepth
,
stack
,
memory
)
{
var
decoded
=
this
.
dynamicBytes
.
decodeLocals
(
stackDepth
,
stack
,
memory
)
decodeFromStorage
(
location
,
storageContent
)
{
var
decoded
=
super
.
decodeFromStorage
(
location
,
storageContent
)
return
format
(
decoded
)
}
}
StringType
.
prototype
.
decodeFromMemory
=
function
(
offset
,
memory
)
{
var
decoded
=
this
.
dynamicBytes
.
decodeFromMemory
(
offset
,
memory
)
decodeLocals
(
stackDepth
,
stack
,
memory
)
{
var
decoded
=
super
.
decodeLocals
(
stackDepth
,
stack
,
memory
)
return
format
(
decoded
)
}
}
StringType
.
prototype
.
decodeFromMemory
=
function
(
offset
,
memory
)
{
var
decoded
=
this
.
dynamicBytes
.
decodeFromMemory
(
offset
,
memory
)
decodeFromMemory
(
offset
,
memory
)
{
var
decoded
=
super
.
decodeFromMemory
(
offset
,
memory
)
return
format
(
decoded
)
}
}
function
format
(
decoded
)
{
...
...
src/solidity/types/Struct.js
View file @
e7c45d29
'use strict'
var
util
=
require
(
'./util'
)
function
Struct
(
memberDetails
)
{
class
Struct
{
constructor
(
memberDetails
)
{
this
.
storageSlots
=
memberDetails
.
storageSlots
this
.
storageBytes
=
32
this
.
members
=
memberDetails
.
members
this
.
typeName
=
'struct'
}
}
Struct
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
decodeFromStorage
(
location
,
storageContent
)
{
var
ret
=
{}
this
.
members
.
map
(
function
(
item
,
i
)
{
var
globalLocation
=
{
...
...
@@ -18,34 +19,9 @@ Struct.prototype.decodeFromStorage = function (location, storageContent) {
ret
[
item
.
name
]
=
item
.
type
.
decodeFromStorage
(
globalLocation
,
storageContent
)
})
return
ret
}
Struct
.
prototype
.
decodeLocals
=
function
(
stackDepth
,
stack
,
memory
)
{
if
(
stack
.
length
-
1
<
stackDepth
)
{
return
{}
}
else
{
// TODO manage decoding locals from storage
var
offset
=
stack
[
stack
.
length
-
1
-
stackDepth
]
offset
=
2
*
parseInt
(
offset
,
16
)
return
this
.
decodeFromMemory
(
offset
,
memory
)
}
}
Struct
.
prototype
.
decodeFromMemory
=
function
(
offset
,
memory
)
{
var
ret
=
{}
this
.
members
.
map
(
function
(
item
,
i
)
{
var
contentOffset
=
offset
if
(
item
.
type
.
typeName
===
'bytes'
||
item
.
type
.
typeName
===
'string'
||
item
.
type
.
typeName
===
'array'
||
item
.
type
.
typeName
===
'struct'
)
{
contentOffset
=
memory
.
substr
(
offset
,
64
)
contentOffset
=
2
*
parseInt
(
contentOffset
,
16
)
}
var
member
=
item
.
type
.
decodeFromMemory
(
contentOffset
,
memory
)
ret
[
item
.
name
]
=
member
offset
+=
64
})
return
ret
}
Struct
.
prototype
.
decodeLocals
=
function
(
stackDepth
,
stack
,
memory
)
{
decodeLocals
(
stackDepth
,
stack
,
memory
)
{
if
(
stack
.
length
-
1
<
stackDepth
)
{
return
{}
}
else
{
// TODO manage decoding locals from storage
...
...
@@ -53,9 +29,9 @@ Struct.prototype.decodeLocals = function (stackDepth, stack, memory) {
offset
=
2
*
parseInt
(
offset
,
16
)
return
this
.
decodeFromMemory
(
offset
,
memory
)
}
}
}
Struct
.
prototype
.
decodeFromMemory
=
function
(
offset
,
memory
)
{
decodeFromMemory
(
offset
,
memory
)
{
var
ret
=
{}
this
.
members
.
map
(
function
(
item
,
i
)
{
var
contentOffset
=
offset
...
...
@@ -68,6 +44,7 @@ Struct.prototype.decodeFromMemory = function (offset, memory) {
offset
+=
64
})
return
ret
}
}
module
.
exports
=
Struct
src/solidity/types/Uint.js
View file @
e7c45d29
'use strict'
var
util
=
require
(
'./util'
)
var
ValueType
=
require
(
'./ValueType'
)
function
Uint
(
storageBytes
)
{
this
.
storageSlots
=
1
this
.
storageBytes
=
storageBytes
this
.
typeName
=
'uint'
class
Uint
extends
ValueType
{
constructor
(
storageBytes
)
{
super
(
1
,
storageBytes
,
'uint'
)
}
}
Uint
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/ValueType.js
0 → 100644
View file @
e7c45d29
'use strict'
class
ValueType
{
constructor
(
storageSlots
,
storageBytes
,
typeName
)
{
this
.
storageSlots
=
storageSlots
this
.
storageBytes
=
storageBytes
this
.
typeName
=
typeName
}
}
module
.
exports
=
ValueType
src/util/internalCallTree.js
View file @
e7c45d29
...
...
@@ -132,7 +132,7 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId) {
tree
.
scopes
[
scopeId
].
locals
[
variableDeclaration
.
attributes
.
name
]
=
{
name
:
variableDeclaration
.
attributes
.
name
,
type
:
decodeInfo
.
parseType
(
variableDeclaration
.
attributes
.
type
,
states
,
contractName
),
stackDepth
:
stack
.
stackDep
th
stackDepth
:
stack
.
leng
th
}
}
})
...
...
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