@@ -18,6 +18,7 @@ package main
1818
1919import (
2020 "fmt"
21+ "net/url"
2122 "os"
2223 "os/signal"
2324 "path/filepath"
@@ -85,10 +86,11 @@ func localConsole(ctx *cli.Context) error {
8586 utils .Fatalf ("Failed to attach to the inproc XDC: %v" , err )
8687 }
8788 config := console.Config {
88- DataDir : utils .MakeDataDir (ctx ),
89- DocRoot : ctx .String (utils .JSpathFlag .Name ),
90- Client : client ,
91- Preload : utils .MakeConsolePreloads (ctx ),
89+ DataDir : utils .MakeDataDir (ctx ),
90+ DocRoot : ctx .String (utils .JSpathFlag .Name ),
91+ Client : client ,
92+ LocalTransport : true ,
93+ Preload : utils .MakeConsolePreloads (ctx ),
9294 }
9395
9496 console , err := console .New (config )
@@ -132,15 +134,16 @@ func remoteConsole(ctx *cli.Context) error {
132134 endpoint = fmt .Sprintf ("%s/XDC.ipc" , path )
133135 }
134136
135- client , err := dialRPC (endpoint )
137+ client , localTransport , err := dialRPC (endpoint )
136138 if err != nil {
137139 utils .Fatalf ("Unable to attach to remote XDC: %v" , err )
138140 }
139141 config := console.Config {
140- DataDir : utils .MakeDataDir (ctx ),
141- DocRoot : ctx .String (utils .JSpathFlag .Name ),
142- Client : client ,
143- Preload : utils .MakeConsolePreloads (ctx ),
142+ DataDir : utils .MakeDataDir (ctx ),
143+ DocRoot : ctx .String (utils .JSpathFlag .Name ),
144+ Client : client ,
145+ LocalTransport : localTransport ,
146+ Preload : utils .MakeConsolePreloads (ctx ),
144147 }
145148
146149 console , err := console .New (config )
@@ -164,15 +167,32 @@ func remoteConsole(ctx *cli.Context) error {
164167// dialRPC returns a RPC client which connects to the given endpoint.
165168// The check for empty endpoint implements the defaulting logic
166169// for "XDC attach" and "XDC monitor" with no argument.
167- func dialRPC (endpoint string ) (* rpc.Client , error ) {
170+ func dialRPC (endpoint string ) (* rpc.Client , bool , error ) {
171+ endpoint , localTransport := resolveConsoleEndpoint (endpoint )
172+ client , err := rpc .Dial (endpoint )
173+ return client , localTransport , err
174+ }
175+
176+ func resolveConsoleEndpoint (endpoint string ) (string , bool ) {
168177 if endpoint == "" {
169- endpoint = node .DefaultIPCEndpoint (clientIdentifier )
170- } else if strings .HasPrefix (endpoint , "rpc:" ) || strings .HasPrefix (endpoint , "ipc:" ) {
171- // Backwards compatibility with geth < 1.5 which required
172- // these prefixes.
173- endpoint = endpoint [4 :]
178+ return node .DefaultIPCEndpoint (clientIdentifier ), true
179+ }
180+ if strings .HasPrefix (endpoint , "rpc:" ) || strings .HasPrefix (endpoint , "ipc:" ) {
181+ // Backwards compatibility with geth < 1.5 which required these prefixes.
182+ return endpoint [4 :], true
183+ }
184+ u , err := url .Parse (endpoint )
185+ if err != nil {
186+ return endpoint , false
187+ }
188+ switch u .Scheme {
189+ case "http" , "https" , "ws" , "wss" , "stdio" :
190+ return endpoint , false
191+ case "" :
192+ return endpoint , true
193+ default :
194+ return endpoint , false
174195 }
175- return rpc .Dial (endpoint )
176196}
177197
178198// ephemeralConsole starts a new XDC node, attaches an ephemeral JavaScript
@@ -190,10 +210,11 @@ func ephemeralConsole(ctx *cli.Context) error {
190210 utils .Fatalf ("Failed to attach to the inproc XDC: %v" , err )
191211 }
192212 config := console.Config {
193- DataDir : utils .MakeDataDir (ctx ),
194- DocRoot : ctx .String (utils .JSpathFlag .Name ),
195- Client : client ,
196- Preload : utils .MakeConsolePreloads (ctx ),
213+ DataDir : utils .MakeDataDir (ctx ),
214+ DocRoot : ctx .String (utils .JSpathFlag .Name ),
215+ Client : client ,
216+ LocalTransport : true ,
217+ Preload : utils .MakeConsolePreloads (ctx ),
197218 }
198219
199220 console , err := console .New (config )
0 commit comments