File tree Expand file tree Collapse file tree 2 files changed +5
-7
lines changed Expand file tree Collapse file tree 2 files changed +5
-7
lines changed Original file line number Diff line number Diff line change @@ -43,10 +43,8 @@ func ToHexArray(b [][]byte) []string {
43
43
// FromHex returns the bytes represented by the hexadecimal string s.
44
44
// s may be prefixed with "0x".
45
45
func FromHex (s string ) []byte {
46
- if len (s ) > 1 {
47
- if s [0 :2 ] == "0x" || s [0 :2 ] == "0X" {
48
- s = s [2 :]
49
- }
46
+ if has0xPrefix (s ) {
47
+ s = s [2 :]
50
48
}
51
49
if len (s )% 2 == 1 {
52
50
s = "0" + s
@@ -65,8 +63,8 @@ func CopyBytes(b []byte) (copiedBytes []byte) {
65
63
return
66
64
}
67
65
68
- // hasHexPrefix validates str begins with '0x' or '0X'.
69
- func hasHexPrefix (str string ) bool {
66
+ // has0xPrefix validates str begins with '0x' or '0X'.
67
+ func has0xPrefix (str string ) bool {
70
68
return len (str ) >= 2 && str [0 ] == '0' && (str [1 ] == 'x' || str [1 ] == 'X' )
71
69
}
72
70
Original file line number Diff line number Diff line change @@ -193,7 +193,7 @@ func HexToAddress(s string) Address { return BytesToAddress(FromHex(s)) }
193
193
// IsHexAddress verifies whether a string can represent a valid hex-encoded
194
194
// Ethereum address or not.
195
195
func IsHexAddress (s string ) bool {
196
- if hasHexPrefix (s ) {
196
+ if has0xPrefix (s ) {
197
197
s = s [2 :]
198
198
}
199
199
return len (s ) == 2 * AddressLength && isHex (s )
You can’t perform that action at this time.
0 commit comments