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
a8d89aa4
Commit
a8d89aa4
authored
Jan 10, 2017
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add RefType + provide location
parent
60ce2bbb
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
60 additions
and
41 deletions
+60
-41
decodeInfo.js
src/solidity/decodeInfo.js
+7
-5
ArrayType.js
src/solidity/types/ArrayType.js
+10
-20
RefType.js
src/solidity/types/RefType.js
+28
-0
Struct.js
src/solidity/types/Struct.js
+4
-15
util.js
src/solidity/types/util.js
+11
-1
No files found.
src/solidity/decodeInfo.js
View file @
a8d89aa4
...
@@ -118,7 +118,8 @@ function Array (type, stateDefinitions, contractName) {
...
@@ -118,7 +118,8 @@ function Array (type, stateDefinitions, contractName) {
console
.
log
(
'unable to parse type '
+
type
)
console
.
log
(
'unable to parse type '
+
type
)
return
null
return
null
}
}
return
new
ArrayType
(
underlyingType
,
arraySize
)
var
location
=
match
[
3
].
trim
()
return
new
ArrayType
(
underlyingType
,
arraySize
,
location
)
}
}
/**
/**
...
@@ -149,12 +150,13 @@ function Enum (type, stateDefinitions, contractName) {
...
@@ -149,12 +150,13 @@ function Enum (type, stateDefinitions, contractName) {
*/
*/
function
Struct
(
type
,
stateDefinitions
,
contractName
)
{
function
Struct
(
type
,
stateDefinitions
,
contractName
)
{
var
match
=
type
.
match
(
/struct
(
.*
?)(
storage ref| storage pointer| memory| calldata
)?
$/
)
var
match
=
type
.
match
(
/struct
(
.*
?)(
storage ref| storage pointer| memory| calldata
)?
$/
)
if
(
!
match
)
{
if
(
match
&&
match
.
length
>
2
)
{
var
memberDetails
=
getStructMembers
(
match
[
1
],
stateDefinitions
,
contractName
)
// type is used to extract the ast struct definition
if
(
!
memberDetails
)
return
null
return
new
StructType
(
memberDetails
,
match
[
2
].
trim
())
}
else
{
return
null
return
null
}
}
var
memberDetails
=
getStructMembers
(
match
[
1
],
stateDefinitions
,
contractName
)
// type is used to extract the ast struct definition
if
(
!
memberDetails
)
return
null
return
new
StructType
(
memberDetails
)
}
}
/**
/**
...
...
src/solidity/types/ArrayType.js
View file @
a8d89aa4
'use strict'
'use strict'
var
util
=
require
(
'./util'
)
var
util
=
require
(
'./util'
)
var
BN
=
require
(
'ethereumjs-util'
).
BN
var
BN
=
require
(
'ethereumjs-util'
).
BN
var
RefType
=
require
(
'./RefType'
)
class
ArrayType
{
class
ArrayType
extends
RefType
{
constructor
(
underlyingType
,
arraySize
)
{
constructor
(
underlyingType
,
arraySize
,
location
)
{
this
.
typeName
=
'array'
var
storageSlots
=
null
this
.
storageBytes
=
32
this
.
underlyingType
=
underlyingType
this
.
arraySize
=
arraySize
this
.
storageSlots
=
null
if
(
arraySize
===
'dynamic'
)
{
if
(
arraySize
===
'dynamic'
)
{
this
.
storageSlots
=
1
storageSlots
=
1
}
else
{
}
else
{
if
(
underlyingType
.
storageBytes
<
32
)
{
if
(
underlyingType
.
storageBytes
<
32
)
{
var
itemPerSlot
=
Math
.
floor
(
32
/
underlyingType
.
storageBytes
)
var
itemPerSlot
=
Math
.
floor
(
32
/
underlyingType
.
storageBytes
)
this
.
storageSlots
=
Math
.
ceil
(
arraySize
/
itemPerSlot
)
storageSlots
=
Math
.
ceil
(
arraySize
/
itemPerSlot
)
}
else
{
}
else
{
this
.
storageSlots
=
arraySize
*
underlyingType
.
storageSlots
storageSlots
=
arraySize
*
underlyingType
.
storageSlots
}
}
}
}
super
(
storageSlots
,
32
,
'array'
,
location
)
this
.
underlyingType
=
underlyingType
this
.
arraySize
=
arraySize
}
}
decodeFromStorage
(
location
,
storageContent
)
{
decodeFromStorage
(
location
,
storageContent
)
{
...
@@ -56,16 +56,6 @@ class ArrayType {
...
@@ -56,16 +56,6 @@ class ArrayType {
}
}
}
}
decodeFromStack
(
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
)
}
}
decodeFromMemory
(
offset
,
memory
)
{
decodeFromMemory
(
offset
,
memory
)
{
var
ret
=
[]
var
ret
=
[]
var
length
=
extractLength
(
this
,
offset
,
memory
)
var
length
=
extractLength
(
this
,
offset
,
memory
)
...
...
src/solidity/types/RefType.js
0 → 100644
View file @
a8d89aa4
'use strict'
var
util
=
require
(
'./util'
)
class
RefType
{
constructor
(
storageSlots
,
storageBytes
,
typeName
,
location
)
{
this
.
location
=
location
this
.
storageSlots
=
storageSlots
this
.
storageBytes
=
storageBytes
this
.
typeName
=
typeName
}
decodeFromStack
(
stackDepth
,
stack
,
memory
,
storage
)
{
if
(
stack
.
length
-
1
<
stackDepth
)
{
return
[]
}
var
offset
=
stack
[
stack
.
length
-
1
-
stackDepth
]
offset
=
2
*
parseInt
(
offset
,
16
)
if
(
util
.
storageStore
(
this
))
{
return
this
.
decodeFromStorage
(
offset
,
storage
)
}
else
if
(
util
.
memoryStore
(
this
))
{
return
this
.
decodeFromMemory
(
offset
,
memory
)
}
else
{
return
'<decoding failed - no decoder for '
+
this
.
location
+
'>'
}
}
}
module
.
exports
=
RefType
src/solidity/types/Struct.js
View file @
a8d89aa4
'use strict'
'use strict'
var
util
=
require
(
'./util'
)
var
util
=
require
(
'./util'
)
var
RefType
=
require
(
'./RefType'
)
class
Struct
{
class
Struct
extends
RefType
{
constructor
(
memberDetails
)
{
constructor
(
memberDetails
,
location
)
{
this
.
storageSlots
=
memberDetails
.
storageSlots
super
(
memberDetails
.
storageSlots
,
32
,
'struct'
,
location
)
this
.
storageBytes
=
32
this
.
members
=
memberDetails
.
members
this
.
members
=
memberDetails
.
members
this
.
typeName
=
'struct'
}
}
decodeFromStorage
(
location
,
storageContent
)
{
decodeFromStorage
(
location
,
storageContent
)
{
...
@@ -21,16 +20,6 @@ class Struct {
...
@@ -21,16 +20,6 @@ class Struct {
return
ret
return
ret
}
}
decodeFromStack
(
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
)
}
}
decodeFromMemory
(
offset
,
memory
)
{
decodeFromMemory
(
offset
,
memory
)
{
var
ret
=
{}
var
ret
=
{}
this
.
members
.
map
(
function
(
item
,
i
)
{
this
.
members
.
map
(
function
(
item
,
i
)
{
...
...
src/solidity/types/util.js
View file @
a8d89aa4
...
@@ -10,7 +10,9 @@ module.exports = {
...
@@ -10,7 +10,9 @@ module.exports = {
extractHexByteSlice
:
extractHexByteSlice
,
extractHexByteSlice
:
extractHexByteSlice
,
sha3
:
sha3
,
sha3
:
sha3
,
toBN
:
toBN
,
toBN
:
toBN
,
add
:
add
add
:
add
,
storageStore
:
storageStore
,
memoryStore
:
memoryStore
}
}
function
decodeInt
(
location
,
storageContent
,
byteLength
,
signed
)
{
function
decodeInt
(
location
,
storageContent
,
byteLength
,
signed
)
{
...
@@ -91,3 +93,11 @@ function toBN (value) {
...
@@ -91,3 +93,11 @@ function toBN (value) {
function
add
(
value1
,
value2
)
{
function
add
(
value1
,
value2
)
{
return
toBN
(
value1
).
add
(
toBN
(
value2
))
return
toBN
(
value1
).
add
(
toBN
(
value2
))
}
}
function
storageStore
(
type
)
{
return
type
.
location
.
indexOf
(
'storage'
)
===
0
}
function
memoryStore
(
type
)
{
return
type
.
location
.
indexOf
(
'memory'
)
===
0
}
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