Skip to content

Commit

Permalink
Fix: detection of error
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Nov 20, 2024
1 parent c93a48c commit cb97b5a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
12 changes: 1 addition & 11 deletions pkg/indexer/parser/parseEvents.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/celenium-io/astria-indexer/pkg/indexer/decode"
"github.com/celenium-io/astria-indexer/pkg/node"
"github.com/celenium-io/astria-indexer/pkg/types"
"github.com/goccy/go-json"
"github.com/pkg/errors"
"github.com/shopspring/decimal"
"google.golang.org/protobuf/proto"
Expand Down Expand Up @@ -159,20 +158,11 @@ func parseTxDeposit(attrs []types.EventAttribute, height types.Level, decodeCtx
return nil
}

type packetAck struct {
Error string `json:"error,omitempty"`
Result string `json:"result,omitempty"`
}

func parseWriteAck(attrs []types.EventAttribute, decodeCtx *decode.Context) error {
for i := range attrs {
switch attrs[i].Key {
case "packet_ack":
var e packetAck
if err := json.Unmarshal([]byte(attrs[i].Value), &e); err != nil {
return err
}
decodeCtx.HasWriteAckError = len(e.Error) > 0
decodeCtx.HasWriteAckError = strings.Contains(attrs[i].Value, "error")
default:
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/indexer/parser/parseEvents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func Test_parseWriteAck(t *testing.T) {
attrs := []types.EventAttribute{
{
Key: "packet_ack",
Value: `{"error":"{\"0\": \"failed to execute ics20 transfer to bridge account\", \"1\": \"failed to parse memo as Ics20TransferDepositMemo\", \"2\": \"EOF while parsing a value at line 1 column 0\"}"}`,
Value: `{\"error\":\"{\"0\": \"failed to execute ics20 transfer to bridge account\", \"1\": \"failed to parse memo as Ics20TransferDepositMemo\", \"2\": \"EOF while parsing a value at line 1 column 0\"}\"}`,
}, {
Key: "packet_data",
Value: `{"amount":"100000","denom":"uusdc","receiver":"astriacompat13vptdafyttpmlwppt0s844efey2cpc0mw6dhm2","sender":"noble1rmhdkl3aaw95zdecnj5paaqcjavm8sylftznrs"}`,
Expand All @@ -121,7 +121,7 @@ func Test_parseWriteAck(t *testing.T) {
attrs := []types.EventAttribute{
{
Key: "packet_ack",
Value: `{"result":"AQ=="}`,
Value: `{\"result\":\"AQ==\"}`,
}, {
Key: "packet_data",
Value: `{"amount":"100000","denom":"uusdc","receiver":"astriacompat13vptdafyttpmlwppt0s844efey2cpc0mw6dhm2","sender":"noble1rmhdkl3aaw95zdecnj5paaqcjavm8sylftznrs"}`,
Expand Down

0 comments on commit cb97b5a

Please sign in to comment.