cmd

package
v1.0.0-beta.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2025 License: Apache-2.0 Imports: 29 Imported by: 0

README

Evolve CLI

A cli tool that allows you to run different kinds of nodes for a evolve network while also helping you generate the required configuration files

Install

NOTE: Requires Go version >= 1.19.

To install evolve, simply run the following command at the root of the evolve repo

make install

The latest Evolve is now installed. You can verify the installation by running:

evolve version

Reinstall

If you have Evolve installed, and you make updates that you want to test, simply run:

make install

Documentation

Index

Constants

View Source
const DefaultMaxBlobSize = 1.5 * 1024 * 1024 // 1.5MB

Variables

View Source
var (
	// GitSHA is set at build time
	GitSHA string

	// Version is set at build time
	Version string
)
View Source
var NetInfoCmd = &cobra.Command{
	Use:   "net-info",
	Short: "Get information about a running node via RPC",
	Long:  "This command retrieves the node information via RPC from a running node in the specified directory (or current directory if not specified).",
	RunE: func(cmd *cobra.Command, args []string) error {
		nodeConfig, err := ParseConfig(cmd)
		if err != nil {
			return fmt.Errorf("error parsing config: %w", err)
		}

		rpcAddress := nodeConfig.RPC.Address
		if rpcAddress == "" {
			return fmt.Errorf("RPC address not found in node configuration")
		}

		httpClient := http.Client{
			Transport: http.DefaultTransport,
		}

		baseURL := fmt.Sprintf("http://%s", rpcAddress)

		p2pClient := rpc.NewP2PServiceClient(
			&httpClient,
			baseURL,
		)

		resp, err := p2pClient.GetNetInfo(
			context.Background(),
			connect.NewRequest(&emptypb.Empty{}),
		)
		if err != nil {
			return fmt.Errorf("error calling GetNetInfo RPC: %w", err)
		}

		netInfo := resp.Msg.NetInfo
		nodeID := netInfo.Id

		out := cmd.OutOrStdout()
		w := tabwriter.NewWriter(out, 2, 0, 2, ' ', 0)

		fmt.Fprintf(w, "%s", strings.Repeat("=", 50))
		fmt.Fprintf(w, "📊 NODE INFORMATION")
		fmt.Fprintf(w, "%s\n", strings.Repeat("=", 50))
		fmt.Fprintf(w, "🆔 Node ID:      \033[1;36m%s\033[0m\n", nodeID)

		fmt.Fprintf(w, "📡 Listen Addrs:")
		for i, addr := range netInfo.ListenAddresses {
			fullAddress := fmt.Sprintf("%s/p2p/%s", addr, nodeID)
			fmt.Fprintf(w, "   [%d] Addr: \033[1;36m%s\033[0m\n", i+1, addr)
			fmt.Fprintf(w, "       Full: \033[1;32m%s\033[0m\n", fullAddress)
		}

		fmt.Fprintf(w, "%s\n", strings.Repeat("-", 50))

		peerResp, err := p2pClient.GetPeerInfo(
			context.Background(),
			connect.NewRequest(&emptypb.Empty{}),
		)
		if err != nil {
			return fmt.Errorf("error calling GetPeerInfo RPC: %w", err)
		}

		peerCount := len(peerResp.Msg.Peers)
		fmt.Fprintf(w, "👥 CONNECTED PEERS: \033[1;33m%d\033[0m\n", peerCount)

		if peerCount > 0 {
			fmt.Fprintf(w, "%s\n", strings.Repeat("-", 50))
			fmt.Fprintf(w, "%-5s %-20s %s\n", "NO.", "PEER ID", "ADDRESS")
			fmt.Fprintf(w, "%s\n", strings.Repeat("-", 50))

			for i, peer := range peerResp.Msg.Peers {

				peerID := peer.Id
				if len(peerID) > 18 {
					peerID = peerID[:15] + "..."
				}
				fmt.Fprintf(w, "%-5d \033[1;34m%-20s\033[0m %s\n", i+1, peerID, peer.Address)
			}
		} else {
			fmt.Fprintf(w, "\n\033[3;33mNo peers connected\033[0m")
		}

		fmt.Fprintf(w, "%s\n", strings.Repeat("=", 50))
		w.Flush()

		return nil
	},
}

