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
e3934b91
Commit
e3934b91
authored
Oct 31, 2016
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
- renaming
- add comments
parent
0e392522
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
42 deletions
+35
-42
astHelper.js
src/solidity/astHelper.js
+12
-12
decodeInfo.js
src/solidity/decodeInfo.js
+23
-30
No files found.
src/solidity/astHelper.js
View file @
e3934b91
...
...
@@ -7,15 +7,15 @@ var AstWalker = require('../util/astWalker')
* @param {Object} sourcesList - sources list (containing root AST node)
* @return {Object} - returns a mapping from AST node ids to AST nodes for the contracts
*/
function
extractContract
sDefinition
(
sourcesList
)
{
function
extractContract
Definitions
(
sourcesList
)
{
var
ret
=
{
contracts
Ids
:
{},
contracts
Names
:
{}
contracts
ById
:
{},
contracts
ByName
:
{}
}
var
walker
=
new
AstWalker
()
walker
.
walkAstList
(
sourcesList
,
{
'ContractDefinition'
:
function
(
node
)
{
ret
.
contracts
Ids
[
node
.
id
]
=
node
ret
.
contracts
Names
[
node
.
attributes
.
name
]
=
node
.
id
ret
.
contracts
ById
[
node
.
id
]
=
node
ret
.
contracts
ByName
[
node
.
attributes
.
name
]
=
node
return
false
}})
return
ret
...
...
@@ -28,8 +28,8 @@ function extractContractsDefinition (sourcesList) {
* @param {Map} contracts - all contracts defined in the current context
* @return {Array} - array of base contracts in derived to base order as AST nodes.
*/
function
getLinearizedBaseContracts
(
id
,
contracts
)
{
return
contracts
[
id
].
attributes
.
linearizedBaseContracts
.
map
(
function
(
id
)
{
return
contracts
[
id
]
})
function
getLinearizedBaseContracts
(
id
,
contracts
ById
)
{
return
contracts
ById
[
id
].
attributes
.
linearizedBaseContracts
.
map
(
function
(
id
)
{
return
contractsById
[
id
]
})
}
/**
...
...
@@ -40,11 +40,11 @@ function getLinearizedBaseContracts (id, contracts) {
* @return {Array} - return an array of AST node of all state variables (including inherited) (this will include all enum/struct declarations)
*/
function
extractStateVariables
(
contractName
,
sourcesList
)
{
var
contracts
=
extractContract
sDefinition
(
sourcesList
)
var
id
=
contracts
.
contractsNames
[
contractName
]
if
(
id
)
{
var
contracts
=
extractContract
Definitions
(
sourcesList
)
var
node
=
contracts
.
contractsByName
[
contractName
]
if
(
node
)
{
var
stateVar
=
[]
var
baseContracts
=
getLinearizedBaseContracts
(
id
,
contracts
.
contractsIds
)
var
baseContracts
=
getLinearizedBaseContracts
(
node
.
id
,
contracts
.
contractsById
)
baseContracts
.
reverse
()
for
(
var
k
in
baseContracts
)
{
var
ctr
=
baseContracts
[
k
]
...
...
@@ -59,6 +59,6 @@ function extractStateVariables (contractName, sourcesList) {
module
.
exports
=
{
extractStateVariables
:
extractStateVariables
,
extractContract
sDefinition
:
extractContractsDefinition
,
extractContract
Definitions
:
extractContractDefinitions
,
getLinearizedBaseContracts
:
getLinearizedBaseContracts
}
src/solidity/decodeInfo.js
View file @
e3934b91
'use strict'
/**
* Uint decode the given @arg type
*
* @param {String} type - type given by the AST
* @param {String} type - type given by the AST
(e.g uint256, uint32)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/
function
Uint
(
type
)
{
if
(
type
.
split
(
' '
))
{
type
=
type
.
split
(
' '
)[
0
]
}
return
{
needsFreeStorageSlot
:
false
,
storageBytes
:
parseInt
(
type
.
replace
(
'uint'
,
''
))
/
8
,
...
...
@@ -18,9 +14,23 @@ function Uint (type) {
}
/**
* Int decode the given @arg type
*
* @param {String} type - type given by the AST (e.g int256, int32)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/
function
Int
(
type
)
{
return
{
needsFreeStorageSlot
:
false
,
storageBytes
:
parseInt
(
type
.
replace
(
'int'
,
''
))
/
8
,
typeName
:
type
}
}
/**
* Address decode the given @arg type
*
* @param {String} type - type given by the AST
* @param {String} type - type given by the AST
(e.g address)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/
function
Address
(
type
)
{
...
...
@@ -34,7 +44,7 @@ function Address (type) {
/**
* Bool decode the given @arg type
*
* @param {String} type - type given by the AST
* @param {String} type - type given by the AST
(e.g bool)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/
function
Bool
(
type
)
{
...
...
@@ -48,7 +58,7 @@ function Bool (type) {
/**
* DynamicByteArray decode the given @arg type
*
* @param {String} type - type given by the AST
* @param {String} type - type given by the AST
(e.g bytes storage ref)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/
function
DynamicByteArray
(
type
)
{
...
...
@@ -62,7 +72,7 @@ function DynamicByteArray (type) {
/**
* FixedByteArray decode the given @arg type
*
* @param {String} type - type given by the AST
* @param {String} type - type given by the AST
(e.g bytes16)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/
function
FixedByteArray
(
type
)
{
...
...
@@ -77,26 +87,9 @@ function FixedByteArray (type) {
}
/**
* Int decode the given @arg type
*
* @param {String} type - type given by the AST
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/
function
Int
(
type
)
{
if
(
type
.
split
(
' '
))
{
type
=
type
.
split
(
' '
)[
0
]
}
return
{
needsFreeStorageSlot
:
false
,
storageBytes
:
parseInt
(
type
.
replace
(
'int'
,
''
))
/
8
,
typeName
:
type
}
}
/**
* StringType decode the given @arg type
*
* @param {String} type - type given by the AST
* @param {String} type - type given by the AST
(e.g string storage ref)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/
function
StringType
(
type
)
{
...
...
@@ -110,7 +103,7 @@ function StringType (type) {
/**
* ArrayType decode the given @arg type
*
* @param {String} type - type given by the AST
* @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: { needsFreeStorageSlot, storageBytes, typeName, decoder, arraySize, subArray}
*/
function
ArrayType
(
type
,
stateDefinitions
)
{
...
...
@@ -153,7 +146,7 @@ function ArrayType (type, stateDefinitions) {
/**
* Enum decode the given @arg type
*
* @param {String} type - type given by the AST
* @param {String} type - type given by the AST
(e.g enum enumDef)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder}
*/
function
Enum
(
type
,
stateDefinitions
)
{
...
...
@@ -169,7 +162,7 @@ function Enum (type, stateDefinitions) {
/**
* Struct decode the given @arg type
*
* @param {String} type - type given by the AST
* @param {String} type - type given by the AST
(e.g struct structDef storage ref)
* @return {Object} returns decoded info about the current type: { needsFreeStorageSlot, storageBytes, typeName, decoder, members}
*/
function
Struct
(
type
,
stateDefinitions
)
{
...
...
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