Skip to content

Commit

Permalink
feat: move exec compat msg to core, regen
Browse files Browse the repository at this point in the history
  • Loading branch information
nhannamsiu committed Jan 11, 2023
1 parent 53b8980 commit 7fadcee
Show file tree
Hide file tree
Showing 4 changed files with 744 additions and 16 deletions.
8 changes: 7 additions & 1 deletion chain/wasmx/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
Expand All @@ -15,7 +16,7 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&BatchContractRegistrationRequestProposal{}, "wasmx/BatchContractRegistrationRequestProposal", nil)
cdc.RegisterConcrete(&BatchContractDeregistrationProposal{}, "wasmx/BatchContractDeregistrationProposal", nil)
cdc.RegisterConcrete(&BatchStoreCodeProposal{}, "wasmx/BatchStoreCodeProposal", nil)

cdc.RegisterConcrete(&MsgExecuteContractCompat{}, "wasmx/MsgExecuteContractCompat", nil)
}

func RegisterInterfaces(registry types.InterfaceRegistry) {
Expand All @@ -27,6 +28,11 @@ func RegisterInterfaces(registry types.InterfaceRegistry) {
&BatchStoreCodeProposal{},
)

registry.RegisterImplementations(
(*sdk.Msg)(nil),
&MsgExecuteContractCompat{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
}

Expand Down
45 changes: 45 additions & 0 deletions chain/wasmx/types/msgs.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
package types

import (
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

const RouterKey = ModuleName

func (msg MsgExecuteContractCompat) Route() string {
return RouterKey
}

func (msg MsgExecuteContractCompat) Type() string {
return "executeCompat"
}

func (msg MsgExecuteContractCompat) ValidateBasic() error {
if _, err := sdk.AccAddressFromBech32(msg.Sender); err != nil {
return sdkerrors.Wrap(err, "sender")
}
if _, err := sdk.AccAddressFromBech32(msg.Contract); err != nil {
return sdkerrors.Wrap(err, "contract")
}

if !msg.Funds.IsValid() {
return sdkerrors.Wrap(sdkerrors.ErrInvalidCoins, "sentFunds")
}

rawMsg := wasmtypes.RawContractMessage(msg.Msg)
if err := rawMsg.ValidateBasic(); err != nil {
return sdkerrors.Wrap(err, "payload msg")
}
return nil
}

func (msg MsgExecuteContractCompat) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func (msg MsgExecuteContractCompat) GetSigners() []sdk.AccAddress {
senderAddr, err := sdk.AccAddressFromBech32(msg.Sender)
if err != nil { // should never happen as valid basic rejects invalid addresses
panic(err.Error())
}
return []sdk.AccAddress{senderAddr}
}
Loading

0 comments on commit 7fadcee

Please sign in to comment.