Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Commit

Permalink
Use trimPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAleksaOpacic committed Jul 16, 2022
1 parent ff727c4 commit 204fec5
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions helper/hex/hex.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func EncodeUint64(i uint64) string {
// DecodeUint64 decodes a hex string with 0x prefix to uint64
func DecodeUint64(hexStr string) (uint64, error) {
// remove 0x suffix if found in the input string
cleaned := strings.Replace(hexStr, "0x", "", -1)
cleaned := strings.TrimPrefix(hexStr, "0x")

// base 16 for hexadecimal
result, err := strconv.ParseUint(cleaned, 16, 64)
Expand All @@ -69,16 +69,12 @@ func DecodeUint64(hexStr string) (uint64, error) {
// MustDecodeUint64 decodes a hex string with 0x prefix to uint64
// Returns panic if there is an error
func MustDecodeUint64(hexStr string) uint64 {
// remove 0x suffix if found in the input string
cleaned := strings.Replace(hexStr, "0x", "", -1)

// base 16 for hexadecimal
result, err := strconv.ParseUint(cleaned, 16, 64)
decodedValue, err := DecodeUint64(hexStr)
if err != nil {
panic(fmt.Errorf("could not decode hex: %w", err))
}

return result
return decodedValue
}

const BadNibble = ^uint64(0)
Expand Down

0 comments on commit 204fec5

Please sign in to comment.