From 79626613a874f3a246b0c7e1f0786ded8b300515 Mon Sep 17 00:00:00 2001 From: Chandragupta Singh Date: Mon, 11 Mar 2024 22:27:31 +0530 Subject: [PATCH] update params added --- app/app.go | 1 + x/gasless/keeper/keeper.go | 3 ++ x/gasless/keeper/msg_server.go | 13 +++++++++ x/gasless/types/codec.go | 4 +++ x/gasless/types/message_update_params.go | 35 ++++++++++++++++++++++++ 5 files changed, 56 insertions(+) create mode 100644 x/gasless/types/message_update_params.go diff --git a/app/app.go b/app/app.go index 8542f5839..6a58b7642 100644 --- a/app/app.go +++ b/app/app.go @@ -971,6 +971,7 @@ func New( app.AccountKeeper, app.BankKeeper, &app.WasmKeeper, + govModAddress, ) // ICQ Keeper diff --git a/x/gasless/keeper/keeper.go b/x/gasless/keeper/keeper.go index 220b7a17f..597cc224a 100644 --- a/x/gasless/keeper/keeper.go +++ b/x/gasless/keeper/keeper.go @@ -25,6 +25,7 @@ type Keeper struct { accountKeeper expected.AccountKeeper bankKeeper expected.BankKeeper wasmKeeper *wasmkeeper.Keeper + authority string } // NewKeeper creates a new gasless Keeper instance. @@ -36,6 +37,7 @@ func NewKeeper( accountKeeper expected.AccountKeeper, bankKeeper expected.BankKeeper, wasmKeeper *wasmkeeper.Keeper, + authority string, ) Keeper { if !paramSpace.HasKeyTable() { paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) @@ -49,6 +51,7 @@ func NewKeeper( accountKeeper: accountKeeper, bankKeeper: bankKeeper, wasmKeeper: wasmKeeper, + authority: authority, } } diff --git a/x/gasless/keeper/msg_server.go b/x/gasless/keeper/msg_server.go index 2a145e58b..679c72932 100644 --- a/x/gasless/keeper/msg_server.go +++ b/x/gasless/keeper/msg_server.go @@ -2,9 +2,11 @@ package keeper import ( "context" + "cosmossdk.io/errors" "github.com/comdex-official/comdex/x/gasless/types" sdk "github.com/cosmos/cosmos-sdk/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) type msgServer struct { @@ -95,3 +97,14 @@ func (m msgServer) UpdateGasConsumerLimit(goCtx context.Context, msg *types.MsgU return &types.MsgUpdateGasConsumerLimitResponse{}, nil } + +func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { + if k.authority != req.Authority { + return nil, errors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.authority, req.Authority) + } + + ctx := sdk.UnwrapSDKContext(goCtx) + k.SetParams(ctx, req.Params) + + return &types.MsgUpdateParamsResponse{}, nil +} diff --git a/x/gasless/types/codec.go b/x/gasless/types/codec.go index 503aacfe4..0c76ef7c9 100644 --- a/x/gasless/types/codec.go +++ b/x/gasless/types/codec.go @@ -4,6 +4,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + "github.com/cosmos/cosmos-sdk/codec/legacy" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/msgservice" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -19,6 +20,8 @@ func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino) { cdc.RegisterConcrete(&MsgBlockConsumer{}, "comdex/gasless/MsgBlockConsumer", nil) cdc.RegisterConcrete(&MsgUnblockConsumer{}, "comdex/gasless/MsgUnblockConsumer", nil) cdc.RegisterConcrete(&MsgUpdateGasConsumerLimit{}, "comdex/gasless/MsgUpdateGasConsumerLimit", nil) + cdc.RegisterConcrete(&Params{}, "comdex/gasless/Params", nil) + legacy.RegisterAminoMsg(cdc, &MsgUpdateParams{}, "comdex/gasless/MsgUpdateParams") } // RegisterInterfaces registers the x/gasless interfaces types with the @@ -37,6 +40,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) { &MsgBlockConsumer{}, &MsgUnblockConsumer{}, &MsgUpdateGasConsumerLimit{}, + &MsgUpdateParams{}, ) msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc) diff --git a/x/gasless/types/message_update_params.go b/x/gasless/types/message_update_params.go new file mode 100644 index 000000000..9c12198b2 --- /dev/null +++ b/x/gasless/types/message_update_params.go @@ -0,0 +1,35 @@ +package types + +import ( + errorsmod "cosmossdk.io/errors" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var _ sdk.Msg = &MsgUpdateParams{} + +func (msg *MsgUpdateParams) Route() string { + return RouterKey +} + +func (msg *MsgUpdateParams) Type() string { + return "update-params" +} + +func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { + authority, err := sdk.AccAddressFromBech32(msg.Authority) + if err != nil { // should never happen as valid basic rejects invalid addresses + panic(err.Error()) + } + return []sdk.AccAddress{authority} +} + +func (msg *MsgUpdateParams) GetSignBytes() []byte { + return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(msg)) +} + +func (msg *MsgUpdateParams) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { + return errorsmod.Wrap(err, "authority is invalid") + } + return nil +}