Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support urls without scheme #2242

Merged
merged 1 commit into from
Oct 14, 2024
Merged

support urls without scheme #2242

merged 1 commit into from
Oct 14, 2024

Conversation

felipemadero
Copy link
Collaborator

Why this should be merged

It is desirable for cmdline ux to be able to provide urls without scheme as for example 127.0.0.1:9650/ext/bc/2TaAjq8oF5PRrGDzX7DvWxsdei1AZvHRZ7TAdNpqrbCEZKcQ55/rpc
This capability is presented in tools like forge.

How this works

How this was tested

How is this documented

@felipemadero felipemadero requested a review from a team as a code owner October 13, 2024 06:50
@felipemadero felipemadero merged commit 6a36a25 into main Oct 14, 2024
33 checks passed
@felipemadero felipemadero deleted the support-urls-without-scheme branch October 14, 2024 19:12

func HasScheme(rpcURL string) (bool, error) {
if parsedURL, err := url.Parse(rpcURL); err != nil {
if !strings.Contains(err.Error(), "first path segment in URL cannot contain colon") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. not clear for me why we can't return what url.Parse() gives us and need additional check for the type of error.
  2. I feel like we need unittests for this to explain functionality like example where this first path segment in URL is relavant
  3. should be moved to utils/net.go

so the main question is why it has to be more complicated then to rely on url.Parse to check if it's a url and has some scheme and then check if Scheme is not empty

if hasScheme {
client, err = ethclient.DialContext(ctx, rpcURL)
} else {
client, _, err = FindOutScheme(rpcURL)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not sure FIndOutScheme is a good name for this as it returns a EthClient. I feel like FindOutScheme should be a helper function to detect endpoint protocol and correct corresponing rpcURL by adding scheme so ethclient.DialContext(ctx, rpcURL) can be still used to get a client

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls feel free to ignore this comment

@@ -259,15 +261,80 @@ func SendTransaction(
return err
}

func FindOutScheme(rpcURL string) (ethclient.Client, string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like it will be more flexible if this detects and returns scheme not ethclient.Client
in this case it will have more generic use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

3 participants