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
d8373b22
Commit
d8373b22
authored
Nov 16, 2016
by
yann300
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement int, uint decoding
parent
4e5f7002
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
2 deletions
+42
-2
Int.js
src/solidity/types/Int.js
+19
-1
Uint.js
src/solidity/types/Uint.js
+10
-1
util.js
src/solidity/types/util.js
+13
-0
No files found.
src/solidity/types/Int.js
View file @
d8373b22
'use strict'
var
util
=
require
(
'./util'
)
var
BN
=
require
(
'ethereumjs-util'
).
BN
var
ethutil
=
require
(
'ethereumjs-util'
)
function
Int
(
storageBytes
)
{
this
.
storageSlots
=
1
...
...
@@ -7,7 +10,22 @@ function Int (storageBytes) {
}
Int
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
return
'<not implemented yet>'
var
slot
=
ethutil
.
bufferToHex
(
ethutil
.
setLengthLeft
(
location
.
slot
,
32
))
if
(
!
storageContent
[
slot
])
{
return
'0'
}
var
value
=
util
.
extractValue
(
storageContent
[
slot
],
this
.
storageBytes
,
location
)
var
bigNumber
=
new
BN
(
value
.
replace
(
'0x'
,
''
),
16
)
if
(
isNegative
(
bigNumber
,
this
.
storageBytes
))
{
return
ethutil
.
fromSigned
(
ethutil
.
toUnsigned
(
bigNumber
)).
toString
(
10
)
}
else
{
return
bigNumber
.
toString
(
10
)
}
}
module
.
exports
=
Int
function
isNegative
(
value
,
storageBytes
)
{
var
binary
=
value
.
toString
(
2
)
return
binary
.
length
<
storageBytes
?
false
:
binary
[
0
]
===
'1'
}
src/solidity/types/Uint.js
View file @
d8373b22
'use strict'
var
util
=
require
(
'./util'
)
var
ethutil
=
require
(
'ethereumjs-util'
)
var
BN
=
require
(
'ethereumjs-util'
).
BN
function
Uint
(
storageBytes
)
{
this
.
storageSlots
=
1
...
...
@@ -7,7 +10,13 @@ function Uint (storageBytes) {
}
Uint
.
prototype
.
decodeFromStorage
=
function
(
location
,
storageContent
)
{
return
'<not implemented yet>'
var
slot
=
ethutil
.
bufferToHex
(
ethutil
.
setLengthLeft
(
location
.
slot
,
32
))
if
(
!
storageContent
[
slot
])
{
return
'0'
}
var
value
=
util
.
extractValue
(
storageContent
[
slot
],
this
.
storageBytes
,
location
)
var
bigNumber
=
new
BN
(
value
.
replace
(
'0x'
,
''
),
16
)
return
bigNumber
.
toString
(
10
)
}
module
.
exports
=
Uint
src/solidity/types/util.js
0 → 100644
View file @
d8373b22
module
.
exports
=
{
extractValue
:
function
(
slotValue
,
storageBytes
,
location
)
{
slotValue
=
slotValue
.
replace
(
'0x'
,
''
)
var
offset
=
slotValue
.
length
-
2
*
location
.
offset
-
storageBytes
/
4
if
(
offset
>=
0
)
{
return
'0x'
+
slotValue
.
substr
(
offset
,
storageBytes
/
4
)
}
else
if
(
offset
+
storageBytes
>
0
)
{
return
'0x'
+
slotValue
.
substr
(
0
,
storageBytes
/
4
+
offset
)
}
else
{
return
'0x0'
}
}
}
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