common: improve IsHexAddress and add tests (#15551)

Also unexport isHex, hasHexPrefix because IsHexAddress is the only caller.

Fixes #15550
This commit is contained in:
Steven Roose
2017-12-04 19:34:15 +01:00
committed by Felix Lange
parent 1d06e41f04
commit afb8154eab
4 changed files with 65 additions and 28 deletions

View File

@ -150,13 +150,10 @@ 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 len(s) == 2+2*AddressLength && IsHex(s) {
return true
if hasHexPrefix(s) {
s = s[2:]
}
if len(s) == 2*AddressLength && IsHex("0x"+s) {
return true
}
return false
return len(s) == 2*AddressLength && isHex(s)
}
// Get the string representation of the underlying address