diff --git a/pkg/abi/abi.go b/pkg/abi/abi.go index 8e4dc6a2..6f68dd23 100644 --- a/pkg/abi/abi.go +++ b/pkg/abi/abi.go @@ -340,29 +340,35 @@ func (a ABI) ErrorString(revertData []byte) (string, bool) { return a.ErrorStringCtx(context.Background(), revertData) } -func (a ABI) ErrorStringCtx(ctx context.Context, revertData []byte) (string, bool) { - var parsed []interface{} +func (a ABI) ErrorStringCtx(ctx context.Context, revertData []byte) (strError string, ok bool) { e, cv, ok := a.ParseErrorCtx(ctx, revertData) if ok { - if res, err := NewSerializer().SetFormattingMode(FormatAsFlatArrays).SerializeInterfaceCtx(ctx, cv); err == nil { - parsed, ok = res.([]interface{}) - } + strError = FormatErrorStringCtx(ctx, e, cv) + ok = strError != "" } - if !ok || parsed == nil { - return "", false + return strError, ok +} + +func FormatErrorStringCtx(ctx context.Context, e *Entry, cv *ComponentValue) string { + var ok bool + var parsed []interface{} + if res, err := NewSerializer().SetFormattingMode(FormatAsFlatArrays).SerializeInterfaceCtx(ctx, cv); err == nil { + parsed, ok = res.([]interface{}) } - buff := new(bytes.Buffer) - buff.WriteString(e.Name) - buff.WriteRune('(') - for i, c := range parsed { - if i > 0 { - buff.WriteRune(',') + buff := new(strings.Builder) + if ok && parsed != nil { + buff.WriteString(e.Name) + buff.WriteRune('(') + for i, c := range parsed { + if i > 0 { + buff.WriteRune(',') + } + b, _ := json.Marshal(c) + buff.Write(b) } - b, _ := json.Marshal(c) - buff.Write(b) + buff.WriteRune(')') } - buff.WriteRune(')') - return buff.String(), true + return buff.String() } // Validate processes all the components of all the parameters in this ABI entry