diff --git a/CHANGELOG.md b/CHANGELOG.md index 28c1cde9..d69e0262 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Unreleased +### Changes +- ([\#93](https://github.com/forbole/juno/pull/93)) Decode IBC transfer data to JSON for `/ibc.core.channel.v1.MsgRecvPacket` message + + ## v4.1.0 ### Changes - ([\#74](https://github.com/forbole/juno/pull/74)) Applied `GetMissingHeights()` in `enqueueMissingBlocks()` & in `parse blocks missing` cmd diff --git a/cmd/start/cmd.go b/cmd/start/cmd.go index 2c0674a4..55ceca91 100644 --- a/cmd/start/cmd.go +++ b/cmd/start/cmd.go @@ -8,6 +8,7 @@ import ( "time" parsecmdtypes "github.com/forbole/juno/v4/cmd/parse/types" + "github.com/forbole/juno/v4/modules" "github.com/forbole/juno/v4/types/utils" "github.com/forbole/juno/v4/logging" @@ -16,7 +17,6 @@ import ( "github.com/go-co-op/gocron" - "github.com/forbole/juno/v4/modules" "github.com/forbole/juno/v4/parser" "github.com/forbole/juno/v4/types" diff --git a/modules/messages/message_handler.go b/modules/messages/message_handler.go index 784f5b40..f0699409 100644 --- a/modules/messages/message_handler.go +++ b/modules/messages/message_handler.go @@ -1,8 +1,11 @@ package messages import ( + "fmt" + "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" + channeltypes "github.com/cosmos/ibc-go/v3/modules/core/04-channel/types" "github.com/gogo/protobuf/proto" "github.com/forbole/juno/v4/database" @@ -27,6 +30,20 @@ func HandleMsg( return err } + // Handle MsgRecvPacket data object + if msgIBC, ok := msg.(*channeltypes.MsgRecvPacket); ok { + trimMessageString := TrimLastChar(string(bz)) + trimDataString := string(msgIBC.Packet.Data)[1:] + return db.SaveMessage(types.NewMessage( + tx.TxHash, + index, + proto.MessageName(msg), + fmt.Sprintf("%s,%s", trimMessageString, trimDataString), + addresses, + tx.Height, + )) + } + return db.SaveMessage(types.NewMessage( tx.TxHash, index, diff --git a/modules/messages/utils.go b/modules/messages/utils.go new file mode 100644 index 00000000..99d27ef4 --- /dev/null +++ b/modules/messages/utils.go @@ -0,0 +1,11 @@ +package messages + +import "unicode/utf8" + +func TrimLastChar(s string) string { + r, size := utf8.DecodeLastRuneInString(s) + if r == utf8.RuneError && (size == 0 || size == 1) { + size = 0 + } + return s[:len(s)-size] +} diff --git a/modules/module.go b/modules/module.go index 39c70ec8..2a29545e 100644 --- a/modules/module.go +++ b/modules/module.go @@ -7,11 +7,10 @@ import ( "github.com/cosmos/cosmos-sdk/x/authz" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/forbole/juno/v4/types" "github.com/go-co-op/gocron" tmctypes "github.com/tendermint/tendermint/rpc/core/types" tmtypes "github.com/tendermint/tendermint/types" - - "github.com/forbole/juno/v4/types" ) // Module represents a generic module without any particular handling of data diff --git a/parser/worker.go b/parser/worker.go index 54ac1c36..2e947b77 100644 --- a/parser/worker.go +++ b/parser/worker.go @@ -14,9 +14,8 @@ import ( "github.com/forbole/juno/v4/database" "github.com/forbole/juno/v4/types/config" - "github.com/forbole/juno/v4/modules" - sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/forbole/juno/v4/modules" tmctypes "github.com/tendermint/tendermint/rpc/core/types" tmtypes "github.com/tendermint/tendermint/types" diff --git a/types/cosmos.go b/types/cosmos.go index 975128f8..6aebc25f 100644 --- a/types/cosmos.go +++ b/types/cosmos.go @@ -4,10 +4,9 @@ import ( "fmt" "time" - tmctypes "github.com/tendermint/tendermint/rpc/core/types" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/tx" + tmctypes "github.com/tendermint/tendermint/rpc/core/types" ) // Validator contains the data of a single validator