generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(mint): add tx to update params
- Loading branch information
Showing
7 changed files
with
736 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
syntax = "proto3"; | ||
|
||
package mint.v1beta1; | ||
|
||
import "cosmos/msg/v1/msg.proto"; | ||
import "cosmos_proto/cosmos.proto"; | ||
import "gogoproto/gogo.proto"; | ||
import "mint/v1beta1/mint.proto"; | ||
|
||
option go_package = "github.com/okp4/okp4d/x/mint/types"; | ||
|
||
// MsgService defines the service for the logic module. | ||
// Do nothing for now as the service is without any side effects. | ||
service MsgService { | ||
// UpdateParams defined a governance operation for updating the x/mint module parameters. | ||
// The authority is hard-coded to the Cosmos SDK x/gov module account | ||
rpc UpdateParams(MsgUpdateParams) returns (MsgUpdateParamsResponse); | ||
} | ||
|
||
// MsgUpdateParams defines a Msg for updating the x/mint module parameters. | ||
message MsgUpdateParams { | ||
option (cosmos.msg.v1.signer) = "authority"; | ||
// authority is the address of the governance account. | ||
string authority = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"]; | ||
// params defines the x/mint parameters to update. | ||
// NOTE: All parameters must be supplied. | ||
Params params = 2 [(gogoproto.nullable) = false]; | ||
} | ||
|
||
// MsgUpdateParamsResponse defines the response structure for executing a | ||
// MsgUpdateParams message. | ||
message MsgUpdateParamsResponse {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
"github.com/okp4/okp4d/x/mint/types" | ||
) | ||
|
||
type msgServer struct { | ||
Keeper | ||
} | ||
|
||
// NewMsgServerImpl returns an implementation of the MsgServer interface | ||
// for the provided Keeper. | ||
func NewMsgServerImpl(keeper Keeper) types.MsgServiceServer { | ||
return &msgServer{Keeper: keeper} | ||
} | ||
|
||
var _ types.MsgServiceServer = msgServer{} | ||
|
||
// UpdateParams implements the gRPC MsgServer interface. When an UpdateParams | ||
// proposal passes, it updates the module parameters. The update can only be | ||
// performed if the requested authority is the Cosmos SDK governance module | ||
// account. | ||
func (ms msgServer) UpdateParams(goCtx context.Context, req *types.MsgUpdateParams) (*types.MsgUpdateParamsResponse, error) { | ||
if ms.authority.String() != req.Authority { | ||
return nil, errorsmod.Wrapf(govtypes.ErrInvalidSigner, "invalid authority; expected %s, got %s", ms.authority.String(), req.Authority) | ||
} | ||
|
||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
if err := ms.SetParams(ctx, req.Params); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &types.MsgUpdateParamsResponse{}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package types | ||
|
||
import ( | ||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
var _ sdk.Msg = &MsgUpdateParams{} | ||
|
||
// GetSigners returns the expected signers for a MsgUpdateParams message. | ||
func (m *MsgUpdateParams) GetSigners() []sdk.AccAddress { | ||
addr := sdk.MustAccAddressFromBech32(m.Authority) | ||
return []sdk.AccAddress{addr} | ||
} | ||
|
||
// ValidateBasic does a sanity check of the provided data. | ||
func (m *MsgUpdateParams) ValidateBasic() error { | ||
if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil { | ||
return errorsmod.Wrap(err, "invalid authority address") | ||
} | ||
|
||
if err := m.Params.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// GetSignBytes implements the LegacyMsg interface. | ||
func (m MsgUpdateParams) GetSignBytes() []byte { | ||
return sdk.MustSortJSON(AminoCdc.MustMarshalJSON(&m)) | ||
} |
Oops, something went wrong.