diff options
author | Steven Roose <stevenroose@gmail.com> | 2017-12-05 02:34:15 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-12-05 02:34:15 +0800 |
commit | afb8154eab2961996b321ac3fe5a21602e3b1aff (patch) | |
tree | 13011886b99de7a66e8d916882d731e12afbb2b1 /common/types.go | |
parent | 1d06e41f04d75c31334c455063e9ec7b4136bf23 (diff) | |
download | dexon-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar dexon-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar.gz dexon-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar.bz2 dexon-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar.lz dexon-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar.xz dexon-afb8154eab2961996b321ac3fe5a21602e3b1aff.tar.zst dexon-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.go | 9 |
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 |