Skip to content

Commit

Permalink
Handle EurekaSendMsg
Browse files Browse the repository at this point in the history
  • Loading branch information
jawoznia committed Feb 17, 2025
1 parent 4e7c441 commit 04a23c8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ replace (
// dgrijalva/jwt-go is deprecated and doesn't receive security updates.
// See: https://github.com/cosmos/cosmos-sdk/issues/13134
github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2
github.com/CosmWasm/wasmvm/v2 => github.com/CosmWasm/wasmvm/v2 v2.2.2-0.20250213170323-ec956d351a70
// Fix upstream GHSA-h395-qcrw-5vmq vulnerability.
// See: https://github.com/cosmos/cosmos-sdk/issues/10409
github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.8.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CosmWasm/wasmvm/v2 v2.2.1 h1:cmOnM+TDfUl2VRugeo1eJBw4U/Lw0WLviuQHKSo9DVQ=
github.com/CosmWasm/wasmvm/v2 v2.2.1/go.mod h1:bMhLQL4Yp9CzJi9A83aR7VO9wockOsSlZbT4ztOl6bg=
github.com/CosmWasm/wasmvm/v2 v2.2.2-0.20250213170323-ec956d351a70 h1:Wt7fazex4eq9s+43X/rFM4pZ0v68XIi+2CdQMPr56OQ=
github.com/CosmWasm/wasmvm/v2 v2.2.2-0.20250213170323-ec956d351a70/go.mod h1:bMhLQL4Yp9CzJi9A83aR7VO9wockOsSlZbT4ztOl6bg=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/datadog-go v4.8.3+incompatible h1:fNGaYSuObuQb5nzeTQqowRAd9bpDIRRV4/gUtIBjh8Q=
github.com/DataDog/datadog-go v4.8.3+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
Expand Down
27 changes: 27 additions & 0 deletions x/wasm/keeper/handler_plugin_encoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
ibctransfertypes "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types"
ibcclienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types"
channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types"
channelv2types "github.com/cosmos/ibc-go/v9/modules/core/04-channel/v2/types"

errorsmod "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
Expand Down Expand Up @@ -36,13 +37,15 @@ type (
AnyEncoder func(ctx sdk.Context, sender sdk.AccAddress, msg *wasmvmtypes.AnyMsg) ([]sdk.Msg, error)
WasmEncoder func(sender sdk.AccAddress, msg *wasmvmtypes.WasmMsg) ([]sdk.Msg, error)
IBCEncoder func(ctx sdk.Context, sender sdk.AccAddress, contractIBCPortID string, msg *wasmvmtypes.IBCMsg) ([]sdk.Msg, error)
EurekaEncoder func(msg *wasmvmtypes.EurekaMsg) ([]sdk.Msg, error)
)

type MessageEncoders struct {
Bank func(sender sdk.AccAddress, msg *wasmvmtypes.BankMsg) ([]sdk.Msg, error)
Custom func(sender sdk.AccAddress, msg json.RawMessage) ([]sdk.Msg, error)
Distribution func(sender sdk.AccAddress, msg *wasmvmtypes.DistributionMsg) ([]sdk.Msg, error)
IBC func(ctx sdk.Context, sender sdk.AccAddress, contractIBCPortID string, msg *wasmvmtypes.IBCMsg) ([]sdk.Msg, error)
Eureka func(msg *wasmvmtypes.EurekaMsg) ([]sdk.Msg, error)
Staking func(sender sdk.AccAddress, msg *wasmvmtypes.StakingMsg) ([]sdk.Msg, error)
Any func(ctx sdk.Context, sender sdk.AccAddress, msg *wasmvmtypes.AnyMsg) ([]sdk.Msg, error)
Wasm func(sender sdk.AccAddress, msg *wasmvmtypes.WasmMsg) ([]sdk.Msg, error)
Expand All @@ -55,6 +58,7 @@ func DefaultEncoders(unpacker codectypes.AnyUnpacker, portSource types.ICS20Tran
Custom: NoCustomMsg,
Distribution: EncodeDistributionMsg,
IBC: EncodeIBCMsg(portSource),
Eureka: EncodeEurekaMsg,
Staking: EncodeStakingMsg,
Any: EncodeAnyMsg(unpacker),
Wasm: EncodeWasmMsg,
Expand All @@ -78,6 +82,9 @@ func (e MessageEncoders) Merge(o *MessageEncoders) MessageEncoders {
if o.IBC != nil {
e.IBC = o.IBC
}
if o.Eureka != nil {
e.Eureka = o.Eureka
}
if o.Staking != nil {
e.Staking = o.Staking
}
Expand All @@ -103,6 +110,8 @@ func (e MessageEncoders) Encode(ctx sdk.Context, contractAddr sdk.AccAddress, co
return e.Distribution(contractAddr, msg.Distribution)
case msg.IBC != nil:
return e.IBC(ctx, contractAddr, contractIBCPortID, msg.IBC)
case msg.Eureka != nil:
return e.Eureka(msg.Eureka)
case msg.Staking != nil:
return e.Staking(contractAddr, msg.Staking)
case msg.Any != nil:
Expand Down Expand Up @@ -360,6 +369,24 @@ func EncodeIBCMsg(portSource types.ICS20TransferPortSource) func(ctx sdk.Context
}
}

func EncodeEurekaMsg(msg *wasmvmtypes.EurekaMsg) func(msg *wasmvmtypes.EurekaMsg) ([]sdk.Msg, error) {
return func(msg *wasmvmtypes.EurekaMsg) ([]sdk.Msg, error) {
switch {
case msg.SendPacket != nil:
msg := &channelv2types.MsgSendPacket{
SourceClient: msg.SendPacket.ChannelID,
TimeoutTimestamp: msg.SendPacket.Timeout,
Payloads: msg.SendPacket.Payloads,
// Do we set it?
// Signer: "signer",
}
return []sdk.Msg{msg}, nil
default:
return nil, errorsmod.Wrap(types.ErrUnknownMsg, "unknown variant of Eureka")
}
}
}

func EncodeGovMsg(sender sdk.AccAddress, msg *wasmvmtypes.GovMsg) ([]sdk.Msg, error) {
switch {
case msg.Vote != nil:
Expand Down

0 comments on commit 04a23c8

Please sign in to comment.