From 10532f6719d242db2989a99ff518aca2d11e2715 Mon Sep 17 00:00:00 2001 From: AleksaOpacic Date: Sat, 16 Jul 2022 13:11:26 +0200 Subject: [PATCH] Use trimPrefix --- helper/hex/hex.go | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/helper/hex/hex.go b/helper/hex/hex.go index c908150969..316a7be156 100644 --- a/helper/hex/hex.go +++ b/helper/hex/hex.go @@ -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) @@ -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