Skip to content

Commit

Permalink
fix(app): use the sdk-utils EmitTypeEvent function that doesn't add d…
Browse files Browse the repository at this point in the history
…ouble quotes to string attributes (#1123)
  • Loading branch information
zale144 authored Aug 23, 2024
1 parent f745bfc commit 95c7b5f
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 24 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
github.com/decred/dcrd/dcrec/edwards v1.0.0
github.com/dustin/go-humanize v1.0.1
github.com/dymensionxyz/gerr-cosmos v1.0.0
github.com/dymensionxyz/sdk-utils v0.2.7
github.com/dymensionxyz/sdk-utils v0.2.8-0.20240823083607-ea6d7a482d69
github.com/ethereum/go-ethereum v1.10.26
github.com/evmos/ethermint v0.22.0
github.com/gogo/protobuf v1.3.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,8 @@ github.com/dymensionxyz/osmosis/osmomath v0.0.6-dymension-v0.1.0.20240820121212-
github.com/dymensionxyz/osmosis/osmomath v0.0.6-dymension-v0.1.0.20240820121212-c0e21fa21e43/go.mod h1:SdGCL9CZb14twRAJUSzb7bRE0OoopRpF2Hnd1UhJpFU=
github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20240820121212-c0e21fa21e43 h1:ugbpHwwlckB4W/aNXUTEsxaakPFgXi+LAsCtvfJ200Q=
github.com/dymensionxyz/osmosis/v15 v15.2.1-0.20240820121212-c0e21fa21e43/go.mod h1:2rsnXAdjYfXtyEw0mNwAdOiAccALYjAPvINGUf9Qg7Y=
github.com/dymensionxyz/sdk-utils v0.2.7 h1:9Hy56ivv81ISIG7x9AMaNo6GABRuEgZQ+MmS2PdfuW0=
github.com/dymensionxyz/sdk-utils v0.2.7/go.mod h1:it9owYOpnIe17+ftTATQNDN4z+mBQx20/2Jm8SK15Rk=
github.com/dymensionxyz/sdk-utils v0.2.8-0.20240823083607-ea6d7a482d69 h1:gecl8M1LJpyfInzTfFFlD48u419jBm0BKNHf/b6ZElc=
github.com/dymensionxyz/sdk-utils v0.2.8-0.20240823083607-ea6d7a482d69/go.mod h1:it9owYOpnIe17+ftTATQNDN4z+mBQx20/2Jm8SK15Rk=
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
Expand Down
3 changes: 2 additions & 1 deletion x/eibc/keeper/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
"github.com/dymensionxyz/sdk-utils/utils/uevent"
"github.com/dymensionxyz/sdk-utils/utils/uibc"
"github.com/pkg/errors"

Expand Down Expand Up @@ -52,7 +53,7 @@ func (k Keeper) EIBCDemandOrderHandler(ctx sdk.Context, rollappPacket commontype
return fmt.Errorf("set eibc demand order: %w", err)
}

if err = ctx.EventManager().EmitTypedEvent(eibcDemandOrder.GetCreatedEvent()); err != nil {
if err = uevent.EmitTypedEvent(ctx, eibcDemandOrder.GetCreatedEvent()); err != nil {
return fmt.Errorf("emit event: %w", err)
}

Expand Down
3 changes: 2 additions & 1 deletion x/eibc/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
"github.com/dymensionxyz/sdk-utils/utils/uevent"

commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"

Expand Down Expand Up @@ -95,7 +96,7 @@ func (k *Keeper) UpdateDemandOrderWithStatus(ctx sdk.Context, demandOrder *types
return nil, err
}

if err = ctx.EventManager().EmitTypedEvent(demandOrder.GetPacketStatusUpdatedEvent()); err != nil {
if err = uevent.EmitTypedEvent(ctx, demandOrder.GetPacketStatusUpdatedEvent()); err != nil {
return nil, fmt.Errorf("emit event: %w", err)
}

Expand Down
5 changes: 3 additions & 2 deletions x/eibc/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"
"github.com/dymensionxyz/sdk-utils/utils/uevent"

commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
"github.com/dymensionxyz/dymension/v3/x/eibc/types"
Expand Down Expand Up @@ -64,7 +65,7 @@ func (m msgServer) FulfillOrder(goCtx context.Context, msg *types.MsgFulfillOrde
return nil, err
}

if err = ctx.EventManager().EmitTypedEvent(demandOrder.GetFulfilledEvent()); err != nil {
if err = uevent.EmitTypedEvent(ctx, demandOrder.GetFulfilledEvent()); err != nil {
return nil, fmt.Errorf("emit event: %w", err)
}

Expand Down Expand Up @@ -127,7 +128,7 @@ func (m msgServer) UpdateDemandOrder(goCtx context.Context, msg *types.MsgUpdate
return nil, err
}

if err = ctx.EventManager().EmitTypedEvent(demandOrder.GetUpdatedEvent()); err != nil {
if err = uevent.EmitTypedEvent(ctx, demandOrder.GetUpdatedEvent()); err != nil {
return nil, fmt.Errorf("emit event: %w", err)
}

Expand Down
3 changes: 2 additions & 1 deletion x/eibc/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/gogoproto/proto"
"github.com/dymensionxyz/sdk-utils/utils/uevent"

"github.com/dymensionxyz/dymension/v3/app/apptesting"
commontypes "github.com/dymensionxyz/dymension/v3/x/common/types"
Expand Down Expand Up @@ -200,7 +201,7 @@ func (suite *KeeperTestSuite) TestFulfillOrderEvent() {
if tc.expectedPostFulfillmentEventsCount > 0 {
lastEvent, ok := suite.FindLastEventOfType(suite.Ctx.EventManager().Events(), eventName)
suite.Require().True(ok)
event, _ := sdk.TypedEventToEvent(tc.expectedPostFulfillmentEvent)
event, _ := uevent.TypedEventToEvent(tc.expectedPostFulfillmentEvent)
suite.AssertAttributes(lastEvent, getEventAttributes(event))
}
}
Expand Down
3 changes: 2 additions & 1 deletion x/rollapp/keeper/msg_server_create_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/sdk-utils/utils/uevent"

"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)
Expand All @@ -27,7 +28,7 @@ func (k msgServer) CreateRollapp(goCtx context.Context, msg *types.MsgCreateRoll
return nil, fmt.Errorf("rollapp created hook: %w", err)
}

if err := ctx.EventManager().EmitTypedEvent(msg); err != nil {
if err := uevent.EmitTypedEvent(ctx, msg); err != nil {
return nil, fmt.Errorf("emit event: %w", err)
}

Expand Down
3 changes: 2 additions & 1 deletion x/rollapp/keeper/msg_server_transfer_ownership.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

errorsmod "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/sdk-utils/utils/uevent"

"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)
Expand Down Expand Up @@ -37,7 +38,7 @@ func (k msgServer) TransferOwnership(goCtx context.Context, msg *types.MsgTransf
rollapp.Owner = msg.NewOwner
k.SetRollapp(ctx, rollapp)

if err := ctx.EventManager().EmitTypedEvent(msg); err != nil {
if err := uevent.EmitTypedEvent(ctx, msg); err != nil {
return nil, fmt.Errorf("emit event: %w", err)
}

Expand Down
3 changes: 2 additions & 1 deletion x/rollapp/keeper/msg_server_update_rollapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/sdk-utils/utils/uevent"

"github.com/dymensionxyz/dymension/v3/x/rollapp/types"
)
Expand All @@ -19,7 +20,7 @@ func (k msgServer) UpdateRollappInformation(goCtx context.Context, msg *types.Ms

k.SetRollapp(ctx, updated)

if err = ctx.EventManager().EmitTypedEvent(msg); err != nil {
if err = uevent.EmitTypedEvent(ctx, msg); err != nil {
return nil, fmt.Errorf("emit event: %w", err)
}

Expand Down
10 changes: 8 additions & 2 deletions x/sequencer/keeper/msg_server_increase_bond.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ package keeper

import (
"context"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/sdk-utils/utils/uevent"

"github.com/dymensionxyz/dymension/v3/x/sequencer/types"
)

Expand All @@ -28,15 +31,18 @@ func (k msgServer) IncreaseBond(goCtx context.Context, msg *types.MsgIncreaseBon
k.UpdateSequencer(ctx, &sequencer, sequencer.Status)

// emit a typed event which includes the added amount and the active bond amount
err = ctx.EventManager().EmitTypedEvent(
err = uevent.EmitTypedEvent(ctx,
&types.EventIncreasedBond{
Sequencer: msg.Creator,
Bond: sequencer.Tokens,
AddedAmount: msg.AddAmount,
},
)
if err != nil {
return nil, fmt.Errorf("emit event: %w", err)
}

return &types.MsgIncreaseBondResponse{}, err
return &types.MsgIncreaseBondResponse{}, nil
}

func (k msgServer) bondUpdateAllowed(ctx sdk.Context, senderAddress string) (types.Sequencer, error) {
Expand Down
3 changes: 2 additions & 1 deletion x/sequencer/keeper/msg_server_update_sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/dymensionxyz/sdk-utils/utils/uevent"

"github.com/dymensionxyz/dymension/v3/x/sequencer/types"
)
Expand Down Expand Up @@ -36,7 +37,7 @@ func (k msgServer) UpdateSequencerInformation(goCtx context.Context, msg *types.

k.SetSequencer(ctx, sequencer)

if err := ctx.EventManager().EmitTypedEvent(&sequencer); err != nil {
if err := uevent.EmitTypedEvent(ctx, &sequencer); err != nil {
return nil, fmt.Errorf("emit event: %w", err)
}

Expand Down
9 changes: 5 additions & 4 deletions x/sponsorship/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/dymensionxyz/sdk-utils/utils/uevent"

"github.com/dymensionxyz/dymension/v3/x/sponsorship/types"
)
Expand Down Expand Up @@ -79,7 +80,7 @@ func (h Hooks) afterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress,
return fmt.Errorf("cannot process hook: %w", err)
}

err = ctx.EventManager().EmitTypedEvent(&types.EventVotingPowerUpdate{
err = uevent.EmitTypedEvent(ctx, &types.EventVotingPowerUpdate{
Voter: delAddr.String(),
Validator: valAddr.String(),
Distribution: result.distribution,
Expand All @@ -88,7 +89,7 @@ func (h Hooks) afterDelegationModified(ctx sdk.Context, delAddr sdk.AccAddress,
VotingPowerDiff: result.vpDiff,
})
if err != nil {
return err
return fmt.Errorf("emit event: %w", err)
}

return nil
Expand Down Expand Up @@ -128,7 +129,7 @@ func (h Hooks) beforeDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress,
return fmt.Errorf("cannot process hook: %w", err)
}

err = ctx.EventManager().EmitTypedEvent(&types.EventVotingPowerUpdate{
err = uevent.EmitTypedEvent(ctx, &types.EventVotingPowerUpdate{
Voter: delAddr.String(),
Validator: valAddr.String(),
Distribution: result.distribution,
Expand All @@ -137,7 +138,7 @@ func (h Hooks) beforeDelegationRemoved(ctx sdk.Context, delAddr sdk.AccAddress,
VotingPowerDiff: result.vpDiff,
})
if err != nil {
return err
return fmt.Errorf("emit event: %w", err)
}

return nil
Expand Down
14 changes: 8 additions & 6 deletions x/sponsorship/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package keeper

import (
"context"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/dymensionxyz/sdk-utils/utils/uevent"

"github.com/dymensionxyz/dymension/v3/x/sponsorship/types"
)
Expand Down Expand Up @@ -34,13 +36,13 @@ func (m MsgServer) Vote(goCtx context.Context, msg *types.MsgVote) (*types.MsgVo
return nil, err
}

err = ctx.EventManager().EmitTypedEvent(&types.EventVote{
err = uevent.EmitTypedEvent(ctx, &types.EventVote{
Voter: msg.Voter,
Vote: vote,
Distribution: distr,
})
if err != nil {
return nil, err
return nil, fmt.Errorf("emit event: %w", err)
}

return &types.MsgVoteResponse{}, nil
Expand All @@ -61,12 +63,12 @@ func (m MsgServer) RevokeVote(goCtx context.Context, msg *types.MsgRevokeVote) (
return nil, err
}

err = ctx.EventManager().EmitTypedEvent(&types.EventRevokeVote{
err = uevent.EmitTypedEvent(ctx, &types.EventRevokeVote{
Voter: msg.Voter,
Distribution: distr,
})
if err != nil {
return nil, err
return nil, fmt.Errorf("emit event: %w", err)
}

return &types.MsgRevokeVoteResponse{}, nil
Expand All @@ -93,13 +95,13 @@ func (m MsgServer) UpdateParams(ctx context.Context, msg *types.MsgUpdateParams)
}

sdkCtx := sdk.UnwrapSDKContext(ctx)
err = sdkCtx.EventManager().EmitTypedEvent(&types.EventUpdateParams{
err = uevent.EmitTypedEvent(sdkCtx, &types.EventUpdateParams{
Authority: msg.Authority,
NewParams: msg.NewParams,
OldParams: oldParams,
})
if err != nil {
return nil, err
return nil, fmt.Errorf("emit event: %w", err)
}

return &types.MsgUpdateParamsResponse{}, nil
Expand Down

0 comments on commit 95c7b5f

Please sign in to comment.