fixed default to grpcs #623

Merged
tech merged 1 commits from tron-622 into main 2026-03-04 00:31:21 +00:00

View File

@@ -107,28 +107,30 @@ func newForceIPv4Dialer(host, port string) func(context.Context, string) (net.Co
func normalizeGRPCAddress(grpcURL string) (string, bool, error) { func normalizeGRPCAddress(grpcURL string) (string, bool, error) {
target := strings.TrimSpace(grpcURL) target := strings.TrimSpace(grpcURL)
useTLS := false
if target == "" { if target == "" {
return "", false, merrors.InvalidArgument("tronclient: grpc url is required") return "", false, merrors.InvalidArgument("tronclient: grpc url is required")
} }
if strings.Contains(target, "://") {
u, err := url.Parse(target) // Default to secure gRPC when no scheme is provided.
if err != nil { if !strings.Contains(target, "://") {
return "", false, merrors.InvalidArgument("tronclient: invalid grpc url") target = "grpcs://" + target
}
if u.Scheme == "https" || u.Scheme == "grpcs" {
useTLS = true
}
host := strings.TrimSpace(u.Host)
if host == "" {
return "", false, merrors.InvalidArgument("tronclient: grpc url missing host")
}
if useTLS && u.Port() == "" {
host = host + ":443"
}
return host, useTLS, nil
} }
return target, useTLS, nil
u, err := url.Parse(target)
if err != nil {
return "", false, merrors.InvalidArgument("tronclient: invalid grpc url")
}
useTLS := u.Scheme == "https" || u.Scheme == "grpcs"
host := strings.TrimSpace(u.Host)
if host == "" {
return "", false, merrors.InvalidArgument("tronclient: grpc url missing host")
}
if useTLS && u.Port() == "" {
host = host + ":443"
}
return host, useTLS, nil
} }
func grpcTokenUnaryInterceptor(token string) grpc.UnaryClientInterceptor { func grpcTokenUnaryInterceptor(token string) grpc.UnaryClientInterceptor {