Skip to content

Commit

Permalink
Fix parseMsgEventLogs
Browse files Browse the repository at this point in the history
Signed-off-by: Dongri Jin <[email protected]>
  • Loading branch information
dongrie committed Feb 6, 2024
1 parent 33ec3a8 commit e9bf745
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 28 deletions.
10 changes: 2 additions & 8 deletions chains/tendermint/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,14 +447,8 @@ func (c *Chain) GetMsgResult(id core.MsgID) (core.MsgResult, error) {
}, nil
}

// parse the log into ABCI logs
abciLogs, err := sdk.ParseABCILogs(resTx.TxResult.Log)
if err != nil {
return nil, fmt.Errorf("failed to parse ABCI logs: %v", err)
}

// parse the ABCI logs into core.MsgEventLog's
events, err := parseMsgEventLogs(abciLogs, msgID.MsgIndex)
// parse the abci.types.Events into core.MsgEventLog's
events, err := parseMsgEventLogs(resTx.TxResult.Events, msgID.MsgIndex)
if err != nil {
return nil, fmt.Errorf("failed to parse msg event log: %v", err)
}
Expand Down
26 changes: 15 additions & 11 deletions chains/tendermint/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
abcitypes "github.com/cometbft/cometbft/abci/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
conntypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
chantypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
Expand All @@ -19,6 +19,10 @@ var (
_ core.MsgResult = (*MsgResult)(nil)
)

const (
MsgIndexAttributeKey = "msg_index"
)

func (*MsgID) Is_MsgID() {}

