diff --git a/CHANGELOG.md b/CHANGELOG.md index 57a381e..152d3b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,14 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Improvements + +* [#157](https://github.com/cosmos/rosetta/pull/157) Rosetta can now run without requiring a plugin. + +### Bug Fixes + +* [#157](https://github.com/cosmos/rosetta/pull/157) Added support for insecure connections to gRPC reflection servers. + ## [v0.50.10](https://github.com/cosmos/rosetta/releases/tag/v0.50.10) 2024-09-25 ### Improvements diff --git a/cmd/rosetta.go b/cmd/rosetta.go index 181fe95..8436728 100644 --- a/cmd/rosetta.go +++ b/cmd/rosetta.go @@ -29,16 +29,18 @@ func RosettaCommand(ir codectypes.InterfaceRegistry, cdc codec.Codec) *cobra.Com } conf.WithCodec(ir, protoCodec) - err = rosetta.LoadPlugin(ir, cmd.Flag("plugin").Value.String()) - if err != nil { - fmt.Printf("[Rosetta]- Error while loading cosmos-hub plugin: %s", err.Error()) - return err - } - - if cmd.Flag("grpc-types-server").Value.String() != "" { - err = rosetta.ReflectInterfaces(ir, cmd.Flag("grpc-types-server").Value.String()) + pluginPath := cmd.Flag(rosetta.FlagPlugin).Value.String() + typesServer := cmd.Flag(rosetta.FlagGRPCTypesServerEndpoint).Value.String() + if pluginPath != "" { + err = rosetta.LoadPlugin(ir, pluginPath) + if err != nil { + fmt.Printf("[Rosetta]- Error while loading plugin: %s", err.Error()) + return err + } + } else if typesServer != "" { + err = rosetta.ReflectInterfaces(ir, typesServer) if err != nil { - fmt.Printf("[Rosetta]- Error while reflecting from grpc server: %s", err.Error()) + fmt.Printf("[Rosetta]- Error while reflecting from gRPC server: %s", err.Error()) return err } } diff --git a/config.go b/config.go index 90bcaa0..d2c6c07 100644 --- a/config.go +++ b/config.go @@ -49,8 +49,6 @@ const ( DenomToSuggest = "uatom" // DefaultPrices defines the default list of prices to suggest DefaultPrices = "1uatom,1stake" - // DefaultPlugin define plugin location for interface and type registry - DefaultPlugin = "cosmos-hub" ) // configuration flags @@ -306,5 +304,5 @@ func SetFlags(flags *pflag.FlagSet) { flags.Int(FlagGasToSuggest, clientflags.DefaultGasLimit, "default gas for fee suggestion") flags.String(FlagDenomToSuggest, DenomToSuggest, "default denom for fee suggestion") flags.String(FlagPricesToSuggest, DefaultPrices, "default prices for fee suggestion") - flags.String(FlagPlugin, DefaultPlugin, "plugin folder name") + flags.String(FlagPlugin, "", "plugin folder name") } diff --git a/load.go b/load.go index 85ec656..2b749a9 100644 --- a/load.go +++ b/load.go @@ -11,6 +11,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/reflection/grpc_reflection_v1alpha" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/descriptorpb" @@ -43,11 +44,15 @@ func ReflectInterfaces(ir codectypes.InterfaceRegistry, endpoint string) (err er } func openClient(endpoint string) (client *grpc.ClientConn, err error) { - tlsCredentials := credentials.NewTLS(&tls.Config{ - MinVersion: tls.VersionTLS12, - }) + creds := insecure.NewCredentials() + if strings.HasPrefix(endpoint, "https://") { + tlsConfig := &tls.Config{ + MinVersion: tls.VersionTLS12, + } + creds = credentials.NewTLS(tlsConfig) + } - client, err = grpc.NewClient(endpoint, grpc.WithTransportCredentials(tlsCredentials)) + client, err = grpc.NewClient(endpoint, grpc.WithTransportCredentials(creds)) if err != nil { return nil, crgerrs.WrapError(crgerrs.ErrClient, fmt.Sprintf("getting grpc client connection %s", err.Error())) } @@ -170,7 +175,7 @@ func cleanImplMsgNames(implMessages []string) (cleanImplMessages []string) { } func registerProtoInterface(registry codectypes.InterfaceRegistry, fileDescriptor *descriptorpb.FileDescriptorProto) { - name := "/" + strings.ReplaceAll(fileDescriptor.GetName(), "/", ".") + name := strings.ReplaceAll(fileDescriptor.GetName(), "/", ".") descriptorMessageInterface := fileDescriptor.ProtoReflect().Interface() registry.RegisterInterface(name, &descriptorMessageInterface) }