From f9d396cf57d14bc17b93e45a088bb87a794420c8 Mon Sep 17 00:00:00 2001 From: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com> Date: Mon, 20 Nov 2023 17:09:11 +0800 Subject: [PATCH] feat: improve `hexutil.Decode` (#571) --- common/hexutil/hexutil.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/hexutil/hexutil.go b/common/hexutil/hexutil.go index d3201850a8..924f7d2513 100644 --- a/common/hexutil/hexutil.go +++ b/common/hexutil/hexutil.go @@ -64,6 +64,10 @@ func Decode(input string) ([]byte, error) { if !has0xPrefix(input) { return nil, ErrMissingPrefix } + // better compatible with odd size string + if len(input)%2 != 0 { + input = "0x0" + input[2:] + } b, err := hex.DecodeString(input[2:]) if err != nil { err = mapError(err)