-
Notifications
You must be signed in to change notification settings - Fork 86
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
Conversation
|
||
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") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- not clear for me why we can't return what url.Parse() gives us and need additional check for the type of error.
- I feel like we need unittests for this to explain functionality like example where this
first path segment in URL
is relavant - 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
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