Skip to content

Commit

Permalink
update params added
Browse files Browse the repository at this point in the history
  • Loading branch information
cgsingh33 committed Mar 11, 2024
1 parent d570339 commit 7962661
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,7 @@ func New(
app.AccountKeeper,
app.BankKeeper,
&app.WasmKeeper,
govModAddress,
)

// ICQ Keeper
Expand Down
3 changes: 3 additions & 0 deletions x/gasless/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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())
Expand All @@ -49,6 +51,7 @@ func NewKeeper(
accountKeeper: accountKeeper,
bankKeeper: bankKeeper,
wasmKeeper: wasmKeeper,
authority: authority,
}
}

Expand Down
13 changes: 13 additions & 0 deletions x/gasless/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions x/gasless/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"
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"
Expand All @@ -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
Expand All @@ -37,6 +40,7 @@ func RegisterInterfaces(registry cdctypes.InterfaceRegistry) {
&MsgBlockConsumer{},
&MsgUnblockConsumer{},
&MsgUpdateGasConsumerLimit{},
&MsgUpdateParams{},
)

msgservice.RegisterMsgServiceDesc(registry, &_Msg_serviceDesc)
Expand Down
35 changes: 35 additions & 0 deletions x/gasless/types/message_update_params.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 7962661

Please sign in to comment.