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')
...
@@ -19,12 +19,8 @@ var UintType = require('./types/Uint')
*/
*/
function
Uint
(
type
)
{
function
Uint
(
type
)
{
type
===
'uint'
?
'uint256'
:
type
type
===
'uint'
?
'uint256'
:
type
var
decodeInfo
=
{
var
storageBytes
=
parseInt
(
type
.
replace
(
'uint'
,
''
))
/
8
storageSlots
:
1
,
return
new
UintType
(
storageBytes
)
storageBytes
:
parseInt
(
type
.
replace
(
'uint'
,
''
))
/
8
,
typeName
:
'uint'
}
return
new
UintType
(
decodeInfo
)
}
}
/**
/**
...
@@ -35,12 +31,8 @@ function Uint (type) {
...
@@ -35,12 +31,8 @@ function Uint (type) {
*/
*/
function
Int
(
type
)
{
function
Int
(
type
)
{
type
===
'int'
?
'int256'
:
type
type
===
'int'
?
'int256'
:
type
var
decodeInfo
=
{
var
storageBytes
=
parseInt
(
type
.
replace
(
'int'
,
''
))
/
8
storageSlots
:
1
,
return
new
IntType
(
storageBytes
)
storageBytes
:
parseInt
(
type
.
replace
(
'int'
,
''
))
/
8
,
typeName
:
'int'
}
return
new
IntType
(
decodeInfo
)
}
}
/**
/**
...
@@ -50,12 +42,7 @@ function Int (type) {
...
@@ -50,12 +42,7 @@ function Int (type) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
*/
function
Address
(
type
)
{
function
Address
(
type
)
{
var
decodeInfo
=
{
return
new
AddressType
()
storageSlots
:
1
,
storageBytes
:
20
,
typeName
:
'address'
}
return
new
AddressType
(
decodeInfo
)
}
}
/**
/**
...
@@ -65,12 +52,7 @@ function Address (type) {
...
@@ -65,12 +52,7 @@ function Address (type) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
*/
function
Bool
(
type
)
{
function
Bool
(
type
)
{
var
decodeInfo
=
{
return
new
BoolType
()
storageSlots
:
1
,
storageBytes
:
1
,
typeName
:
'bool'
}
return
new
BoolType
(
decodeInfo
)
}
}
/**
/**
...
@@ -80,12 +62,7 @@ function Bool (type) {
...
@@ -80,12 +62,7 @@ function Bool (type) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
*/
function
DynamicByteArray
(
type
)
{
function
DynamicByteArray
(
type
)
{
var
decodeInfo
=
{
return
new
BytesType
()
storageSlots
:
1
,
storageBytes
:
32
,
typeName
:
'bytes'
}
return
new
BytesType
(
decodeInfo
)
}
}
/**
/**
...
@@ -95,12 +72,8 @@ function DynamicByteArray (type) {
...
@@ -95,12 +72,8 @@ function DynamicByteArray (type) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
*/
function
FixedByteArray
(
type
)
{
function
FixedByteArray
(
type
)
{
var
decodeInfo
=
{
var
storageBytes
=
parseInt
(
type
.
replace
(
'bytes'
,
''
))
storageSlots
:
1
,
return
new
BytesXType
(
storageBytes
)
storageBytes
:
parseInt
(
type
.
replace
(
'bytes'
,
''
)),
typeName
:
'bytesX'
}
return
new
BytesXType
(
decodeInfo
)
}
}
/**
/**
...
@@ -110,12 +83,7 @@ function FixedByteArray (type) {
...
@@ -110,12 +83,7 @@ function FixedByteArray (type) {
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
* @return {Object} returns decoded info about the current type: { storageBytes, typeName}
*/
*/
function
String
(
type
)
{
function
String
(
type
)
{
var
decodeInfo
=
{
return
new
StringType
()
storageSlots
:
1
,
storageBytes
:
32
,
typeName
:
'string'
}
return
new
StringType
(
decodeInfo
)
}
}
/**
/**
...
@@ -126,41 +94,18 @@ function String (type) {
...
@@ -126,41 +94,18 @@ function String (type) {
*/
*/
function
Array
(
type
,
stateDefinitions
)
{
function
Array
(
type
,
stateDefinitions
)
{
var
arraySize
var
arraySize
var
match
=
type
.
match
(
/
(
.*
)\[(
.*
?)\](
storage ref| storage pointer| memory| calldata
)?
$/
)
var
match
=
type
.
match
(
/
(
.*
)\[(
.*
?)\](
storage ref| storage pointer| memory| calldata
)?
$/
)
if
(
!
match
||
match
.
length
<
3
)
{
if
(
!
match
||
match
.
length
<
3
)
{
console
.
log
(
'unable to parse type '
+
type
)
console
.
log
(
'unable to parse type '
+
type
)
return
null
return
null
}
}
arraySize
=
match
[
2
]
===
''
?
'dynamic'
:
parseInt
(
match
[
2
])
arraySize
=
match
[
2
]
===
''
?
'dynamic'
:
parseInt
(
match
[
2
])
var
underlyingType
=
parseType
(
match
[
1
],
stateDefinitions
)
var
underlyingType
=
parseType
(
match
[
1
],
stateDefinitions
)
if
(
underlyingType
===
null
)
{
if
(
underlyingType
===
null
)
{
console
.
log
(
'unable to parse type '
+
type
)
console
.
log
(
'unable to parse type '
+
type
)
return
null
return
null
}
}
return
new
ArrayType
(
underlyingType
,
arraySize
)
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
)
}
}
/**
/**
...
@@ -175,19 +120,7 @@ function Enum (type, stateDefinitions) {
...
@@ -175,19 +120,7 @@ function Enum (type, stateDefinitions) {
console
.
log
(
'unable to retrieve decode info of '
+
type
)
console
.
log
(
'unable to retrieve decode info of '
+
type
)
return
null
return
null
}
}
var
length
=
enumDef
.
children
.
length
return
new
EnumType
(
enumDef
)
var
storageBytes
=
0
while
(
length
>
1
)
{
length
=
length
/
256
storageBytes
++
}
var
decodeInfo
=
{
storageSlots
:
1
,
storageBytes
:
storageBytes
,
typeName
:
'enum'
,
enum
:
enumDef
}
return
new
EnumType
(
decodeInfo
)
}
}
/**
/**
...
@@ -203,13 +136,7 @@ function Struct (type, stateDefinitions) {
...
@@ -203,13 +136,7 @@ function Struct (type, stateDefinitions) {
}
}
var
memberDetails
=
getStructMembers
(
match
[
1
],
stateDefinitions
)
// type is used to extract the ast struct definition
var
memberDetails
=
getStructMembers
(
match
[
1
],
stateDefinitions
)
// type is used to extract the ast struct definition
if
(
!
memberDetails
)
return
null
if
(
!
memberDetails
)
return
null
var
decodeInfo
=
{
return
new
StructType
(
memberDetails
)
storageSlots
:
Math
.
ceil
(
memberDetails
.
storageBytes
/
32
),
storageBytes
:
32
,
typeName
:
'struct'
,
members
:
memberDetails
.
members
}
return
new
StructType
(
decodeInfo
)
}
}
/**
/**
...
...
src/solidity/types/Address.js
View file @
5a833953
'use strict'
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
Address
(
decoder
)
{
function
Address
()
{
baseType
(
this
,
decoder
)
this
.
storageSlots
=
1
this
.
storageBytes
=
20
this
.
typeName
=
'address'
}
}
Address
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
Address
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/ArrayType.js
View file @
5a833953
'use strict'
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
ArrayType
(
decoder
)
{
function
ArrayType
(
underlyingType
,
arraySize
)
{
baseType
(
this
,
decoder
)
this
.
typeName
=
'array'
this
.
arraySize
=
decoder
.
arraySize
this
.
storageBytes
=
32
this
.
subArray
=
decoder
.
subArray
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
)
{
ArrayType
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/Bool.js
View file @
5a833953
'use strict'
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
Bool
(
decoder
)
{
function
Bool
()
{
baseType
(
this
,
decoder
)
this
.
storageSlots
=
1
this
.
storageBytes
=
1
this
.
typeName
=
'bool'
}
}
Bool
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
Bool
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/DynamicByteArray.js
View file @
5a833953
'use strict'
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
DynamicByteArray
(
decoder
)
{
function
DynamicByteArray
()
{
baseType
(
this
,
decoder
)
this
.
storageSlots
=
1
this
.
storageBytes
=
32
this
.
typeName
=
'bytes'
}
}
DynamicByteArray
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
DynamicByteArray
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/Enum.js
View file @
5a833953
'use strict'
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
Enum
(
decoder
)
{
function
Enum
(
enumDef
)
{
baseType
(
this
,
decoder
)
this
.
enumDef
=
enumDef
this
.
enum
=
decoder
.
enum
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
)
{
Enum
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/FixedByteArray.js
View file @
5a833953
'use strict'
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
FixedByteArray
(
decoder
)
{
function
FixedByteArray
(
storageBytes
)
{
baseType
(
this
,
decoder
)
this
.
storageSlots
=
1
this
.
storageBytes
=
storageBytes
this
.
typeName
=
'bytesX'
}
}
FixedByteArray
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
FixedByteArray
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/Int.js
View file @
5a833953
'use strict'
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
Int
(
decoder
)
{
function
Int
(
storageBytes
)
{
baseType
(
this
,
decoder
)
this
.
storageSlots
=
1
this
.
storageBytes
=
storageBytes
this
.
typeName
=
'int'
}
}
Int
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
Int
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/StringType.js
View file @
5a833953
'use strict'
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
StringType
(
decoder
)
{
function
StringType
()
{
baseType
(
this
,
decoder
)
this
.
storageSlots
=
1
this
.
storageBytes
=
32
this
.
typeName
=
'string'
}
}
StringType
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
StringType
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/Struct.js
View file @
5a833953
'use strict'
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
Struct
(
decoder
)
{
function
Struct
(
memberDetails
)
{
baseType
(
this
,
decoder
)
this
.
storageSlots
=
Math
.
ceil
(
memberDetails
.
storageBytes
/
32
)
this
.
members
=
decoder
.
members
this
.
storageBytes
=
32
this
.
members
=
memberDetails
.
members
this
.
typeName
=
'struct'
}
}
Struct
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
Struct
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
...
...
src/solidity/types/Uint.js
View file @
5a833953
'use strict'
'use strict'
var
baseType
=
require
(
'./baseType'
)
function
Uint
(
decoder
)
{
function
Uint
(
storageBytes
)
{
baseType
(
this
,
decoder
)
this
.
storageSlots
=
1
this
.
storageBytes
=
storageBytes
this
.
typeName
=
'uint'
}
}
Uint
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
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