@@ -51,26 +51,28 @@ const DefaultPrompt = "> "
5151// Config is the collection of configurations to fine tune the behavior of the
5252// JavaScript console.
5353type Config struct {
54- DataDir string // Data directory to store the console history at
55- DocRoot string // Filesystem path from where to load JavaScript files from
56- Client * rpc.Client // RPC client to execute Ethereum requests through
57- Prompt string // Input prompt prefix string (defaults to DefaultPrompt)
58- Prompter UserPrompter // Input prompter to allow interactive user feedback (defaults to TerminalPrompter)
59- Printer io.Writer // Output writer to serialize any display strings to (defaults to os.Stdout)
60- Preload []string // Absolute paths to JavaScript files to preload
54+ DataDir string // Data directory to store the console history at
55+ DocRoot string // Filesystem path from where to load JavaScript files from
56+ Client * rpc.Client // RPC client to execute Ethereum requests through
57+ LocalTransport bool // Whether the console is attached over an in-process or IPC transport
58+ Prompt string // Input prompt prefix string (defaults to DefaultPrompt)
59+ Prompter UserPrompter // Input prompter to allow interactive user feedback (defaults to TerminalPrompter)
60+ Printer io.Writer // Output writer to serialize any display strings to (defaults to os.Stdout)
61+ Preload []string // Absolute paths to JavaScript files to preload
6162}
6263
6364// Console is a JavaScript interpreted runtime environment. It is a fully fleged
6465// JavaScript console attached to a running node via an external or in-process RPC
6566// client.
6667type Console struct {
67- client * rpc.Client // RPC client to execute Ethereum requests through
68- jsre * jsre.JSRE // JavaScript runtime environment running the interpreter
69- prompt string // Input prompt prefix string
70- prompter UserPrompter // Input prompter to allow interactive user feedback
71- histPath string // Absolute path to the console scrollback history
72- history []string // Scroll history maintained by the console
73- printer io.Writer // Output writer to serialize any display strings to
68+ client * rpc.Client // RPC client to execute Ethereum requests through
69+ jsre * jsre.JSRE // JavaScript runtime environment running the interpreter
70+ localTransport bool // Whether the connected transport is in-process or IPC
71+ prompt string // Input prompt prefix string
72+ prompter UserPrompter // Input prompter to allow interactive user feedback
73+ histPath string // Absolute path to the console scrollback history
74+ history []string // Scroll history maintained by the console
75+ printer io.Writer // Output writer to serialize any display strings to
7476}
7577
7678// New initializes a JavaScript interpreted runtime environment and sets defaults
@@ -89,12 +91,13 @@ func New(config Config) (*Console, error) {
8991
9092 // Initialize the console and return
9193 console := & Console {
92- client : config .Client ,
93- jsre : jsre .New (config .DocRoot , config .Printer ),
94- prompt : config .Prompt ,
95- prompter : config .Prompter ,
96- printer : config .Printer ,
97- histPath : filepath .Join (config .DataDir , HistoryFile ),
94+ client : config .Client ,
95+ jsre : jsre .New (config .DocRoot , config .Printer ),
96+ localTransport : config .LocalTransport ,
97+ prompt : config .Prompt ,
98+ prompter : config .Prompter ,
99+ printer : config .Printer ,
100+ histPath : filepath .Join (config .DataDir , HistoryFile ),
98101 }
99102 if err := os .MkdirAll (config .DataDir , 0700 ); err != nil {
100103 return nil , err
@@ -207,9 +210,25 @@ func (c *Console) initExtensions() error {
207210 }
208211 }
209212 })
213+ if ! c .localTransport {
214+ c .hideUnavailableDebugMethods ()
215+ }
210216 return nil
211217}
212218
219+ func (c * Console ) hideUnavailableDebugMethods () {
220+ c .jsre .Do (func (vm * goja.Runtime ) {
221+ if debug := getObject (vm , "debug" ); debug != nil {
222+ debug .Set ("setHead" , goja .Undefined ())
223+ }
224+ if web3 := getObject (vm , "web3" ); web3 != nil {
225+ if debug := web3 .Get ("debug" ); debug != nil && ! goja .IsUndefined (debug ) && ! goja .IsNull (debug ) {
226+ debug .ToObject (vm ).Set ("setHead" , goja .Undefined ())
227+ }
228+ }
229+ })
230+ }
231+
213232// initAdmin creates additional admin APIs implemented by the bridge.
214233func (c * Console ) initAdmin (vm * goja.Runtime , bridge * bridge ) {
215234 if admin := getObject (vm , "admin" ); admin != nil {
@@ -260,7 +279,21 @@ func (c *Console) AutoCompleteInput(line string, pos int) (string, []string, str
260279 start ++
261280 break
262281 }
263- return line [:start ], c .jsre .CompleteKeywords (line [start :pos ]), line [pos :]
282+ return line [:start ], c .filterCompletions (c .jsre .CompleteKeywords (line [start :pos ])), line [pos :]
283+ }
284+
285+ func (c * Console ) filterCompletions (completions []string ) []string {
286+ if c .localTransport {
287+ return completions
288+ }
289+ filtered := completions [:0 ]
290+ for _ , completion := range completions {
291+ if completion == "debug.setHead" || completion == "debug.setHead(" || completion == "web3.debug.setHead" || completion == "web3.debug.setHead(" {
292+ continue
293+ }
294+ filtered = append (filtered , completion )
295+ }
296+ return filtered
264297}
265298
266299// Welcome show summary of current Geth instance and some metadata about the
0 commit comments