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
5a833953
Commit
5a833953
authored
Nov 15, 2016
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change types ctor
parent
cf10206c
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
72 additions
and
128 deletions
+72
-128
decodeInfo.js
src/solidity/decodeInfo.js
+13
-86
Address.js
src/solidity/types/Address.js
+4
-3
ArrayType.js
src/solidity/types/ArrayType.js
+16
-5
Bool.js
src/solidity/types/Bool.js
+4
-3
DynamicByteArray.js
src/solidity/types/DynamicByteArray.js
+4
-3
Enum.js
src/solidity/types/Enum.js
+10
-4
FixedByteArray.js
src/solidity/types/FixedByteArray.js
+4
-3
Int.js
src/solidity/types/Int.js
+4
-3
StringType.js
src/solidity/types/StringType.js
+4
-3
Struct.js
src/solidity/types/Struct.js
+5
-4
Uint.js
src/solidity/types/Uint.js
+4
-3
baseType.js
src/solidity/types/baseType.js
+0
-8
No files found.
src/solidity/decodeInfo.js
View file @
5a833953
...
...
@@ -19,12 +19,8 @@ var UintType = require('./types/Uint')
*/
function
Uint
(
type
)
{
type
===
'uint'
?
'uint256'
:
type
var
decodeInfo
=
{
storageSlots
:
1
,
storageBytes
:
parseInt
(
type
.
replace
(
'uint'
,
''
))
/
8
,
typeName
:
'uint'
}
return
new
UintType
(
decodeInfo
)
var
storageBytes
=
parseInt
(
type
.
replace
(
'uint'
,
''
))
/
8
return
new
UintType
(
storageBytes
)
}
/**
...
...
@@ -35,12 +31,8 @@ function Uint (type) {
*/
function
Int
(
type
)
{
type
===
'int'
?
'int256'
:
type
var
decodeInfo
=
{
storageSlots
:
1
,
storageBytes
:
parseInt
(
type
.
replace
(
'int'
,
''
))
/
8
,
typeName
:
'int'
}
return
new
IntType
(
decodeInfo
)
var
storageBytes
=
parseInt
(
type
.
replace
(
'int'
,
''
))
/
8
return
new
IntType
(
storageBytes
)
}
/**
...
...
@@ -50,12 +42,7 @@ function Int (type) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
function
Address
(
type
)
{
var
decodeInfo
=
{
storageSlots
:
1
,
storageBytes
:
20
,
typeName
:
'address'
}
return
new
AddressType
(
decodeInfo
)
return
new
AddressType
()
}
/**
...
...
@@ -65,12 +52,7 @@ function Address (type) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
function
Bool
(
type
)
{
var
decodeInfo
=
{
storageSlots
:
1
,
storageBytes
:
1
,
typeName
:
'bool'
}
return
new
BoolType
(
decodeInfo
)
return
new
BoolType
()
}
/**
...
...
@@ -80,12 +62,7 @@ function Bool (type) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
function
DynamicByteArray
(
type
)
{
var
decodeInfo
=
{
storageSlots
:
1
,
storageBytes
:
32
,
typeName
:
'bytes'
}
return
new
BytesType
(
decodeInfo
)
return
new
BytesType
()
}
/**
...
...
@@ -95,12 +72,8 @@ function DynamicByteArray (type) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
function
FixedByteArray
(
type
)
{
var
decodeInfo
=
{
storageSlots
:
1
,
storageBytes
:
parseInt
(
type
.
replace
(
'bytes'
,
''
)),
typeName
:
'bytesX'
}
return
new
BytesXType
(
decodeInfo
)
var
storageBytes
=
parseInt
(
type
.
replace
(
'bytes'
,
''
))
return
new
BytesXType
(
storageBytes
)
}
/**
...
...
@@ -110,12 +83,7 @@ function FixedByteArray (type) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
function
String
(
type
)
{
var
decodeInfo
=
{
storageSlots
:
1
,
storageBytes
:
32
,
typeName
:
'string'
}
return
new
StringType
(
decodeInfo
)
return
new
StringType
()
}
/**
...
...
@@ -126,41 +94,18 @@ function String (type) {
*/
function
Array
(
type
,
stateDefinitions
)
{
var
arraySize
var
match
=
type
.
match
(
/
(
.*
)\[(
.*
?)\](
storage ref| storage pointer| memory| calldata
)?
$/
)
if
(
!
match
||
match
.
length
<
3
)
{
console
.
log
(
'unable to parse type '
+
type
)
return
null
}
arraySize
=
match
[
2
]
===
''
?
'dynamic'
:
parseInt
(
match
[
2
])
var
underlyingType
=
parseType
(
match
[
1
],
stateDefinitions
)
if
(
underlyingType
===
null
)
{
console
.
log
(
'unable to parse type '
+
type
)
return
null
}
var
storageSlots
if
(
arraySize
===
'dynamic'
)
{
storageSlots
=
1
}
else
{
if
(
underlyingType
.
storageBytes
<
32
)
{
var
itemPerSlot
=
Math
.
floor
(
32
/
underlyingType
.
storageBytes
)
storageSlots
=
Math
.
ceil
(
arraySize
/
itemPerSlot
)
}
else
{
storageSlots
=
arraySize
*
underlyingType
.
storageSlots
}
}
var
decodeInfo
=
{
storageSlots
:
storageSlots
,
storageBytes
:
32
,
typeName
:
'array'
,
arraySize
:
arraySize
,
underlyingType
:
underlyingType
}
return
new
ArrayType
(
decodeInfo
)
return
new
ArrayType
(
underlyingType
,
arraySize
)
}
/**
...
...
@@ -175,19 +120,7 @@ function Enum (type, stateDefinitions) {
console
.
log
(
'unable to retrieve decode info of '
+
type
)
return
null
}
var
length
=
enumDef
.
children
.
length
var
storageBytes
=
0
while
(
length
>
1
)
{
length
=
length
/
256
storageBytes
++
}
var
decodeInfo
=
{
storageSlots
:
1
,
storageBytes
:
storageBytes
,
typeName
:
'enum'
,
enum
:
enumDef
}
return
new
EnumType
(
decodeInfo
)
return
new
EnumType
(
enumDef
)
}
/**
...
...
@@ -203,13 +136,7 @@ function Struct (type, stateDefinitions) {
}
var
memberDetails
=
getStructMembers
(
match
[
1
],
stateDefinitions
)
// type is used to extract the ast struct definition
if
(
!
memberDetails
)
return
null
var
decodeInfo
=
{
storageSlots
:
Math
.
ceil
(
memberDetails
.
storageBytes
/
32
),
storageBytes
:
32
,
typeName
:
'struct'
,
members
:
memberDetails
.
members
}
return
new
StructType
(
decodeInfo
)
return
new
StructType
(
memberDetails
)
}
/**
...
...
src/solidity/types/Address.js
View file @
5a833953
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
Address
(
decoder
)
{
baseType
(
this
,
decoder
)
function
Address
()
{
this
.
storageSlots
=
1
this
.
storageBytes
=
20
this
.
typeName
=
'address'
}
Address
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/ArrayType.js
View file @
5a833953
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
ArrayType
(
decoder
)
{
baseType
(
this
,
decoder
)
this
.
arraySize
=
decoder
.
arraySize
this
.
subArray
=
decoder
.
subArray
function
ArrayType
(
underlyingType
,
arraySize
)
{
this
.
typeName
=
'array'
this
.
storageBytes
=
32
this
.
underlyingType
=
underlyingType
this
.
arraySize
=
arraySize
this
.
storageSlots
=
null
if
(
arraySize
===
'dynamic'
)
{
this
.
storageSlots
=
1
}
else
{
if
(
underlyingType
.
storageBytes
<
32
)
{
var
itemPerSlot
=
Math
.
floor
(
32
/
underlyingType
.
storageBytes
)
this
.
storageSlots
=
Math
.
ceil
(
arraySize
/
itemPerSlot
)
}
else
{
this
.
storageSlots
=
arraySize
*
underlyingType
.
storageSlots
}
}
}
ArrayType
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/Bool.js
View file @
5a833953
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
Bool
(
decoder
)
{
baseType
(
this
,
decoder
)
function
Bool
()
{
this
.
storageSlots
=
1
this
.
storageBytes
=
1
this
.
typeName
=
'bool'
}
Bool
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/DynamicByteArray.js
View file @
5a833953
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
DynamicByteArray
(
decoder
)
{
baseType
(
this
,
decoder
)
function
DynamicByteArray
()
{
this
.
storageSlots
=
1
this
.
storageBytes
=
32
this
.
typeName
=
'bytes'
}
DynamicByteArray
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/Enum.js
View file @
5a833953
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
Enum
(
decoder
)
{
baseType
(
this
,
decoder
)
this
.
enum
=
decoder
.
enum
function
Enum
(
enumDef
)
{
this
.
enumDef
=
enumDef
this
.
typeName
=
'enum'
this
.
storageSlots
=
1
var
length
=
enumDef
.
children
.
length
this
.
storageBytes
=
0
while
(
length
>
1
)
{
length
=
length
/
256
this
.
storageBytes
++
}
}
Enum
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/FixedByteArray.js
View file @
5a833953
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
FixedByteArray
(
decoder
)
{
baseType
(
this
,
decoder
)
function
FixedByteArray
(
storageBytes
)
{
this
.
storageSlots
=
1
this
.
storageBytes
=
storageBytes
this
.
typeName
=
'bytesX'
}
FixedByteArray
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/Int.js
View file @
5a833953
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
Int
(
decoder
)
{
baseType
(
this
,
decoder
)
function
Int
(
storageBytes
)
{
this
.
storageSlots
=
1
this
.
storageBytes
=
storageBytes
this
.
typeName
=
'int'
}
Int
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/StringType.js
View file @
5a833953
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
StringType
(
decoder
)
{
baseType
(
this
,
decoder
)
function
StringType
()
{
this
.
storageSlots
=
1
this
.
storageBytes
=
32
this
.
typeName
=
'string'
}
StringType
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/Struct.js
View file @
5a833953
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
Struct
(
decoder
)
{
baseType
(
this
,
decoder
)
this
.
members
=
decoder
.
members
function
Struct
(
memberDetails
)
{
this
.
storageSlots
=
Math
.
ceil
(
memberDetails
.
storageBytes
/
32
)
this
.
storageBytes
=
32
this
.
members
=
memberDetails
.
members
this
.
typeName
=
'struct'
}
Struct
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/Uint.js
View file @
5a833953
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
Uint
(
decoder
)
{
baseType
(
this
,
decoder
)
function
Uint
(
storageBytes
)
{
this
.
storageSlots
=
1
this
.
storageBytes
=
storageBytes
this
.
typeName
=
'uint'
}
Uint
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/baseType.js
deleted
100644 → 0
View file @
cf10206c
'use strict'
module
.
exports
=
function
(
type
,
decoder
)
{
type
.
storageSlots
=
decoder
.
storageSlots
type
.
storageBytes
=
decoder
.
storageBytes
type
.
typeName
=
decoder
.
typeName
type
.
decoder
=
decoder
.
decoder
}
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