aboutsummaryrefslogtreecommitdiffstats
path: root/common/types.go
diff options
context:
space:
mode:
authorSteven Roose <stevenroose@gmail.com>2017-12-05 02:34:15 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-12-05 02:34:15 +0800
commitafb8154eab2961996b321ac3fe5a21602e3b1aff (patch)
tree13011886b99de7a66e8d916882d731e12afbb2b1 /common/types.go
parent1d06e41f04d75c31334c455063e9ec7b4136bf23 (diff)
downloadgo-tangerine-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar
go-tangerine-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar.gz
go-tangerine-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar.bz2
go-tangerine-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar.lz
go-tangerine-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar.xz
go-tangerine-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar.zst
go-tangerine-afb8154eab2961996b321ac3fe5a21602e3b1aff.zip
common: improve IsHexAddress and add tests (#15551)
Also unexport isHex, hasHexPrefix because IsHexAddress is the only caller. Fixes #15550
Diffstat (limited to 'common/types.go')
-rw-r--r--common/types.go9
1 files changed, 3 insertions, 6 deletions
diff --git a/common/types.go b/common/types.go
index d31bbf741..fdc67480c 100644
--- a/common/types.go
+++ b/common/types.go
@@ -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