type MsgResult struct {
Expand All @@ -44,11 +48,11 @@ func (r *MsgResult) Events() []core.MsgEventLog {
return r.events
}

func parseMsgEventLogs(logs sdk.ABCIMessageLogs, msgIndex uint32) ([]core.MsgEventLog, error) {
func parseMsgEventLogs(events []abcitypes.Event, msgIndex uint32) ([]core.MsgEventLog, error) {
var msgEventLogs []core.MsgEventLog
for _, log := range logs {
if msgIndex == log.MsgIndex {
for _, ev := range log.Events {
for _, ev := range events {
for _, attr := range ev.Attributes {
if attr.Key == MsgIndexAttributeKey && attr.Value == strconv.FormatUint(uint64(msgIndex), 10) {
event, err := parseMsgEventLog(ev)
if err != nil {
return nil, fmt.Errorf("failed to parse msg event log: %v", err)
Expand All @@ -60,7 +64,7 @@ func parseMsgEventLogs(logs sdk.ABCIMessageLogs, msgIndex uint32) ([]core.MsgEve
return msgEventLogs, nil
}

func parseMsgEventLog(ev sdk.StringEvent) (core.MsgEventLog, error) {
func parseMsgEventLog(ev abcitypes.Event) (core.MsgEventLog, error) {
switch ev.Type {
case clienttypes.EventTypeCreateClient:
clientID, err := getAttributeString(ev, clienttypes.AttributeKeyClientID)
Expand Down Expand Up @@ -134,7 +138,7 @@ func parseMsgEventLog(ev sdk.StringEvent) (core.MsgEventLog, error) {
}
}

func getAttributeString(ev sdk.StringEvent, key string) (string, error) {
func getAttributeString(ev abcitypes.Event, key string) (string, error) {
for _, attr := range ev.Attributes {
if attr.Key == key {
return attr.Value, nil
Expand All @@ -143,7 +147,7 @@ func getAttributeString(ev sdk.StringEvent, key string) (string, error) {
return "", fmt.Errorf("failed to find attribute of key %q", key)
}

func getAttributeBytes(ev sdk.StringEvent, key string) ([]byte, error) {
func getAttributeBytes(ev abcitypes.Event, key string) ([]byte, error) {
v, err := getAttributeString(ev, key)
if err != nil {
return nil, err
Expand All @@ -155,7 +159,7 @@ func getAttributeBytes(ev sdk.StringEvent, key string) ([]byte, error) {
return bz, nil
}

func getAttributeHeight(ev sdk.StringEvent, key string) (clienttypes.Height, error) {
func getAttributeHeight(ev abcitypes.Event, key string) (clienttypes.Height, error) {
v, err := getAttributeString(ev, key)
if err != nil {
return clienttypes.Height{}, err
Expand All @@ -167,7 +171,7 @@ func getAttributeHeight(ev sdk.StringEvent, key string) (clienttypes.Height, err
return height, nil
}

func getAttributeUint64(ev sdk.StringEvent, key string) (uint64, error) {
func getAttributeUint64(ev abcitypes.Event, key string) (uint64, error) {
v, err := getAttributeString(ev, key)
if err != nil {
return 0, err
Expand All @@ -179,7 +183,7 @@ func getAttributeUint64(ev sdk.StringEvent, key string) (uint64, error) {
return d, nil
}

func getAttributeTimestamp(ev sdk.StringEvent, key string) (time.Time, error) {
func getAttributeTimestamp(ev abcitypes.Event, key string) (time.Time, error) {
d, err := getAttributeUint64(ev, key)
if err != nil {
return time.Time{}, err
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/cosmos/gogoproto v1.4.11
github.com/cosmos/ibc-go/modules/capability v1.0.0
github.com/cosmos/ibc-go/v8 v8.0.0
github.com/datachainlab/ibc-mock-client v0.3.2
github.com/datachainlab/ibc-mock-client v0.0.0-00010101000000-000000000000
github.com/prometheus/client_golang v1.17.0
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.16.0
Expand Down Expand Up @@ -197,6 +197,6 @@ replace (
// https://github.com/cosmos/cosmos-sdk/blob/v0.47.3/go.mod#L171-L182
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0

github.com/datachainlab/ibc-mock-client => github.com/dongrie/ibc-mock-client v0.3.3-0.20240202034046-2286f47fe7a8
github.com/datachainlab/ibc-mock-client => github.com/dongrie/ibc-mock-client v0.3.3-0.20240202040041-f4bae04fc249
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,6 @@ github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7Do
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/danieljoos/wincred v1.1.2 h1:QLdCxFs1/Yl4zduvBdcHB8goaYk9RARS2SgLLRuAyr0=
github.com/danieljoos/wincred v1.1.2/go.mod h1:GijpziifJoIBfYh+S7BbkdUTU4LfM+QnGqR5Vl2tAx0=
github.com/datachainlab/ibc-mock-client v0.3.3 h1:jZQvvd88g/6Jq8LULaqeYviOSQYqWhgsUMYMtUzosiA=
github.com/datachainlab/ibc-mock-client v0.3.3/go.mod h1:FfqyF+VJKp8jlIG21lTNJJIp8RCaxSrx6vjhNkfwgBM=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -403,8 +401,8 @@ github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKoh
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dongrie/ibc-mock-client v0.3.3-0.20240202034046-2286f47fe7a8 h1:RLXUuvh/PJi0/THnVn/sTHH//jn2KYTAi8hCRCvodSw=
github.com/dongrie/ibc-mock-client v0.3.3-0.20240202034046-2286f47fe7a8/go.mod h1:+WXl7RLwjigJvsqxabHCqSp+qxBjTwkNV9KPHJndGhA=
github.com/dongrie/ibc-mock-client v0.3.3-0.20240202040041-f4bae04fc249 h1:qg7RzypiD3lDXlGXzjEzh8RSTmeYDAmLoquzoP/CRdI=
github.com/dongrie/ibc-mock-client v0.3.3-0.20240202040041-f4bae04fc249/go.mod h1:+WXl7RLwjigJvsqxabHCqSp+qxBjTwkNV9KPHJndGhA=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
Expand Down
2 changes: 1 addition & 1 deletion tests/chains/tendermint/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,6 @@ replace (
// https://github.com/cosmos/cosmos-sdk/blob/v0.47.3/go.mod#L171-L182
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0

github.com/datachainlab/ibc-mock-client => github.com/dongrie/ibc-mock-client v0.3.3-0.20240202034046-2286f47fe7a8
github.com/datachainlab/ibc-mock-client => github.com/dongrie/ibc-mock-client v0.3.3-0.20240202040041-f4bae04fc249
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
)
4 changes: 2 additions & 2 deletions tests/chains/tendermint/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKoh
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dongrie/ibc-mock-client v0.3.3-0.20240202034046-2286f47fe7a8 h1:RLXUuvh/PJi0/THnVn/sTHH//jn2KYTAi8hCRCvodSw=
github.com/dongrie/ibc-mock-client v0.3.3-0.20240202034046-2286f47fe7a8/go.mod h1:+WXl7RLwjigJvsqxabHCqSp+qxBjTwkNV9KPHJndGhA=
github.com/dongrie/ibc-mock-client v0.3.3-0.20240202040041-f4bae04fc249 h1:qg7RzypiD3lDXlGXzjEzh8RSTmeYDAmLoquzoP/CRdI=
github.com/dongrie/ibc-mock-client v0.3.3-0.20240202040041-f4bae04fc249/go.mod h1:+WXl7RLwjigJvsqxabHCqSp+qxBjTwkNV9KPHJndGhA=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
Expand Down

0 comments on commit e9bf745

Please sign in to comment.