From afb8154eab2961996b321ac3fe5a21602e3b1aff Mon Sep 17 00:00:00 2001 From: Steven Roose Date: Mon, 4 Dec 2017 19:34:15 +0100 Subject: common: improve IsHexAddress and add tests (#15551) Also unexport isHex, hasHexPrefix because IsHexAddress is the only caller. Fixes #15550 --- common/types.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'common/types.go') 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 -- cgit v1.2.3