aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorlmittmann <lmittmann@users.noreply.github.com>2019-08-22 17:45:07 +0800
committerFelix Lange <fjl@twurst.com>2019-08-22 17:45:07 +0800
commit1cd5bf080ea82caeef8bebb4f0e46a47ee647f55 (patch)
treec2afa9995829c42370fe31297487c6096e1bd909 /common
parent7c229941ac332557bf148918a3a1cff98354e2df (diff)
downloadgo-tangerine-1cd5bf080ea82caeef8bebb4f0e46a47ee647f55.tar
go-tangerine-1cd5bf080ea82caeef8bebb4f0e46a47ee647f55.tar.gz
go-tangerine-1cd5bf080ea82caeef8bebb4f0e46a47ee647f55.tar.bz2
go-tangerine-1cd5bf080ea82caeef8bebb4f0e46a47ee647f55.tar.lz
go-tangerine-1cd5bf080ea82caeef8bebb4f0e46a47ee647f55.tar.xz
go-tangerine-1cd5bf080ea82caeef8bebb4f0e46a47ee647f55.tar.zst
go-tangerine-1cd5bf080ea82caeef8bebb4f0e46a47ee647f55.zip
common: unify hex prefix check code (#19937)
Diffstat (limited to 'common')
-rw-r--r--common/bytes.go10
-rw-r--r--common/types.go2
2 files changed, 5 insertions, 7 deletions
diff --git a/common/bytes.go b/common/bytes.go
index c82e61624..910c97d3c 100644
--- a/common/bytes.go
+++ b/common/bytes.go
@@ -43,10 +43,8 @@ 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" {
- s = s[2:]
- }
+ 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
}
-// hasHexPrefix validates str begins with '0x' or '0X'.
-func hasHexPrefix(str string) bool {
+// has0xPrefix validates str begins with '0x' or '0X'.
+func has0xPrefix(str string) bool {
return len(str) >= 2 && str[0] == '0' && (str[1] == 'x' || str[1] == 'X')
}
diff --git a/common/types.go b/common/types.go
index 98c83edd4..5cba4e9f3 100644
--- a/common/types.go
+++ b/common/types.go
@@ -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 hasHexPrefix(s) {
+ if has0xPrefix(s) {
s = s[2:]
}
return len(s) == 2*AddressLength && isHex(s)