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 10532f6
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 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 @@ -66,21 +66,6 @@ func DecodeUint64(hexStr string) (uint64, error) {
return result, nil
}

// 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)
if err != nil {
panic(fmt.Errorf("could not decode hex: %w", err))
}

return result
}

const BadNibble = ^uint64(0)

// DecodeNibble decodes a byte into a uint64
Expand Down

0 comments on commit 10532f6

Please sign in to comment.