Skip to content

Commit

Permalink
Parse events of all the messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojtek committed Nov 20, 2023
1 parent 3ede61f commit 1f9541c
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 127 deletions.
35 changes: 13 additions & 22 deletions utils/addresses.go → modules/addresses/handle_msg.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,33 @@
package utils
package addresses

import (
"strings"

tmtypes "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/forbole/bdjuno/v4/database"
junomessages "github.com/forbole/juno/v5/modules/messages"
"github.com/cosmos/gogoproto/proto"
juno "github.com/forbole/juno/v5/types"
"github.com/gogo/protobuf/proto"
"github.com/samber/lo"
)

// HandleMessageWithAddresses handle messages and takes addresses from events.
func HandleMessageWithAddresses(
index int,
msg sdk.Msg,
tx *juno.Tx,
messageParser junomessages.MessageAddressesParser,
cdc codec.Codec, db *database.Db,
) error {
addresses, err := collectAddresses(cdc, messageParser, msg, tx)
// HandleMsg implements MessageModule
func (m *Module) HandleMsg(index int, msg sdk.Msg, tx *juno.Tx) error {
if len(tx.Events) == 0 {
return nil
}

addresses, err := m.collectAddresses(msg, tx)
if err != nil {
return err
}

// marshal the value properly
bz, err := cdc.MarshalJSON(msg)
bz, err := m.cdc.MarshalJSON(msg)
if err != nil {
return err
}

return db.SaveMessage(juno.NewMessage(
return m.db.SaveMessage(juno.NewMessage(
tx.TxHash,
index,
proto.MessageName(msg),
Expand All @@ -42,13 +37,9 @@ func HandleMessageWithAddresses(
))
}

func collectAddresses(
cdc codec.Codec,
messageParser junomessages.MessageAddressesParser,
msg sdk.Msg, tx *juno.Tx,
) ([]string, error) {
func (m *Module) collectAddresses(msg sdk.Msg, tx *juno.Tx) ([]string, error) {
// get the involved addresses with general parser first
messageAddresses, err := messageParser(cdc, msg)
messageAddresses, err := m.messageParser(m.cdc, msg)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions modules/group/module.go → modules/addresses/module.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package group
package addresses

import (
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -33,5 +33,5 @@ func NewModule(

// Name implements modules.Module
func (m *Module) Name() string {
return "group"
return "addresses"
}
35 changes: 0 additions & 35 deletions modules/group/handle_msg.go

This file was deleted.

8 changes: 3 additions & 5 deletions modules/registrar.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package modules

import (
"github.com/forbole/bdjuno/v4/modules/actions"
"github.com/forbole/bdjuno/v4/modules/group"
"github.com/forbole/bdjuno/v4/modules/addresses"
"github.com/forbole/bdjuno/v4/modules/types"

"github.com/forbole/juno/v5/modules/pruning"
Expand Down Expand Up @@ -35,7 +35,6 @@ import (
"github.com/forbole/bdjuno/v4/modules/pricefeed"
"github.com/forbole/bdjuno/v4/modules/staking"
"github.com/forbole/bdjuno/v4/modules/upgrade"
"github.com/forbole/bdjuno/v4/modules/wasm"
)

// UniqueAddressesParser returns a wrapper around the given parser that removes all duplicated addresses
Expand Down Expand Up @@ -92,7 +91,6 @@ func (r *Registrar) BuildModules(ctx registrar.Context) jmodules.Modules {
customParamsModule := customparams.NewModule(sources.CustomParamsSource, cdc, db)
assetFTModule := assetft.NewModule(sources.AssetFTSource, cdc, db)
assetNFTModule := assetnft.NewModule(sources.AssetNFTSource, cdc, db)
wasmModule := wasm.NewModule(r.parser, cdc, db)
govModule := gov.NewModule(
sources.GovSource,
distrModule,
Expand Down Expand Up @@ -126,12 +124,12 @@ func (r *Registrar) BuildModules(ctx registrar.Context) jmodules.Modules {
pricefeed.NewModule(ctx.JunoConfig, cdc, db),
slashingModule,
stakingModule,
group.NewModule(r.parser, cdc, db),
upgradeModule,
feeModelModule,
customParamsModule,
assetFTModule,
assetNFTModule,
wasmModule,
// This must be the last item.
addresses.NewModule(r.parser, cdc, db),
}
}
25 changes: 0 additions & 25 deletions modules/wasm/handle_msg.go

This file was deleted.

38 changes: 0 additions & 38 deletions modules/wasm/module.go

This file was deleted.

0 comments on commit 1f9541c

Please sign in to comment.