mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 05:06:43 +00:00
revert changes for has0xprefix func
This commit is contained in:
parent
a1d860e0ef
commit
5061a08452
3 changed files with 8 additions and 4 deletions
|
|
@ -20,7 +20,6 @@ package common
|
|||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
)
|
||||
|
|
@ -28,7 +27,7 @@ import (
|
|||
// FromHex returns the bytes represented by the hexadecimal string s.
|
||||
// s may be prefixed with "0x".
|
||||
func FromHex(s string) []byte {
|
||||
if len(s) >= 2 && strings.HasPrefix(strings.ToLower(s), "0x") {
|
||||
if has0xPrefix(s) {
|
||||
s = s[2:]
|
||||
}
|
||||
if len(s)&1 == 1 {
|
||||
|
|
@ -37,6 +36,11 @@ func FromHex(s string) []byte {
|
|||
return Hex2Bytes(s)
|
||||
}
|
||||
|
||||
// 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')
|
||||
}
|
||||
|
||||
// CopyBytes returns an exact copy of the provided bytes.
|
||||
func CopyBytes(b []byte) (copiedBytes []byte) {
|
||||
if b == nil {
|
||||
|
|
|
|||
|
|
@ -231,7 +231,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 len(s) >= 2 && strings.HasPrefix(strings.ToLower(s), "0x") {
|
||||
if has0xPrefix(s) {
|
||||
s = s[2:]
|
||||
}
|
||||
return len(s) == 2*AddressLength && isHex(s)
|
||||
|
|
|
|||
|
|
@ -215,4 +215,4 @@ func fakeExponential(factor, numerator, denominator *big.Int) *big.Int {
|
|||
accum.Div(accum, big.NewInt(int64(i)))
|
||||
}
|
||||
return output.Div(output, denominator)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue