Closed
Description
opened on Oct 14, 2020
Summary
Implement ADR 031: Protobuf Msg Services as documented in #7458 and #7122 .
Roadmap
- Base implementation
- Refactor RegisterQueryServices -> RegisterServices #7518 Refactor
RegisterQueryService
->RegisterServices
and createConfigurator
type - Add ADR 031 BaseApp and codec infrastructure #7519 Implement
ServiceMsg
,MsgRequest
, and router for aMsg
service
intestdata
. Router should also handleEventManager
stuff - Refactor x/bank according to ADR 031 #7520 Add buf linter exception for
service
request type names (we want to use the existingMsg
types without theRequest
suffix) - Refactor x/bank according to ADR 031 #7520 Create
WrapServiceResult(proto.Message, error) (*sdk.Result, error)
func which takes a service method result and error and wraps it in an*sdk.Result
orerror
for use in refactored module handlers - Add
MsgServer
toConfigurator
and wire up modules
- Refactor RegisterQueryServices -> RegisterServices #7518 Refactor
- Modules - only modules which define
Msg
s. See Implementation Notes below- Refactor x/bank according to ADR 031 #7520 x/bank
- Refactor x/{gov, crisis} according to ADR 031 #7533 x/crisis (@atheeshp )
- Refactor x/distribution according to ADR 031 #7524 x/distribution (@atheeshp )
- x/evidence (@amaurymartiny)
- Refactor x/{gov, crisis} according to ADR 031 #7533 x/gov (@atheeshp )
- x/ibc
- [x/slashing] Implement Protobuf Msg Services #7557 x/slashing (@blushi)
- Refactor x/staking according to ADR 031 #7556 x/staking (@atheeshp )
- Refactor x/auth/vesting to use ADR-031 #7551 x/vesting (@clevinson)
Implementation Notes
Modules
- Add a
service
definition calledMsg
in each module's tx.proto file. Re-use the existingMsg
types for the request type and add an uniqueResponse
type for eachrpc
method. - Refactor all handler functions into an implementation of the generated
MsgServer
interface
// x/bank/handler.go
// Handle MsgSend.
func handleMsgSend(ctx sdk.Context, k keeper.Keeper, msg *types.MsgSend) (*sdk.Result, error) {
...
return &sdk.Result{Events: ctx.EventManager().ABCIEvents()}, nil
}
becomes:
// x/bank/keeper/msg_server.go
type msgServer struct {
Keeper
}
func (k msgServer) Send(goCtx context.Context, msg *types.MsgSend) (*types.MsgSendResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
...
return &types.MsgSendResponse{}, nil
}
- Refactor the root handler to just call those
MsgService
methods. Ex:
func NewHandler(k keeper.Keeper) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) {
ctx = ctx.WithEventManager(sdk.NewEventManager())
msgServer := keeper.NewMsgServerImpl(k)
switch msg := msg.(type) {
case *types.MsgSend:
res, err := msgServer.Send(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
case *types.MsgMultiSend:
res, err := msgServer.MultiSend(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
default:
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized bank message type: %T", msg)
}
}
}
- Wire up
MsgServer
inRegisterServices
(if possible - that functionality is currently not ready, so skip this step for now)
Metadata
Assignees
Labels
No labels
Activity