You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In #7519, MsgServer request types are registered with custom type URLs in the InterfaceRegistry in AppModule.RegisterServices. Clients will not have these URLs registered just by calling AppModuleBasic.RegisterInterfaces so the registration needs to happen earlier for clients (CLI and grpc-gateway).
Implementation
First add a function RegisterMsgServiceDesc(InterfaceRegistry, grpc.ServiceDesc) which will be used in RegisterInterfaces:
// x/bank/types/codec.gofuncRegisterInterfaces(registry types.InterfaceRegistry) {
...RegisterMsgServiceDesc(registry, _Msg_serviceDesc) // _Msg_serviceDesc is generated by proto-gen
}
RegisterMsgServiceDesc should do the same thing under the hood that MsgServiceRouter.RegisterServices is now doing under the hood:
// NOTE: This is how we pull the concrete request type for each handler for registering in the InterfaceRegistry.// This approach is maybe a bit hacky, but less hacky than reflecting on the handler object itself.// We use a no-op interceptor to avoid actually calling into the handler itself._, _=methodHandler(nil, context.Background(), func(iinterface{}) error {
msg, ok:=i.(proto.Message)
if!ok {
// We panic here because there is no other alternative and the app cannot be initialized correctly// this should only happen if there is a problem with code generation in which case the app won't// work correctly anyway.panic(fmt.Errorf("can't register request type %T for service method %s", i, fqMethod))
}
msr.interfaceRegistry.RegisterCustomTypeURL((*sdk.MsgRequest)(nil), fqMethod, msg)
returnnil
}, noopInterceptor)
MsgServiceRouter.RegisterServices should then be updated to return an error if interfaces are not already registered. It can check what is registered using the InterfaceRegistry.Resolve method. That error should be very clear and explain how to use RegisterMsgServiceDesc.
It would be ideal to have an integration test to verify that CLI clients (using QueryTxCmd) and ideally grpc-gateway have these type URLs registered properly.
The text was updated successfully, but these errors were encountered:
Context
In #7519,
MsgServer
request types are registered with custom type URLs in theInterfaceRegistry
inAppModule.RegisterServices
. Clients will not have these URLs registered just by callingAppModuleBasic.RegisterInterfaces
so the registration needs to happen earlier for clients (CLI and grpc-gateway).Implementation
First add a function
RegisterMsgServiceDesc(InterfaceRegistry, grpc.ServiceDesc)
which will be used inRegisterInterfaces
:RegisterMsgServiceDesc
should do the same thing under the hood thatMsgServiceRouter.RegisterServices
is now doing under the hood:MsgServiceRouter.RegisterServices
should then be updated to return an error if interfaces are not already registered. It can check what is registered using theInterfaceRegistry.Resolve
method. That error should be very clear and explain how to useRegisterMsgServiceDesc
.It would be ideal to have an integration test to verify that CLI clients (using
QueryTxCmd
) and ideally grpc-gateway have these type URLs registered properly.The text was updated successfully, but these errors were encountered: