Start the Streamer

Lastly, we'll modify the makeFullNode() calls in the main entry point and start the streamer. In cmd/geth/main.go modify geth() to look like the following:

// cmd/geth/main.go

func geth(ctx *cli.Context) error {
	if args := ctx.Args().Slice(); len(args) > 0 {
		return fmt.Errorf("invalid command: %q", args[0])
	}

	prepare(ctx)
	stack, backend, mlstream := makeFullNode(ctx)
	defer stack.Close()
	defer mlstream.Stop()

	startNode(ctx, stack, backend, false)

	// Start the mevlink streamer
	if err := mlstream.Stream(); err != nil {
		log.Info("[ mevlink-streamer ] encountered fatal error: ", err)
	}

	stack.Wait()
	return nil
}

We'll also have to modify cmd/geth/consolecmd.go which also calls makeFullNode() and ignore the returned mevlink stream:

// cmd/geth/consolecmd.go

func localConsole(ctx *cli.Context) error {
	// Create and start the node based on the CLI flags
	prepare(ctx)
	stack, backend, _ := makeFullNode(ctx)
	startNode(ctx, stack, backend, true)
	defer stack.Close()

	// Attach to the newly started node and create the JavaScript console.
	client, err := stack.Attach()
	if err != nil {
		return fmt.Errorf("failed to attach to the inproc geth: %v", err)
	}
	config := console.Config{
		DataDir: utils.MakeDataDir(ctx),
		DocRoot: ctx.String(utils.JSpathFlag.Name),
		Client:  client,
		Preload: utils.MakeConsolePreloads(ctx),
	}
	console, err := console.New(config)
	if err != nil {
		return fmt.Errorf("failed to start the JavaScript console: %v", err)
	}
	defer console.Stop(false)

	// If only a short execution was requested, evaluate and return.
	if script := ctx.String(utils.ExecFlag.Name); script != "" {
		console.Evaluate(script)
		return nil
	}

	// Track node shutdown and stop the console when it goes down.
	// This happens when SIGTERM is sent to the process.
	go func() {
		stack.Wait()
		console.StopInteractive()
	}()

	// Print the welcome screen and enter interactive mode.
	console.Welcome()
	console.Interactive()
	return nil
}

Last updated