Skip to content

Commit

Permalink
refactor: Update HexToBytes function
Browse files Browse the repository at this point in the history
  • Loading branch information
duanyytop committed May 30, 2024
1 parent 2cf14e0 commit 64b719c
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil"
)

// HexToBytes decodes a hex string with 0x prefix to byte array.
// HexToBytes decodes a hexadecimal string to byte array.
func HexToBytes(h string) []byte {
if strings.Contains(h, "0x") {
data, err := hexutil.Decode(h)
if err != nil {
panic(err)
}
return data
var str = h
if !strings.Contains(h, "0x") {
str = fmt.Sprintf("0x%s", h)
}
data, err := hexutil.Decode(fmt.Sprintf("0x%s", h))
data, err := hexutil.Decode(str)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 64b719c

Please sign in to comment.