NodeInfoCmd returns information about the running node via RPC

View Source
var StoreUnsafeCleanCmd = &cobra.Command{
	Use:   "unsafe-clean",
	Short: "Remove all contents of the data directory (DANGEROUS: cannot be undone)",
	Long: `Removes all files and subdirectories in the node's data directory.
This operation is unsafe and cannot be undone. Use with caution!`,
	RunE: func(cmd *cobra.Command, args []string) error {
		nodeConfig, err := ParseConfig(cmd)
		if err != nil {
			return fmt.Errorf("error parsing config: %w", err)
		}
		dataDir := filepath.Join(nodeConfig.RootDir, nodeConfig.DBPath)
		fmt.Println("Data directory:", dataDir)
		if dataDir == "" {
			return fmt.Errorf("data directory not found in node configuration")
		}

		if err := UnsafeCleanDataDir(dataDir); err != nil {
			return err
		}
		cmd.Printf("All contents of the data directory at %s have been removed.\n", dataDir)
		return nil
	},
}

StoreUnsafeCleanCmd is a Cobra command that removes all contents of the data directory.

View Source
var VersionCmd = &cobra.Command{
	Use:   "version",
	Short: "Show version info",
	RunE: func(cmd *cobra.Command, args []string) error {
		if GitSHA == "" {
			return errors.New("git SHA not set")
		}
		if Version == "" {
			return errors.New("version not set")
		}
		out := cmd.OutOrStdout()
		w := tabwriter.NewWriter(out, 2, 0, 2, ' ', 0)
		_, err1 := fmt.Fprintf(w, "\nevolve version:\t%v\n", Version)
		_, err2 := fmt.Fprintf(w, "evolve git sha:\t%v\n", GitSHA)
		_, err3 := fmt.Fprintln(w, "")
		return errors.Join(err1, err2, err3, w.Flush())
	},
}

VersionCmd is the command to show version info for evolve CLI

Functions

func CreateSigner

func CreateSigner(config *rollconf.Config, homePath string, passphrase string) ([]byte, error)

CreateSigner sets up the signer configuration and creates necessary files

func KeysCmd

func KeysCmd() *cobra.Command

KeysCmd returns a command for managing keys.

func LoadOrGenNodeKey

func LoadOrGenNodeKey(homePath string) error

LoadOrGenNodeKey creates the node key file if it doesn't exist.

func ParseConfig

func ParseConfig(cmd *cobra.Command) (rollconf.Config, error)

ParseConfig is an helpers that loads the node configuration and validates it.

func SetupLogger

func SetupLogger(config rollconf.LogConfig) zerolog.Logger

SetupLogger configures and returns a logger based on the provided configuration. It applies the following settings from the config:

  • Log format (text or JSON)
  • Log level (debug, info, warn, error)
  • Stack traces for error logs

The returned logger is already configured with the "module" field set to "main".

func StartNode

func StartNode(
	logger zerolog.Logger,
	cmd *cobra.Command,
	executor coreexecutor.Executor,
	sequencer coresequencer.Sequencer,
	da coreda.DA,
	p2pClient *p2p.Client,
	datastore datastore.Batching,
	nodeConfig rollconf.Config,
	genesis genesispkg.Genesis,
	nodeOptions node.NodeOptions,
) error

StartNode handles the node startup logic

func UnsafeCleanDataDir

func UnsafeCleanDataDir(dataDir string) error

UnsafeCleanDataDir removes all contents of the specified data directory. It does not remove the data directory itself, only its contents.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL