chore: migrate core to gogoproto.Message (#20781)

This commit is contained in:
Marko
2024-06-28 09:34:23 +00:00
committed by GitHub
parent 5d54274775
commit c7375f7cd3
27 changed files with 183 additions and 153 deletions
+2 -2
View File
@@ -3,7 +3,7 @@ package runtime
import (
"context"
"google.golang.org/protobuf/runtime/protoiface"
gogoproto "github.com/cosmos/gogoproto/proto"
"cosmossdk.io/core/event"
@@ -34,7 +34,7 @@ func NewEventManager(ctx context.Context) event.Manager {
// Emit emits an typed event that is defined in the protobuf file.
// In the future these events will be added to consensus.
func (e Events) Emit(event protoiface.MessageV1) error {
func (e Events) Emit(event gogoproto.Message) error {
return e.EventManagerI.EmitTypedEvent(event)
}
+11 -12
View File
@@ -6,9 +6,8 @@ import (
"reflect"
"strings"
"github.com/cosmos/gogoproto/proto"
gogoproto "github.com/cosmos/gogoproto/proto"
protov2 "google.golang.org/protobuf/proto"
"google.golang.org/protobuf/runtime/protoiface"
"cosmossdk.io/core/router"
@@ -48,7 +47,7 @@ func (m *msgRouterService) CanInvoke(ctx context.Context, typeURL string) error
// InvokeTyped execute a message and fill-in a response.
// The response must be known and passed as a parameter.
// Use InvokeUntyped if the response type is not known.
func (m *msgRouterService) InvokeTyped(ctx context.Context, msg, resp protoiface.MessageV1) error {
func (m *msgRouterService) InvokeTyped(ctx context.Context, msg, resp gogoproto.Message) error {
messageName := msgTypeURL(msg)
handler := m.router.HybridHandlerByMsgName(messageName)
if handler == nil {
@@ -59,7 +58,7 @@ func (m *msgRouterService) InvokeTyped(ctx context.Context, msg, resp protoiface
}
// InvokeUntyped execute a message and returns a response.
func (m *msgRouterService) InvokeUntyped(ctx context.Context, msg protoiface.MessageV1) (protoiface.MessageV1, error) {
func (m *msgRouterService) InvokeUntyped(ctx context.Context, msg gogoproto.Message) (gogoproto.Message, error) {
messageName := msgTypeURL(msg)
respName := m.router.ResponseNameByMsgName(messageName)
if respName == "" {
@@ -67,11 +66,11 @@ func (m *msgRouterService) InvokeUntyped(ctx context.Context, msg protoiface.Mes
}
// get response type
typ := proto.MessageType(respName)
typ := gogoproto.MessageType(respName)
if typ == nil {
return nil, fmt.Errorf("no message type found for %s", respName)
}
msgResp, ok := reflect.New(typ.Elem()).Interface().(protoiface.MessageV1)
msgResp, ok := reflect.New(typ.Elem()).Interface().(gogoproto.Message)
if !ok {
return nil, fmt.Errorf("could not create response message %s", respName)
}
@@ -113,7 +112,7 @@ func (m *queryRouterService) CanInvoke(ctx context.Context, typeURL string) erro
// InvokeTyped execute a message and fill-in a response.
// The response must be known and passed as a parameter.
// Use InvokeUntyped if the response type is not known.
func (m *queryRouterService) InvokeTyped(ctx context.Context, req, resp protoiface.MessageV1) error {
func (m *queryRouterService) InvokeTyped(ctx context.Context, req, resp gogoproto.Message) error {
reqName := msgTypeURL(req)
handlers := m.router.HybridHandlerByRequestName(reqName)
if len(handlers) == 0 {
@@ -126,7 +125,7 @@ func (m *queryRouterService) InvokeTyped(ctx context.Context, req, resp protoifa
}
// InvokeUntyped execute a message and returns a response.
func (m *queryRouterService) InvokeUntyped(ctx context.Context, req protoiface.MessageV1) (protoiface.MessageV1, error) {
func (m *queryRouterService) InvokeUntyped(ctx context.Context, req gogoproto.Message) (gogoproto.Message, error) {
reqName := msgTypeURL(req)
respName := m.router.ResponseNameByRequestName(reqName)
if respName == "" {
@@ -134,11 +133,11 @@ func (m *queryRouterService) InvokeUntyped(ctx context.Context, req protoiface.M
}
// get response type
typ := proto.MessageType(respName)
typ := gogoproto.MessageType(respName)
if typ == nil {
return nil, fmt.Errorf("no message type found for %s", respName)
}
reqResp, ok := reflect.New(typ.Elem()).Interface().(protoiface.MessageV1)
reqResp, ok := reflect.New(typ.Elem()).Interface().(gogoproto.Message)
if !ok {
return nil, fmt.Errorf("could not create response request %s", respName)
}
@@ -147,10 +146,10 @@ func (m *queryRouterService) InvokeUntyped(ctx context.Context, req protoiface.M
}
// msgTypeURL returns the TypeURL of a proto message.
func msgTypeURL(msg proto.Message) string {
func msgTypeURL(msg gogoproto.Message) string {
if m, ok := msg.(protov2.Message); ok {
return string(m.ProtoReflect().Descriptor().FullName())
}
return proto.MessageName(msg)
return gogoproto.MessageName(msg)
}