Skip to content

Commit

Permalink
Fix msgIndexOf func
Browse files Browse the repository at this point in the history
Signed-off-by: Dongri Jin <[email protected]>
  • Loading branch information
dongrie committed Mar 21, 2024
1 parent b7dcf27 commit 68732a2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions chains/tendermint/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ func (r *MsgResult) Events() []core.MsgEventLog {
func parseMsgEventLogs(events []abcitypes.Event, msgIndex uint32) ([]core.MsgEventLog, error) {
var msgEventLogs []core.MsgEventLog
for _, ev := range events {
if msgIndexOf(ev) == strconv.FormatUint(uint64(msgIndex), 10) {
index, err := msgIndexOf(ev)
if err == nil && index == msgIndex {
event, err := parseMsgEventLog(ev)
if err != nil {
return nil, fmt.Errorf("failed to parse msg event log: %v", err)
Expand All @@ -62,13 +63,17 @@ func parseMsgEventLogs(events []abcitypes.Event, msgIndex uint32) ([]core.MsgEve
return msgEventLogs, nil
}

func msgIndexOf(event abcitypes.Event) string {
func msgIndexOf(event abcitypes.Event) (uint32, error) {
for _, attr := range event.Attributes {
if attr.Key == MsgIndexAttributeKey {
return attr.Value
intValue, err := strconv.ParseUint(attr.Value, 10, 32)
if err != nil {
return 0, fmt.Errorf("failed to parse value: %v", err)
}
return uint32(intValue), nil
}
}
return ""
return 0, fmt.Errorf("failed to find attribute of key %q", MsgIndexAttributeKey)
}

func parseMsgEventLog(ev abcitypes.Event) (core.MsgEventLog, error) {
Expand Down

0 comments on commit 68732a2

Please sign in to comment.