@@ -18,11 +18,9 @@ package main
1818
1919import (
2020 "fmt"
21- "path/filepath"
2221 "strings"
2322
2423 "github.com/ethereum/go-ethereum/cmd/utils"
25- "github.com/ethereum/go-ethereum/common"
2624 "github.com/ethereum/go-ethereum/console"
2725 "github.com/ethereum/go-ethereum/node"
2826 "github.com/ethereum/go-ethereum/rpc"
@@ -61,7 +59,7 @@ This command allows to open a console on a running geth node.`,
6159 javascriptCommand = cli.Command {
6260 Action : utils .MigrateFlags (ephemeralConsole ),
6361 Name : "js" ,
64- Usage : "Execute the specified JavaScript files" ,
62+ Usage : "(DEPRECATED) Execute the specified JavaScript files" ,
6563 ArgsUsage : "<jsfile> [jsfile...]" ,
6664 Flags : utils .GroupFlags (nodeFlags , consoleFlags ),
6765 Category : "CONSOLE COMMANDS" ,
@@ -121,31 +119,9 @@ func localConsole(ctx *cli.Context) error {
121119func remoteConsole (ctx * cli.Context ) error {
122120 endpoint := ctx .Args ().First ()
123121 if endpoint == "" {
124- path := node .DefaultDataDir ()
125- if ctx .GlobalIsSet (utils .DataDirFlag .Name ) {
126- path = ctx .GlobalString (utils .DataDirFlag .Name )
127- }
128- if path != "" {
129- if ctx .GlobalBool (utils .RopstenFlag .Name ) {
130- // Maintain compatibility with older Geth configurations storing the
131- // Ropsten database in `testnet` instead of `ropsten`.
132- legacyPath := filepath .Join (path , "testnet" )
133- if common .FileExist (legacyPath ) {
134- path = legacyPath
135- } else {
136- path = filepath .Join (path , "ropsten" )
137- }
138- } else if ctx .GlobalBool (utils .RinkebyFlag .Name ) {
139- path = filepath .Join (path , "rinkeby" )
140- } else if ctx .GlobalBool (utils .GoerliFlag .Name ) {
141- path = filepath .Join (path , "goerli" )
142- } else if ctx .GlobalBool (utils .SepoliaFlag .Name ) {
143- path = filepath .Join (path , "sepolia" )
144- } else if ctx .GlobalBool (utils .KilnFlag .Name ) {
145- path = filepath .Join (path , "kiln" )
146- }
147- }
148- endpoint = fmt .Sprintf ("%s/geth.ipc" , path )
122+ cfg := defaultNodeConfig ()
123+ utils .SetDataDir (ctx , & cfg )
124+ endpoint = cfg .IPCEndpoint ()
149125 }
150126 client , err := dialRPC (endpoint )
151127 if err != nil {
@@ -174,6 +150,19 @@ func remoteConsole(ctx *cli.Context) error {
174150 return nil
175151}
176152
153+ // ephemeralConsole starts a new geth node, attaches an ephemeral JavaScript
154+ // console to it, executes each of the files specified as arguments and tears
155+ // everything down.
156+ func ephemeralConsole (ctx * cli.Context ) error {
157+ var b strings.Builder
158+ for _ , file := range ctx .Args () {
159+ b .Write ([]byte (fmt .Sprintf ("loadScript('%s');" , file )))
160+ }
161+ utils .Fatalf (`The "js" command is deprecated. Please use the following instead:
162+ geth --exec "%s" console` , b .String ())
163+ return nil
164+ }
165+
177166// dialRPC returns a RPC client which connects to the given endpoint.
178167// The check for empty endpoint implements the defaulting logic
179168// for "geth attach" with no argument.
@@ -187,48 +176,3 @@ func dialRPC(endpoint string) (*rpc.Client, error) {
187176 }
188177 return rpc .Dial (endpoint )
189178}
190-
191- // ephemeralConsole starts a new geth node, attaches an ephemeral JavaScript
192- // console to it, executes each of the files specified as arguments and tears
193- // everything down.
194- func ephemeralConsole (ctx * cli.Context ) error {
195- // Create and start the node based on the CLI flags
196- stack , backend := makeFullNode (ctx )
197- startNode (ctx , stack , backend , false )
198- defer stack .Close ()
199-
200- // Attach to the newly started node and start the JavaScript console
201- client , err := stack .Attach ()
202- if err != nil {
203- return fmt .Errorf ("Failed to attach to the inproc geth: %v" , err )
204- }
205- config := console.Config {
206- DataDir : utils .MakeDataDir (ctx ),
207- DocRoot : ctx .GlobalString (utils .JSpathFlag .Name ),
208- Client : client ,
209- Preload : utils .MakeConsolePreloads (ctx ),
210- }
211-
212- console , err := console .New (config )
213- if err != nil {
214- return fmt .Errorf ("Failed to start the JavaScript console: %v" , err )
215- }
216- defer console .Stop (false )
217-
218- // Interrupt the JS interpreter when node is stopped.
219- go func () {
220- stack .Wait ()
221- console .Stop (false )
222- }()
223-
224- // Evaluate each of the specified JavaScript files.
225- for _ , file := range ctx .Args () {
226- if err = console .Execute (file ); err != nil {
227- return fmt .Errorf ("Failed to execute %s: %v" , file , err )
228- }
229- }
230-
231- // The main script is now done, but keep running timers/callbacks.
232- console .Stop (true )
233- return nil
234- }
0 commit comments