feat: improve hexutil.Decode (#571)

This commit is contained in:
HAOYUatHZ 2023-11-20 17:09:11 +08:00 committed by GitHub
parent 932d6e371c
commit f9d396cf57
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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)