cosmos-sdk/x/consensus/keeper/msg_server.go
Marko 6ec25b6261
feat: consensus module (#13164)
* add module

* pulsar

* fix++

* adddress comments

* comments on genesis methods

* register migration

* Update x/consensus/exported/exported.go

Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>

* address

* remove annotations

* remove migrations

* fix lint

Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
2022-09-08 03:28:44 +00:00

49 lines
1.3 KiB
Go

package keeper
import (
"context"
tmtypes "github.com/tendermint/tendermint/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/x/consensus/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
)
type msgServer struct {
Keeper
}
var _ types.MsgServer = msgServer{}
// NewMsgServerImpl returns an implementation of the bank MsgServer interface
// for the provided Keeper.
func NewMsgServerImpl(keeper Keeper) types.MsgServer {
return &msgServer{Keeper: keeper}
}
func (k msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) {
if k.GetAuthority() != req.Authority {
return nil, sdkerrors.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", k.GetAuthority(), req.Authority)
}
ctx := sdk.UnwrapSDKContext(goCtx)
consensusParams := req.ToProtoConsensusParams()
if err := types.Validate(tmtypes.ConsensusParamsFromProto(consensusParams)); err != nil {
return nil, err
}
k.Set(ctx, &consensusParams)
ctx.EventManager().EmitEvent(
sdk.NewEvent(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, req.Authority),
),
)
return &types.MsgUpdateParamsResponse{}, nil
}