Skip to content

Commit

Permalink
Allow formatting of string errors separately from matching
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Broadhurst <peter.broadhurst@kaleido.io>
  • Loading branch information
peterbroadhurst committed Oct 24, 2024
1 parent 1608ddc commit eafd71c
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions pkg/abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit eafd71c

Please sign in to comment.