From 3090dbf4390a5d0877a877bfa8d26a45050ae4a6 Mon Sep 17 00:00:00 2001 From: anhductn2001 Date: Wed, 20 Aug 2025 15:51:16 +0700 Subject: [PATCH 1/2] feat: auto-append :443 port to HTTPS endpoints --- cmd/eibc/fulfill/feeshare/feeshare.go | 8 ++++---- cmd/eibc/init/init.go | 6 ++++-- cmd/rollapp/setup/setup.go | 9 +++++++++ utils/config/prompts.go | 14 ++++++++++++++ 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/cmd/eibc/fulfill/feeshare/feeshare.go b/cmd/eibc/fulfill/feeshare/feeshare.go index 5235b8c8a..c576c2ca7 100644 --- a/cmd/eibc/fulfill/feeshare/feeshare.go +++ b/cmd/eibc/fulfill/feeshare/feeshare.go @@ -26,10 +26,10 @@ func Cmd() *cobra.Command { return } - if err != nil { - pterm.Error.Println("failed to expand home directory") - return - } + // if err != nil { + // pterm.Error.Println("failed to expand home directory") + // return + // } eibcHome := filepath.Join(home, consts.ConfigDirName.Eibc) eibcConfigPath := filepath.Join(eibcHome, "config.yaml") diff --git a/cmd/eibc/init/init.go b/cmd/eibc/init/init.go index 71474cf67..bc337fa53 100644 --- a/cmd/eibc/init/init.go +++ b/cmd/eibc/init/init.go @@ -373,6 +373,8 @@ func setupEibcClient(hd consts.HubData, eibcHome string, ki *keys.KeyInfo) error rpc = strings.TrimSuffix(rpc, "/") + // Add :443 to HTTPS URLs if no port is specified + rpc = config.AddHttpsPortIfNeeded(rpc) isValid := config.IsValidURL(rpc) if !isValid { @@ -433,13 +435,13 @@ func initializeEibcForEnvironment() (consts.HubData, error) { var rollerConfig roller.RollappConfig hdid, _ := pterm.DefaultInteractiveTextInput.WithDefaultText("provide hub chain id"). Show() - hdrpc, _ := pterm.DefaultInteractiveTextInput.WithDefaultText("provide hub rpc endpoint"). + hdrpc, _ := pterm.DefaultInteractiveTextInput.WithDefaultText("provide hub rpc endpoint (example: https://hub.dym.xyz:443)"). Show() hdws, _ := pterm.DefaultInteractiveTextInput.WithDefaultText("provide hub websocket endpoint, only fill this in when RPC and WebSocket are separate (optional)"). Show() rollerConfig.HubData.ID = hdid - rollerConfig.HubData.RpcUrl = hdrpc + rollerConfig.HubData.RpcUrl = config.AddHttpsPortIfNeeded(hdrpc) if hdws == "" { rollerConfig.HubData.WsUrl = hdrpc diff --git a/cmd/rollapp/setup/setup.go b/cmd/rollapp/setup/setup.go index c6c994cd5..200fb8a87 100644 --- a/cmd/rollapp/setup/setup.go +++ b/cmd/rollapp/setup/setup.go @@ -1185,6 +1185,9 @@ func populateSequencerMetadata(raCfg roller.RollappConfig) error { rpc = "https://" + rpc } + // Add :443 to HTTPS URLs if no port is specified + rpc = config.AddHttpsPortIfNeeded(rpc) + isValid := config.IsValidURL(rpc) // Validate the URL @@ -1205,6 +1208,9 @@ func populateSequencerMetadata(raCfg roller.RollappConfig) error { rest = "https://" + rest } + // Add :443 to HTTPS URLs if no port is specified + rest = config.AddHttpsPortIfNeeded(rest) + isValid := config.IsValidURL(rest) // Validate the URL @@ -1226,6 +1232,9 @@ func populateSequencerMetadata(raCfg roller.RollappConfig) error { evmRpc = "https://" + evmRpc } + // Add :443 to HTTPS URLs if no port is specified + evmRpc = config.AddHttpsPortIfNeeded(evmRpc) + isValid := config.IsValidURL(evmRpc) // Validate the URL diff --git a/utils/config/prompts.go b/utils/config/prompts.go index 837e7e7da..4818f0552 100644 --- a/utils/config/prompts.go +++ b/utils/config/prompts.go @@ -9,6 +9,17 @@ import ( "github.com/dymensionxyz/roller/utils/roller" ) +// AddHttpsPortIfNeeded appends :443 to HTTPS URLs that don't already have a port specified +func AddHttpsPortIfNeeded(url string) string { + if strings.HasPrefix(url, "https://") { + // Check if URL already has a port + if !strings.Contains(url[8:], ":") { + return url + ":443" + } + } + return url +} + func PromptVmType() string { vmtypes := []string{"evm", "wasm"} vmtype, _ := pterm.DefaultInteractiveSelect. @@ -50,6 +61,9 @@ func PromptCustomHubEndpoint(rollerConfig roller.RollappConfig) roller.RollappCo rpcEndpoint, _ = pterm.DefaultInteractiveTextInput.WithDefaultText("We recommend using a private RPC endpoint for the hub. Please provide the hub rpc endpoint to use. You can obtain one here: https://blastapi.io/chains/dymension"). Show() + // Add :443 to HTTPS URLs if no port is specified + rpcEndpoint = AddHttpsPortIfNeeded(rpcEndpoint) + isValidUrl := IsValidURL(rpcEndpoint) if isValidUrl { break From 70b69963e3c3d1665fe66e1e14ced14b4bba2b89 Mon Sep 17 00:00:00 2001 From: anhductn2001 Date: Wed, 20 Aug 2025 16:10:54 +0700 Subject: [PATCH 2/2] improve add port func, use url.Parse --- utils/config/prompts.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/utils/config/prompts.go b/utils/config/prompts.go index 4818f0552..ba51333b4 100644 --- a/utils/config/prompts.go +++ b/utils/config/prompts.go @@ -1,6 +1,7 @@ package config import ( + "net/url" "strings" "github.com/pterm/pterm" @@ -10,14 +11,15 @@ import ( ) // AddHttpsPortIfNeeded appends :443 to HTTPS URLs that don't already have a port specified -func AddHttpsPortIfNeeded(url string) string { - if strings.HasPrefix(url, "https://") { - // Check if URL already has a port - if !strings.Contains(url[8:], ":") { - return url + ":443" - } +func AddHttpsPortIfNeeded(rawurl string) string { + u, err := url.Parse(rawurl) + if err != nil || u.Scheme != "https" { + return rawurl + } + if !strings.Contains(u.Host, ":") { + u.Host = u.Host + ":443" } - return url + return u.String() } func PromptVmType() string {