77 "sync"
88 "time"
99
10- sdk "github.com/cosmos/cosmos-sdk/types"
1110 "github.com/cosmos/cosmos-sdk/crypto/keyring"
11+ sdk "github.com/cosmos/cosmos-sdk/types"
1212 "google.golang.org/grpc"
1313 "google.golang.org/grpc/credentials"
1414 "google.golang.org/grpc/credentials/insecure"
@@ -67,7 +67,7 @@ func New(ctx context.Context, cfg Config, kr keyring.Keyring, keyName string) (*
6767 // Determine if we should use TLS based on the endpoint
6868 // Use TLS if: port is 443, or hostname doesn't start with "localhost"/"127.0.0.1"
6969 useTLS := shouldUseTLS (cfg .GRPCAddr )
70-
70+
7171 var creds credentials.TransportCredentials
7272 if useTLS {
7373 // Use system TLS credentials for secure connections
@@ -76,7 +76,7 @@ func New(ctx context.Context, cfg Config, kr keyring.Keyring, keyName string) (*
7676 // Use insecure credentials for local development
7777 creds = insecure .NewCredentials ()
7878 }
79-
79+
8080 // Create gRPC connection
8181 dialOpts := []grpc.DialOption {
8282 grpc .WithTransportCredentials (creds ),
@@ -86,7 +86,7 @@ func New(ctx context.Context, cfg Config, kr keyring.Keyring, keyName string) (*
8686 ),
8787 }
8888
89- conn , err := grpc .DialContext ( ctx , cfg .GRPCAddr , dialOpts ... )
89+ conn , err := grpc .NewClient ( cfg .GRPCAddr , dialOpts ... )
9090 if err != nil {
9191 return nil , fmt .Errorf ("failed to connect to gRPC: %w" , err )
9292 }
@@ -126,23 +126,23 @@ func shouldUseTLS(addr string) bool {
126126 if strings .HasSuffix (addr , ":443" ) {
127127 return true
128128 }
129-
129+
130130 // Check if it's a local address (localhost, 127.0.0.1, or no hostname)
131131 if strings .HasPrefix (addr , "localhost:" ) ||
132132 strings .HasPrefix (addr , "127.0.0.1:" ) ||
133133 strings .HasPrefix (addr , "0.0.0.0:" ) ||
134134 strings .HasPrefix (addr , ":" ) { // Just port, implies localhost
135135 return false
136136 }
137-
137+
138138 // For any other remote address, prefer TLS by default for security
139139 // This covers domain names without explicit port 443
140140 if ! strings .Contains (addr , "localhost" ) &&
141141 ! strings .Contains (addr , "127.0.0.1" ) &&
142142 ! strings .Contains (addr , "0.0.0.0" ) {
143143 return true
144144 }
145-
145+
146146 return false
147147}
148148
0 commit comments