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
2a1a531b
Commit
2a1a531b
authored
Jan 16, 2017
by
Péter Szilágyi
Committed by
GitHub
Jan 16, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3570 from fjl/hexutil-zero-fix
common/hexutil: fix EncodeBig, Big.MarshalJSON
parents
b5a100b8
51f6b6d3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
4 additions
and
13 deletions
+4
-13
hexutil.go
common/hexutil/hexutil.go
+1
-6
hexutil_test.go
common/hexutil/hexutil_test.go
+1
-0
json.go
common/hexutil/json.go
+2
-7
No files found.
common/hexutil/hexutil.go
View file @
2a1a531b
...
...
@@ -169,12 +169,7 @@ func EncodeBig(bigint *big.Int) string {
if
nbits
==
0
{
return
"0x0"
}
enc
:=
make
([]
byte
,
2
,
(
nbits
/
8
)
*
2
+
2
)
copy
(
enc
,
"0x"
)
for
i
:=
len
(
bigint
.
Bits
())
-
1
;
i
>=
0
;
i
--
{
enc
=
strconv
.
AppendUint
(
enc
,
uint64
(
bigint
.
Bits
()[
i
]),
16
)
}
return
string
(
enc
)
return
fmt
.
Sprintf
(
"0x%x"
,
bigint
)
}
func
has0xPrefix
(
input
string
)
bool
{
...
...
common/hexutil/hexutil_test.go
View file @
2a1a531b
...
...
@@ -46,6 +46,7 @@ var (
{
referenceBig
(
"1"
),
"0x1"
},
{
referenceBig
(
"ff"
),
"0xff"
},
{
referenceBig
(
"112233445566778899aabbccddeeff"
),
"0x112233445566778899aabbccddeeff"
},
{
referenceBig
(
"80a7f2c1bcc396c00"
),
"0x80a7f2c1bcc396c00"
},
}
encodeUint64Tests
=
[]
marshalTest
{
...
...
common/hexutil/json.go
View file @
2a1a531b
...
...
@@ -109,13 +109,8 @@ func (b *Big) MarshalJSON() ([]byte, error) {
if
nbits
==
0
{
return
jsonZero
,
nil
}
enc
:=
make
([]
byte
,
3
,
(
nbits
/
8
)
*
2
+
4
)
copy
(
enc
,
`"0x`
)
for
i
:=
len
(
bigint
.
Bits
())
-
1
;
i
>=
0
;
i
--
{
enc
=
strconv
.
AppendUint
(
enc
,
uint64
(
bigint
.
Bits
()[
i
]),
16
)
}
enc
=
append
(
enc
,
'"'
)
return
enc
,
nil
enc
:=
fmt
.
Sprintf
(
`"0x%x"`
,
bigint
)
return
[]
byte
(
enc
),
nil
}
// 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