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
6a58db66
Commit
6a58db66
authored
Jan 19, 2015
by
Marek Kotewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
parsing real, ureal values on output
parent
af54832d
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
14 deletions
+85
-14
ethereum.js
dist/ethereum.js
+20
-4
ethereum.js.map
dist/ethereum.js.map
+2
-2
ethereum.min.js
dist/ethereum.min.js
+1
-1
abi.js
lib/abi.js
+20
-4
abi.parsers.js
test/abi.parsers.js
+42
-3
No files found.
dist/ethereum.js
View file @
6a58db66
...
@@ -194,13 +194,19 @@ var toAbiInput = function (json, methodName, params) {
...
@@ -194,13 +194,19 @@ var toAbiInput = function (json, methodName, params) {
return
bytes
;
return
bytes
;
};
};
/// Check if input value is negative
/// @param value is hex format
/// @returns true if it is negative, otherwise false
var
signedIsNegative
=
function
(
value
)
{
return
(
new
BigNumber
(
value
.
substr
(
0
,
1
),
16
).
toString
(
2
).
substr
(
0
,
1
))
===
'1'
;
};
/// Formats input right-aligned input bytes to int
/// Formats input right-aligned input bytes to int
/// @returns right-aligned input bytes formatted to int
/// @returns right-aligned input bytes formatted to int
var
formatOutputInt
=
function
(
value
)
{
var
formatOutputInt
=
function
(
value
)
{
// check if it's negative number
// check if it's negative number
// it it is, return two's complement
// it it is, return two's complement
var
firstBit
=
new
BigNumber
(
value
.
substr
(
0
,
1
),
16
).
toString
(
2
).
substr
(
0
,
1
);
if
(
signedIsNegative
(
value
))
{
if
(
firstBit
===
'1'
)
{
return
new
BigNumber
(
value
,
16
).
minus
(
new
BigNumber
(
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
,
16
)).
minus
(
1
);
return
new
BigNumber
(
value
,
16
).
minus
(
new
BigNumber
(
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
,
16
)).
minus
(
1
);
}
}
return
new
BigNumber
(
value
,
16
);
return
new
BigNumber
(
value
,
16
);
...
@@ -212,6 +218,16 @@ var formatOutputUInt = function (value) {
...
@@ -212,6 +218,16 @@ var formatOutputUInt = function (value) {
return
new
BigNumber
(
value
,
16
);
return
new
BigNumber
(
value
,
16
);
};
};
/// @returns input bytes formatted to real
var
formatOutputReal
=
function
(
value
)
{
return
formatOutputInt
(
value
).
dividedBy
(
new
BigNumber
(
2
).
pow
(
128
));
};
/// @returns input bytes formatted to ureal
var
formatOutputUReal
=
function
(
value
)
{
return
formatOutputUInt
(
value
).
dividedBy
(
new
BigNumber
(
2
).
pow
(
128
));
};
/// @returns right-aligned input bytes formatted to hex
/// @returns right-aligned input bytes formatted to hex
var
formatOutputHash
=
function
(
value
)
{
var
formatOutputHash
=
function
(
value
)
{
return
"0x"
+
value
;
return
"0x"
+
value
;
...
@@ -247,8 +263,8 @@ var setupOutputTypes = function () {
...
@@ -247,8 +263,8 @@ var setupOutputTypes = function () {
{
type
:
prefixedType
(
'int'
),
format
:
formatOutputInt
},
{
type
:
prefixedType
(
'int'
),
format
:
formatOutputInt
},
{
type
:
prefixedType
(
'hash'
),
format
:
formatOutputHash
},
{
type
:
prefixedType
(
'hash'
),
format
:
formatOutputHash
},
{
type
:
prefixedType
(
'string'
),
format
:
formatOutputString
},
{
type
:
prefixedType
(
'string'
),
format
:
formatOutputString
},
{
type
:
prefixedType
(
'real'
),
format
:
formatOutput
Int
},
{
type
:
prefixedType
(
'real'
),
format
:
formatOutput
Real
},
{
type
:
prefixedType
(
'ureal'
),
format
:
formatOutput
Int
},
{
type
:
prefixedType
(
'ureal'
),
format
:
formatOutput
UReal
},
{
type
:
namedType
(
'address'
),
format
:
formatOutputAddress
},
{
type
:
namedType
(
'address'
),
format
:
formatOutputAddress
},
{
type
:
namedType
(
'bool'
),
format
:
formatOutputBool
}
{
type
:
namedType
(
'bool'
),
format
:
formatOutputBool
}
];
];
...
...
dist/ethereum.js.map
View file @
6a58db66
This diff is collapsed.
Click to expand it.
dist/ethereum.min.js
View file @
6a58db66
This diff is collapsed.
Click to expand it.
lib/abi.js
View file @
6a58db66
...
@@ -193,13 +193,19 @@ var toAbiInput = function (json, methodName, params) {
...
@@ -193,13 +193,19 @@ var toAbiInput = function (json, methodName, params) {
return
bytes
;
return
bytes
;
};
};
/// Check if input value is negative
/// @param value is hex format
/// @returns true if it is negative, otherwise false
var
signedIsNegative
=
function
(
value
)
{
return
(
new
BigNumber
(
value
.
substr
(
0
,
1
),
16
).
toString
(
2
).
substr
(
0
,
1
))
===
'1'
;
};
/// Formats input right-aligned input bytes to int
/// Formats input right-aligned input bytes to int
/// @returns right-aligned input bytes formatted to int
/// @returns right-aligned input bytes formatted to int
var
formatOutputInt
=
function
(
value
)
{
var
formatOutputInt
=
function
(
value
)
{
// check if it's negative number
// check if it's negative number
// it it is, return two's complement
// it it is, return two's complement
var
firstBit
=
new
BigNumber
(
value
.
substr
(
0
,
1
),
16
).
toString
(
2
).
substr
(
0
,
1
);
if
(
signedIsNegative
(
value
))
{
if
(
firstBit
===
'1'
)
{
return
new
BigNumber
(
value
,
16
).
minus
(
new
BigNumber
(
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
,
16
)).
minus
(
1
);
return
new
BigNumber
(
value
,
16
).
minus
(
new
BigNumber
(
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
,
16
)).
minus
(
1
);
}
}
return
new
BigNumber
(
value
,
16
);
return
new
BigNumber
(
value
,
16
);
...
@@ -211,6 +217,16 @@ var formatOutputUInt = function (value) {
...
@@ -211,6 +217,16 @@ var formatOutputUInt = function (value) {
return
new
BigNumber
(
value
,
16
);
return
new
BigNumber
(
value
,
16
);
};
};
/// @returns input bytes formatted to real
var
formatOutputReal
=
function
(
value
)
{
return
formatOutputInt
(
value
).
dividedBy
(
new
BigNumber
(
2
).
pow
(
128
));
};
/// @returns input bytes formatted to ureal
var
formatOutputUReal
=
function
(
value
)
{
return
formatOutputUInt
(
value
).
dividedBy
(
new
BigNumber
(
2
).
pow
(
128
));
};
/// @returns right-aligned input bytes formatted to hex
/// @returns right-aligned input bytes formatted to hex
var
formatOutputHash
=
function
(
value
)
{
var
formatOutputHash
=
function
(
value
)
{
return
"0x"
+
value
;
return
"0x"
+
value
;
...
@@ -246,8 +262,8 @@ var setupOutputTypes = function () {
...
@@ -246,8 +262,8 @@ var setupOutputTypes = function () {
{
type
:
prefixedType
(
'int'
),
format
:
formatOutputInt
},
{
type
:
prefixedType
(
'int'
),
format
:
formatOutputInt
},
{
type
:
prefixedType
(
'hash'
),
format
:
formatOutputHash
},
{
type
:
prefixedType
(
'hash'
),
format
:
formatOutputHash
},
{
type
:
prefixedType
(
'string'
),
format
:
formatOutputString
},
{
type
:
prefixedType
(
'string'
),
format
:
formatOutputString
},
{
type
:
prefixedType
(
'real'
),
format
:
formatOutput
Int
},
{
type
:
prefixedType
(
'real'
),
format
:
formatOutput
Real
},
{
type
:
prefixedType
(
'ureal'
),
format
:
formatOutput
Int
},
{
type
:
prefixedType
(
'ureal'
),
format
:
formatOutput
UReal
},
{
type
:
namedType
(
'address'
),
format
:
formatOutputAddress
},
{
type
:
namedType
(
'address'
),
format
:
formatOutputAddress
},
{
type
:
namedType
(
'bool'
),
format
:
formatOutputBool
}
{
type
:
namedType
(
'bool'
),
format
:
formatOutputBool
}
];
];
...
...
test/abi.parsers.js
View file @
6a58db66
...
@@ -419,7 +419,6 @@ describe('abi', function() {
...
@@ -419,7 +419,6 @@ describe('abi', function() {
});
});
});
});
describe
(
'outputParser'
,
function
()
{
describe
(
'outputParser'
,
function
()
{
...
@@ -673,12 +672,52 @@ describe('abi', function() {
...
@@ -673,12 +672,52 @@ describe('abi', function() {
var
parser
=
abi
.
outputParser
(
d
);
var
parser
=
abi
.
outputParser
(
d
);
// then
// then
assert
.
equal
(
parser
.
test
(
"000000000000000000000000000000000000000000000000000000000000000001"
)[
0
],
true
);
assert
.
equal
(
parser
.
test
(
"0x0000000000000000000000000000000000000000000000000000000000000001"
)[
0
],
true
);
assert
.
equal
(
parser
.
test
(
"000000000000000000000000000000000000000000000000000000000000000000"
)[
0
],
false
);
assert
.
equal
(
parser
.
test
(
"0x0000000000000000000000000000000000000000000000000000000000000000"
)[
0
],
false
);
});
it
(
'should parse output real'
,
function
()
{
// given
var
d
=
clone
(
description
);
d
[
0
].
outputs
=
[
{
type
:
'real'
}
];
// when
var
parser
=
abi
.
outputParser
(
d
);
// then
assert
.
equal
(
parser
.
test
(
"0x0000000000000000000000000000000100000000000000000000000000000000"
)[
0
],
1
);
assert
.
equal
(
parser
.
test
(
"0x0000000000000000000000000000000220000000000000000000000000000000"
)[
0
],
2.125
);
assert
.
equal
(
parser
.
test
(
"0x0000000000000000000000000000000880000000000000000000000000000000"
)[
0
],
8.5
);
assert
.
equal
(
parser
.
test
(
"0xffffffffffffffffffffffffffffffff00000000000000000000000000000000"
)[
0
],
-
1
);
});
it
(
'should parse output ureal'
,
function
()
{
// given
var
d
=
clone
(
description
);
d
[
0
].
outputs
=
[
{
type
:
'ureal'
}
];
// when
var
parser
=
abi
.
outputParser
(
d
);
// then
assert
.
equal
(
parser
.
test
(
"0x0000000000000000000000000000000100000000000000000000000000000000"
)[
0
],
1
);
assert
.
equal
(
parser
.
test
(
"0x0000000000000000000000000000000220000000000000000000000000000000"
)[
0
],
2.125
);
assert
.
equal
(
parser
.
test
(
"0x0000000000000000000000000000000880000000000000000000000000000000"
)[
0
],
8.5
);
});
});
it
(
'should parse multiple output strings'
,
function
()
{
it
(
'should parse multiple output strings'
,
function
()
{
// given
// given
...
...
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