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
280f08be
Commit
280f08be
authored
Feb 26, 2017
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common/hexutil: ensure negative big.Int is encoded sensibly
Restricting encoding is silly.
parent
d304da38
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
5 additions
and
16 deletions
+5
-16
hexutil.go
common/hexutil/hexutil.go
+1
-1
hexutil_test.go
common/hexutil/hexutil_test.go
+1
-0
json.go
common/hexutil/json.go
+3
-15
No files found.
common/hexutil/hexutil.go
View file @
280f08be
...
@@ -178,7 +178,7 @@ func EncodeBig(bigint *big.Int) string {
...
@@ -178,7 +178,7 @@ func EncodeBig(bigint *big.Int) string {
if
nbits
==
0
{
if
nbits
==
0
{
return
"0x0"
return
"0x0"
}
}
return
fmt
.
Sprintf
(
"
0x%
x"
,
bigint
)
return
fmt
.
Sprintf
(
"
%#
x"
,
bigint
)
}
}
func
has0xPrefix
(
input
string
)
bool
{
func
has0xPrefix
(
input
string
)
bool
{
...
...
common/hexutil/hexutil_test.go
View file @
280f08be
...
@@ -47,6 +47,7 @@ var (
...
@@ -47,6 +47,7 @@ var (
{
referenceBig
(
"ff"
),
"0xff"
},
{
referenceBig
(
"ff"
),
"0xff"
},
{
referenceBig
(
"112233445566778899aabbccddeeff"
),
"0x112233445566778899aabbccddeeff"
},
{
referenceBig
(
"112233445566778899aabbccddeeff"
),
"0x112233445566778899aabbccddeeff"
},
{
referenceBig
(
"80a7f2c1bcc396c00"
),
"0x80a7f2c1bcc396c00"
},
{
referenceBig
(
"80a7f2c1bcc396c00"
),
"0x80a7f2c1bcc396c00"
},
{
referenceBig
(
"-80a7f2c1bcc396c00"
),
"-0x80a7f2c1bcc396c00"
},
}
}
encodeUint64Tests
=
[]
marshalTest
{
encodeUint64Tests
=
[]
marshalTest
{
...
...
common/hexutil/json.go
View file @
280f08be
...
@@ -27,7 +27,6 @@ import (
...
@@ -27,7 +27,6 @@ import (
var
(
var
(
textZero
=
[]
byte
(
`0x0`
)
textZero
=
[]
byte
(
`0x0`
)
errNonString
=
errors
.
New
(
"cannot unmarshal non-string as hex data"
)
errNonString
=
errors
.
New
(
"cannot unmarshal non-string as hex data"
)
errNegativeBigInt
=
errors
.
New
(
"hexutil.Big: can't marshal negative integer"
)
)
)
// Bytes marshals/unmarshals as a JSON string with 0x prefix.
// Bytes marshals/unmarshals as a JSON string with 0x prefix.
...
@@ -101,18 +100,7 @@ type Big big.Int
...
@@ -101,18 +100,7 @@ type Big big.Int
// MarshalText implements encoding.TextMarshaler
// MarshalText implements encoding.TextMarshaler
func
(
b
Big
)
MarshalText
()
([]
byte
,
error
)
{
func
(
b
Big
)
MarshalText
()
([]
byte
,
error
)
{
bigint
:=
(
big
.
Int
)(
b
)
return
[]
byte
(
EncodeBig
((
*
big
.
Int
)(
&
b
))),
nil
if
bigint
.
Sign
()
==
-
1
{
return
nil
,
errNegativeBigInt
}
nbits
:=
bigint
.
BitLen
()
if
nbits
==
0
{
return
textZero
,
nil
}
enc
:=
make
([]
byte
,
2
,
nbits
/
4
+
2
)
copy
(
enc
,
"0x"
)
enc
=
bigint
.
Append
(
enc
,
16
)
return
enc
,
nil
}
}
// UnmarshalJSON implements json.Unmarshaler.
// UnmarshalJSON implements json.Unmarshaler.
...
...
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