From a19c3a60e4efff8dfd9d07b6fe68a4cfd1331b8c Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 25 Oct 2022 17:35:49 -0400 Subject: [PATCH] feat(core): add ADR 033 (inter-module communication) Client interface (#13631) Co-authored-by: Marko --- core/intermodule/client.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 core/intermodule/client.go diff --git a/core/intermodule/client.go b/core/intermodule/client.go new file mode 100644 index 000000000..0c6d5f33a --- /dev/null +++ b/core/intermodule/client.go @@ -0,0 +1,32 @@ +package intermodule + +import ( + "context" + + "google.golang.org/grpc" +) + +// Client is an inter-module client as specified in ADR-033. It +// allows one module to send msg's and queries to other modules provided +// that the request is valid and can be properly authenticated. +type Client interface { + grpc.ClientConnInterface + + // InvokerByMethod resolves an invoker for the provided method or returns an error. + InvokerByMethod(method string) (Invoker, error) + + // InvokerByRequest resolves an invoker for the provided request type or returns an error. + // This only works for Msg's as they are routed based on type name in transactions already. + // For queries use InvokerByMethod instead. + InvokerByRequest(request any) (Invoker, error) + + // DerivedClient returns an inter-module client for the ADR-028 derived + // module address for the provided key. + DerivedClient(key []byte) Client + + // Address is the ADR-028 address of this client against which messages will be authenticated. + Address() []byte +} + +// Invoker is an inter-module invoker that has already been resolved to a specific method route. +type Invoker func(ctx context.Context, request any, opts ...grpc.CallOption) (res any, err error)