Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Protobuf Msg Services #7540

Closed
16 tasks done
clevinson opened this issue Oct 14, 2020 · 3 comments
Closed
16 tasks done

Implement Protobuf Msg Services #7540

clevinson opened this issue Oct 14, 2020 · 3 comments
Milestone

Comments

@clevinson
Copy link
Contributor

clevinson commented Oct 14, 2020

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)
@aaronc
Copy link
Member

aaronc commented Oct 14, 2020

do-not-edit-start-codetree-epic-issues

Issues in this epic:

Title Milestone Assignees State
ADR 031: Add MsgServer to Configurator and wire up modules #7568 v0.40.1 amaurymartiny Closed
[x/vesting] Implement Protobuf Msg Services #7548 v0.40.1 clevinson Closed
[x/distribution] Implement Protobuf Msg Services #7547 v0.40.1 atheeshp Closed
[x/staking] Implement Protobuf Msg Services #7546 v0.40.1 atheeshp Closed
[x/slashing] Implement Protobuf Msg Services #7545 v0.40.1 blushi Closed
[x/gov & x/crisis] Implement Protobuf Msg Services #7544 v0.40.1 atheeshp Closed
[x/ibc] Implement Protobuf Msg Services #7543 v0.40.1 atheeshp Closed
[x/evidence] Implement Protobuf Msg Services #7542 v0.40.1 amaurymartiny Closed
do-not-edit-end-codetree-epic-issues

@aaronc aaronc added size: 3 and removed size: 3 labels Oct 14, 2020
@aaronc aaronc added this to the v0.40.1 milestone Oct 14, 2020
@clevinson clevinson mentioned this issue Oct 19, 2020
31 tasks
@clevinson clevinson changed the title [Codetree Trial] Implement Protobuf Msg Services Implement Protobuf Msg Services Oct 19, 2020
@aaronc
Copy link
Member

aaronc commented Oct 19, 2020

Note that we probably don't need all the checkboxes when we're using epics @clevinson

@aaronc
Copy link
Member

aaronc commented Oct 19, 2020

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants