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
1cd5bf08
Commit
1cd5bf08
authored
Aug 22, 2019
by
lmittmann
Committed by
Felix Lange
Aug 22, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common: unify hex prefix check code (#19937)
parent
7c229941
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
7 deletions
+5
-7
bytes.go
common/bytes.go
+4
-6
types.go
common/types.go
+1
-1
No files found.
common/bytes.go
View file @
1cd5bf08
...
...
@@ -43,11 +43,9 @@ func ToHexArray(b [][]byte) []string {
// FromHex returns the bytes represented by the hexadecimal string s.
// s may be prefixed with "0x".
func
FromHex
(
s
string
)
[]
byte
{
if
len
(
s
)
>
1
{
if
s
[
0
:
2
]
==
"0x"
||
s
[
0
:
2
]
==
"0X"
{
if
has0xPrefix
(
s
)
{
s
=
s
[
2
:
]
}
}
if
len
(
s
)
%
2
==
1
{
s
=
"0"
+
s
}
...
...
@@ -65,8 +63,8 @@ func CopyBytes(b []byte) (copiedBytes []byte) {
return
}
// has
He
xPrefix validates str begins with '0x' or '0X'.
func
has
He
xPrefix
(
str
string
)
bool
{
// has
0
xPrefix validates str begins with '0x' or '0X'.
func
has
0
xPrefix
(
str
string
)
bool
{
return
len
(
str
)
>=
2
&&
str
[
0
]
==
'0'
&&
(
str
[
1
]
==
'x'
||
str
[
1
]
==
'X'
)
}
...
...
common/types.go
View file @
1cd5bf08
...
...
@@ -193,7 +193,7 @@ func HexToAddress(s string) Address { return BytesToAddress(FromHex(s)) }
// IsHexAddress verifies whether a string can represent a valid hex-encoded
// Ethereum address or not.
func
IsHexAddress
(
s
string
)
bool
{
if
has
He
xPrefix
(
s
)
{
if
has
0
xPrefix
(
s
)
{
s
=
s
[
2
:
]
}
return
len
(
s
)
==
2
*
AddressLength
&&
isHex
(
s
)
...
...
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