mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
refactor: Removed IsValidHexString and make has0xPrefix as public as per review comment
This commit is contained in:
parent
46a301a528
commit
631be3cc04
2 changed files with 4 additions and 28 deletions
|
|
@ -60,7 +60,7 @@ func Decode(input string) ([]byte, error) {
|
|||
if len(input) == 0 {
|
||||
return nil, ErrEmptyString
|
||||
}
|
||||
if !has0xPrefix(input) {
|
||||
if !Has0xPrefix(input) {
|
||||
return nil, ErrMissingPrefix
|
||||
}
|
||||
b, err := hex.DecodeString(input[2:])
|
||||
|
|
@ -185,31 +185,7 @@ func EncodeBig(bigint *big.Int) string {
|
|||
}
|
||||
}
|
||||
|
||||
func IsValidHexString(input string) bool {
|
||||
if !has0xPrefix(input) {
|
||||
return false
|
||||
}
|
||||
|
||||
hexPart := input[2:]
|
||||
if len(hexPart) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, c := range hexPart {
|
||||
if !isHexChar(c) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func isHexChar(c rune) bool {
|
||||
return ('0' <= c && c <= '9') ||
|
||||
('a' <= c && c <= 'f') ||
|
||||
('A' <= c && c <= 'F')
|
||||
}
|
||||
|
||||
func has0xPrefix(input string) bool {
|
||||
func Has0xPrefix(input string) bool {
|
||||
return len(input) >= 2 && input[0] == '0' && (input[1] == 'x' || input[1] == 'X')
|
||||
}
|
||||
|
||||
|
|
@ -217,7 +193,7 @@ func checkNumber(input string) (raw string, err error) {
|
|||
if len(input) == 0 {
|
||||
return "", ErrEmptyString
|
||||
}
|
||||
if !has0xPrefix(input) {
|
||||
if !Has0xPrefix(input) {
|
||||
return "", ErrMissingPrefix
|
||||
}
|
||||
input = input[2:]
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
|
|||
var err error
|
||||
|
||||
//Check if input is valid hex string before converting.
|
||||
if hexutil.IsValidHexString(input) {
|
||||
if hexutil.Has0xPrefix(input) {
|
||||
blckNum, err = hexutil.DecodeUint64(input)
|
||||
} else {
|
||||
//Else try converting input directly into uint64 value
|
||||
|
|
|
|||
Loading…
Reference in a new issue