diff --git a/nodebuilder/core/flags.go b/nodebuilder/core/flags.go index b98c7acd07..901d910ea6 100644 --- a/nodebuilder/core/flags.go +++ b/nodebuilder/core/flags.go @@ -2,6 +2,7 @@ package core import ( "fmt" + "net" "github.com/spf13/cobra" flag "github.com/spf13/pflag" @@ -21,7 +22,8 @@ func Flags() *flag.FlagSet { coreFlag, "", "Indicates node to connect to the given core node. "+ - "Example: , 127.0.0.1. Assumes RPC port 26657 and gRPC port 9090 as default unless otherwise specified.", + "Example: , 127.0.0.1. , subdomain.domain.tld "+ + "Assumes RPC port 26657 and gRPC port 9090 as default unless otherwise specified.", ) flags.String( coreRPCFlag, @@ -37,10 +39,7 @@ func Flags() *flag.FlagSet { } // ParseFlags parses Core flags from the given cmd and saves them to the passed config. -func ParseFlags( - cmd *cobra.Command, - cfg *Config, -) error { +func ParseFlags(cmd *cobra.Command, cfg *Config) error { coreIP := cmd.Flag(coreFlag).Value.String() if coreIP == "" { if cmd.Flag(coreGRPCFlag).Changed || cmd.Flag(coreRPCFlag).Changed { @@ -49,10 +48,22 @@ func ParseFlags( return nil } + ip := net.ParseIP(coreIP) + if ip == nil { + ips, err := net.LookupIP(coreIP) + if err != nil { + return fmt.Errorf("failed to resolve DNS record: %v", err) + } + if len(ips) == 0 { + return fmt.Errorf("no IP addresses found for DNS record") + } + ip = ips[0] + } + rpc := cmd.Flag(coreRPCFlag).Value.String() grpc := cmd.Flag(coreGRPCFlag).Value.String() - cfg.IP = coreIP + cfg.IP = ip.String() cfg.RPCPort = rpc cfg.GRPCPort = grpc return nil