Skip to content

Commit

Permalink
refactor: grpc insecure plus plugin not mandatory (#158)
Browse files Browse the repository at this point in the history
* update: plugin not by default

* del: defaultPlugin

* changelog

* changelog bug fixes
  • Loading branch information
JulianToledano authored Sep 27, 2024
1 parent 38a2b0a commit bc5816a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 11 additions & 9 deletions cmd/rosetta.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
4 changes: 1 addition & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
}
15 changes: 10 additions & 5 deletions load.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()))
}
Expand Down Expand Up @@ -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)
}

0 comments on commit bc5816a

Please sign in to comment.