Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
774e9d24
Commit
774e9d24
authored
Jan 16, 2015
by
Marek Kotewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
abi.js rounds down floating point input
parent
9a264a42
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
49 additions
and
24 deletions
+49
-24
ethereum.js
dist/ethereum.js
+11
-11
ethereum.js.map
dist/ethereum.js.map
+1
-1
ethereum.min.js
dist/ethereum.min.js
+1
-1
abi.js
lib/abi.js
+11
-11
abi.parsers.js
test/abi.parsers.js
+25
-0
No files found.
dist/ethereum.js
View file @
774e9d24
...
...
@@ -29,6 +29,8 @@ if ("build" !== 'build') {/*
var
web3
=
require
(
'./web3'
);
// jshint ignore:line
BigNumber
.
config
({
ROUNDING_MODE
:
BigNumber
.
ROUND_DOWN
});
// TODO: make these be actually accurate instead of falling back onto JS's doubles.
var
hexToDec
=
function
(
hex
)
{
return
parseInt
(
hex
,
16
).
toString
();
...
...
@@ -88,25 +90,23 @@ var setupInputTypes = function () {
/// Formats input value to byte representation of int
/// If value is negative, return it's two's complement
/// If the value is floating point, it rounds it down
/// @returns right-aligned byte representation of int
var
formatInt
=
function
(
value
)
{
var
padding
=
32
*
2
;
if
(
value
instanceof
BigNumber
)
{
if
(
value
instanceof
BigNumber
||
typeof
value
===
'number'
)
{
if
(
typeof
value
===
'number'
)
value
=
new
BigNumber
(
value
);
value
=
value
.
round
();
if
(
value
.
lessThan
(
0
))
value
=
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
).
plus
(
value
).
plus
(
1
).
toString
(
16
);
else
value
=
value
.
toString
(
16
);
}
else
if
(
typeof
value
===
'number'
)
{
if
(
value
<
0
)
value
=
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
).
plus
(
value
).
plus
(
1
).
toString
(
16
);
else
value
=
new
BigNumber
(
value
).
toString
(
16
);
value
=
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
).
plus
(
value
).
plus
(
1
);
value
=
value
.
toString
(
16
);
}
else
if
(
value
.
indexOf
(
'0x'
)
===
0
)
value
=
value
.
substr
(
2
);
else
if
(
typeof
value
===
'string'
)
value
=
new
BigNumber
(
value
).
toString
(
16
);
value
=
formatInt
(
new
BigNumber
(
value
));
else
value
=
(
+
value
).
toString
(
16
);
return
padLeft
(
value
,
padding
);
...
...
dist/ethereum.js.map
View file @
774e9d24
This diff is collapsed.
Click to expand it.
dist/ethereum.min.js
View file @
774e9d24
This diff is collapsed.
Click to expand it.
lib/abi.js
View file @
774e9d24
...
...
@@ -28,6 +28,8 @@ if (process.env.NODE_ENV !== 'build') {
var
web3
=
require
(
'./web3'
);
// jshint ignore:line
BigNumber
.
config
({
ROUNDING_MODE
:
BigNumber
.
ROUND_DOWN
});
// TODO: make these be actually accurate instead of falling back onto JS's doubles.
var
hexToDec
=
function
(
hex
)
{
return
parseInt
(
hex
,
16
).
toString
();
...
...
@@ -87,25 +89,23 @@ var setupInputTypes = function () {
/// Formats input value to byte representation of int
/// If value is negative, return it's two's complement
/// If the value is floating point, it rounds it down
/// @returns right-aligned byte representation of int
var
formatInt
=
function
(
value
)
{
var
padding
=
32
*
2
;
if
(
value
instanceof
BigNumber
)
{
if
(
value
instanceof
BigNumber
||
typeof
value
===
'number'
)
{
if
(
typeof
value
===
'number'
)
value
=
new
BigNumber
(
value
);
value
=
value
.
round
();
if
(
value
.
lessThan
(
0
))
value
=
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
).
plus
(
value
).
plus
(
1
).
toString
(
16
);
else
value
=
value
.
toString
(
16
);
}
else
if
(
typeof
value
===
'number'
)
{
if
(
value
<
0
)
value
=
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
).
plus
(
value
).
plus
(
1
).
toString
(
16
);
else
value
=
new
BigNumber
(
value
).
toString
(
16
);
value
=
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
).
plus
(
value
).
plus
(
1
);
value
=
value
.
toString
(
16
);
}
else
if
(
value
.
indexOf
(
'0x'
)
===
0
)
value
=
value
.
substr
(
2
);
else
if
(
typeof
value
===
'string'
)
value
=
new
BigNumber
(
value
).
toString
(
16
);
value
=
formatInt
(
new
BigNumber
(
value
));
else
value
=
(
+
value
).
toString
(
16
);
return
padLeft
(
value
,
padding
);
...
...
test/abi.parsers.js
View file @
774e9d24
...
...
@@ -43,6 +43,11 @@ describe('abi', function() {
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
'3.9'
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
});
...
...
@@ -69,6 +74,10 @@ describe('abi', function() {
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
'3.9'
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
});
...
...
@@ -95,6 +104,10 @@ describe('abi', function() {
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
'3.9'
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
});
...
...
@@ -124,6 +137,10 @@ describe('abi', function() {
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
'3.9'
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
});
it
(
'should parse input int128'
,
function
()
{
...
...
@@ -152,6 +169,10 @@ describe('abi', function() {
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
'3.9'
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
});
...
...
@@ -181,6 +202,10 @@ describe('abi', function() {
parser
.
test
(
new
BigNumber
(
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
,
16
)),
"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
);
assert
.
equal
(
parser
.
test
(
0.1
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
3.9
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
assert
.
equal
(
parser
.
test
(
'0.1'
),
"0000000000000000000000000000000000000000000000000000000000000000"
);
assert
.
equal
(
parser
.
test
(
'3.9'
),
"0000000000000000000000000000000000000000000000000000000000000003"
);
});
...
...
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