Skip to content

Implement Protobuf Msg Services #7540

Closed
@clevinson

Description

Summary

Implement ADR 031: Protobuf Msg Services as documented in #7458 and #7122 .

Roadmap

Implementation Notes

Modules

  1. Add a service definition called Msg in each module's tx.proto file. Re-use the existing Msg types for the request type and add an unique Response type for each rpc method.
  2. 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
}
  1. 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)
		}
	}
}
  1. Wire up MsgServer in RegisterServices (if possible - that functionality is currently not ready, so skip this step for now)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions