Skip to content

Commit

Permalink
feat: decode IBC transfer data object to JSON for MsgRecvPacket (#93)
Browse files Browse the repository at this point in the history
<!-- < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < ☺
v                               ✰  Thanks for creating a PR! ✰    
v    Before smashing the submit button please review the checkboxes.
v If a checkbox is n/a - please still include it but + a little note why
☺ > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >  -->

## Description
<!-- Small description -->
Fixes
[BDU-894](https://forbole.atlassian.net/jira/software/c/projects/BDU/issues/BDU-894)
and
[BDU-446](https://forbole.atlassian.net/jira/software/c/projects/BDU/issues/BDU-446)

Changes:
- Decode transfer `data` object to JSON, append it to the message and
store it inside `message` table for `/ibc.core.channel.v1.MsgRecvPacket`

## Checklist
- [x] Targeted PR against correct branch.
- [x] Linked to Github issue with discussion and accepted design OR link
to spec that describes this work.
- [ ] Wrote unit tests.  
- [x] Re-reviewed `Files changed` in the Github PR explorer.


[BDU-894]:
https://forbole.atlassian.net/browse/BDU-894?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[BDU-446]:
https://forbole.atlassian.net/browse/BDU-446?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

---------

Co-authored-by: Riccardo Montagnin <riccardo.montagnin@gmail.com>
Co-authored-by: Mai Quang Hiep <maiquanghiepdl@gmail.com>
  • Loading branch information
3 people committed Jan 3, 2024
1 parent c073725 commit a80f422
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/start/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand Down
17 changes: 17 additions & 0 deletions modules/messages/message_handler.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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,
Expand Down
11 changes: 11 additions & 0 deletions modules/messages/utils.go
Original file line number Diff line number Diff line change
@@ -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]
}
3 changes: 1 addition & 2 deletions modules/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions parser/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 1 addition & 2 deletions types/cosmos.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a80f422

Please sign in to comment.