Skip to content

Commit

Permalink
Add EIP712 support for create-IRO-plan message (#1287)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Tsitrin <[email protected]>
  • Loading branch information
ItzhakBokris and mtsitrin authored Oct 6, 2024
1 parent 90a8791 commit d3c31fd
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
15 changes: 14 additions & 1 deletion x/iro/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
cdctypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/msgservice"
authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec"
)

func RegisterCodec(cdc *codec.LegacyAmino) {
cdc.RegisterConcrete(&MsgBuy{}, "iro/Buy", nil)
cdc.RegisterConcrete(&MsgSell{}, "iro/Sell", nil)
cdc.RegisterConcrete(&MsgClaim{}, "iro/Claim", nil)
cdc.RegisterConcrete(&MsgCreatePlan{}, "iro/CreatePlan", nil)
cdc.RegisterConcrete(&MsgUpdateParams{}, "iro/UpdateParams", nil)
}

Expand All @@ -20,6 +22,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
&MsgBuy{},
&MsgSell{},
&MsgClaim{},
&MsgCreatePlan{},
&MsgUpdateParams{},
)

Expand All @@ -28,5 +31,15 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {

var (
Amino = codec.NewLegacyAmino()
ModuleCdc = codec.NewProtoCodec(cdctypes.NewInterfaceRegistry())
ModuleCdc = codec.NewAminoCodec(Amino)
)

func init() {
RegisterCodec(Amino)
// Register all Amino interfaces and concrete types on the authz Amino codec so that this can later be
// used to properly serialize MsgGrant and MsgExec instances
sdk.RegisterLegacyAminoCodec(Amino)
RegisterCodec(authzcodec.Amino)

Amino.Seal()
}
27 changes: 22 additions & 5 deletions x/iro/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ package types

import (
"errors"
"github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

const TypeMsgCreatePlan = "create_plan"

var (
_ sdk.Msg = &MsgCreatePlan{}
_ sdk.Msg = &MsgBuy{}
_ sdk.Msg = &MsgSell{}
_ sdk.Msg = &MsgClaim{}
_ sdk.Msg = &MsgUpdateParams{}
_ sdk.Msg = &MsgCreatePlan{}
_ sdk.Msg = &MsgBuy{}
_ sdk.Msg = &MsgSell{}
_ sdk.Msg = &MsgClaim{}
_ sdk.Msg = &MsgUpdateParams{}
_ legacytx.LegacyMsg = &MsgCreatePlan{}
)

// ValidateBasic performs basic validation checks on the MsgCreatePlan message.
Expand Down Expand Up @@ -45,11 +49,24 @@ func (m *MsgCreatePlan) ValidateBasic() error {
return nil
}

func (m *MsgCreatePlan) Route() string {
return RouterKey
}

func (m *MsgCreatePlan) Type() string {
return TypeMsgCreatePlan
}

func (m *MsgCreatePlan) GetSigners() []sdk.AccAddress {
addr := sdk.MustAccAddressFromBech32(m.Owner)
return []sdk.AccAddress{addr}
}

func (m *MsgCreatePlan) GetSignBytes() []byte {
bz := ModuleCdc.MustMarshalJSON(m)
return sdk.MustSortJSON(bz)
}

func (m *MsgBuy) ValidateBasic() error {
// buyer bech32
_, err := sdk.AccAddressFromBech32(m.Buyer)
Expand Down

0 comments on commit d3c31fd

Please sign in to comment.