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
177d87b5
Commit
177d87b5
authored
Nov 14, 2016
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
return type directly instead of decode info
parent
d53d2ad3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
33 deletions
+42
-33
decodeInfo.js
src/solidity/decodeInfo.js
+41
-19
stateDecoder.js
src/solidity/stateDecoder.js
+1
-14
No files found.
src/solidity/decodeInfo.js
View file @
177d87b5
'use strict'
var
AddressType
=
require
(
'./types/Address'
)
var
ArrayType
=
require
(
'./types/ArrayType'
)
var
BoolType
=
require
(
'./types/Bool'
)
var
BytesType
=
require
(
'./types/DynamicByteArray'
)
var
BytesXType
=
require
(
'./types/FixedByteArray'
)
var
EnumType
=
require
(
'./types/Enum'
)
var
StringType
=
require
(
'./types/StringType'
)
var
StructType
=
require
(
'./types/Struct'
)
var
IntType
=
require
(
'./types/Int'
)
var
UintType
=
require
(
'./types/Uint'
)
/**
* Uint decode the given @arg type
*
...
...
@@ -7,11 +19,12 @@
*/
function
Uint
(
type
)
{
type
===
'uint'
?
'uint256'
:
type
return
{
var
decodeInfo
=
{
storageSlots
:
1
,
storageBytes
:
parseInt
(
type
.
replace
(
'uint'
,
''
))
/
8
,
typeName
:
'uint'
}
return
new
UintType
(
decodeInfo
)
}
/**
...
...
@@ -22,11 +35,12 @@ function Uint (type) {
*/
function
Int
(
type
)
{
type
===
'int'
?
'int256'
:
type
return
{
var
decodeInfo
=
{
storageSlots
:
1
,
storageBytes
:
parseInt
(
type
.
replace
(
'int'
,
''
))
/
8
,
typeName
:
'int'
}
return
new
IntType
(
decodeInfo
)
}
/**
...
...
@@ -36,11 +50,12 @@ function Int (type) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
function
Address
(
type
)
{
return
{
var
decodeInfo
=
{
storageSlots
:
1
,
storageBytes
:
20
,
typeName
:
'address'
}
return
new
AddressType
(
decodeInfo
)
}
/**
...
...
@@ -50,11 +65,12 @@ function Address (type) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
function
Bool
(
type
)
{
return
{
var
decodeInfo
=
{
storageSlots
:
1
,
storageBytes
:
1
,
typeName
:
'bool'
}
return
new
BoolType
(
decodeInfo
)
}
/**
...
...
@@ -64,11 +80,12 @@ function Bool (type) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
function
DynamicByteArray
(
type
)
{
return
{
var
decodeInfo
=
{
storageSlots
:
1
,
storageBytes
:
32
,
typeName
:
'bytes'
}
return
new
BytesType
(
decodeInfo
)
}
/**
...
...
@@ -78,11 +95,12 @@ function DynamicByteArray (type) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
function
FixedByteArray
(
type
)
{
return
{
var
decodeInfo
=
{
storageSlots
:
1
,
storageBytes
:
parseInt
(
type
.
replace
(
'bytes'
,
''
)),
typeName
:
'bytesX'
}
return
new
BytesXType
(
decodeInfo
)
}
/**
...
...
@@ -91,12 +109,13 @@ function FixedByteArray (type) {
* @param {String} type - type given by the AST (e.g string storage ref)
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
function
String
Type
(
type
)
{
return
{
function
String
(
type
)
{
var
decodeInfo
=
{
storageSlots
:
1
,
storageBytes
:
32
,
typeName
:
'string'
}
return
new
StringType
(
decodeInfo
)
}
/**
...
...
@@ -105,7 +124,7 @@ function StringType (type) {
* @param {String} type - type given by the AST (e.g int256[] storage ref, int256[] storage ref[] storage ref)
* @return {Object} returns decoded info about the current type: { storageBytes, typeName, arraySize, subArray}
*/
function
Array
Type
(
type
,
stateDefinitions
)
{
function
Array
(
type
,
stateDefinitions
)
{
var
arraySize
var
match
=
type
.
match
(
/
(
.*
)\[(
.*
?)\](
storage ref| storage pointer| memory| calldata
)?
$/
)
...
...
@@ -116,7 +135,7 @@ function ArrayType (type, stateDefinitions) {
arraySize
=
match
[
2
]
===
''
?
'dynamic'
:
parseInt
(
match
[
2
])
var
underlyingType
=
decod
e
(
match
[
1
],
stateDefinitions
)
var
underlyingType
=
parseTyp
e
(
match
[
1
],
stateDefinitions
)
if
(
underlyingType
===
null
)
{
console
.
log
(
'unable to parse type '
+
type
)
return
null
...
...
@@ -134,13 +153,14 @@ function ArrayType (type, stateDefinitions) {
}
}
return
{
var
decodeInfo
=
{
storageSlots
:
storageSlots
,
storageBytes
:
32
,
typeName
:
'array'
,
arraySize
:
arraySize
,
underlyingType
:
underlyingType
}
return
new
ArrayType
(
decodeInfo
)
}
/**
...
...
@@ -161,12 +181,13 @@ function Enum (type, stateDefinitions) {
length
=
length
/
256
storageBytes
++
}
return
{
var
decodeInfo
=
{
storageSlots
:
1
,
storageBytes
:
storageBytes
,
typeName
:
'enum'
,
enum
:
enumDef
}
return
new
EnumType
(
decodeInfo
)
}
/**
...
...
@@ -182,12 +203,13 @@ function Struct (type, stateDefinitions) {
}
var
memberDetails
=
getStructMembers
(
match
[
1
],
stateDefinitions
)
// type is used to extract the ast struct definition
if
(
!
memberDetails
)
return
null
return
{
var
decodeInfo
=
{
storageSlots
:
Math
.
ceil
(
memberDetails
.
storageBytes
/
32
),
storageBytes
:
32
,
typeName
:
'struct'
,
members
:
memberDetails
.
members
}
return
new
StructType
(
decodeInfo
)
}
/**
...
...
@@ -222,7 +244,7 @@ function getStructMembers (typeName, stateDefinitions) {
if
(
dec
.
name
===
'StructDefinition'
&&
typeName
===
dec
.
attributes
.
name
)
{
for
(
var
i
in
dec
.
children
)
{
var
member
=
dec
.
children
[
i
]
var
decoded
=
decod
e
(
member
.
attributes
.
type
,
stateDefinitions
)
var
decoded
=
parseTyp
e
(
member
.
attributes
.
type
,
stateDefinitions
)
if
(
!
decoded
)
{
console
.
log
(
'unable to retrieve decode info of '
+
member
.
attributes
.
type
)
return
null
...
...
@@ -266,12 +288,12 @@ function typeClass (fullType) {
function
parseType
(
type
,
stateDefinitions
)
{
var
decodeInfos
=
{
'address'
:
Address
,
'array'
:
Array
Type
,
'array'
:
Array
,
'bool'
:
Bool
,
'bytes'
:
DynamicByteArray
,
'bytesX'
:
FixedByteArray
,
'enum'
:
Enum
,
'string'
:
String
Type
,
'string'
:
String
,
'struct'
:
Struct
,
'int'
:
Int
,
'uint'
:
Uint
...
...
@@ -285,15 +307,15 @@ function parseType (type, stateDefinitions) {
}
module
.
exports
=
{
decod
e
:
parseType
,
parseTyp
e
:
parseType
,
Uint
:
Uint
,
Address
:
Address
,
Bool
:
Bool
,
DynamicByteArray
:
DynamicByteArray
,
FixedByteArray
:
FixedByteArray
,
Int
:
Int
,
String
Type
:
StringType
,
Array
Type
:
ArrayType
,
String
:
String
,
Array
:
Array
,
Enum
:
Enum
,
Struct
:
Struct
}
src/solidity/stateDecoder.js
View file @
177d87b5
...
...
@@ -41,8 +41,7 @@ function extractStateVariables (contractName, sourcesList) {
for
(
var
k
in
stateDefinitions
)
{
var
variable
=
stateDefinitions
[
k
]
if
(
variable
.
name
===
'VariableDeclaration'
)
{
var
decoded
=
decodeInfo
.
parseType
(
variable
.
attributes
.
type
,
stateDefinitions
)
var
type
=
new
types
[
decoded
.
typeName
](
decoded
)
var
type
=
decodeInfo
.
parseType
(
variable
.
attributes
.
type
,
stateDefinitions
)
if
(
location
.
offset
+
type
.
storageBytes
>
32
)
{
location
.
slot
++
location
.
offset
=
0
...
...
@@ -85,15 +84,3 @@ module.exports = {
decodeState
:
decodeState
}
var
types
=
{
'address'
:
require
(
'./types/Address'
),
'array'
:
require
(
'./types/ArrayType'
),
'bool'
:
require
(
'./types/Bool'
),
'bytes'
:
require
(
'./types/DynamicByteArray'
),
'bytesX'
:
require
(
'./types/FixedByteArray'
),
'enum'
:
require
(
'./types/Enum'
),
'string'
:
require
(
'./types/StringType'
),
'struct'
:
require
(
'./types/Struct'
),
'int'
:
require
(
'./types/Int'
),
'uint'
:
require
(
'./types/Uint'
)
}
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